-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add actor access to notification templates #3724
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { | |
IAttachmentOptions, | ||
IEmailOptions, | ||
LogCodeEnum, | ||
ActorTypeEnum, | ||
} from '@novu/shared'; | ||
import * as Sentry from '@sentry/node'; | ||
import { | ||
|
@@ -52,10 +53,18 @@ export class SendMessageEmail extends SendMessageBase { | |
|
||
@InstrumentUsecase() | ||
public async execute(command: SendMessageCommand) { | ||
const subscriber = await this.getSubscriberBySubscriberId({ | ||
subscriberId: command.subscriberId, | ||
_environmentId: command.environmentId, | ||
}); | ||
const [subscriber, actorSubscriber] = await Promise.all([ | ||
this.getSubscriberBySubscriberId({ | ||
subscriberId: command.subscriberId, | ||
_environmentId: command.environmentId, | ||
}), | ||
command.job._actorId | ||
? this.getSubscriberById({ | ||
_id: command.job._actorId, | ||
_environmentId: command.environmentId, | ||
}) | ||
: Promise.resolve(null), | ||
]); | ||
if (!subscriber) throw new PlatformException(`Subscriber ${command.subscriberId} not found`); | ||
|
||
let integration: IntegrationEntity | undefined = undefined; | ||
|
@@ -90,6 +99,7 @@ export class SendMessageEmail extends SendMessageBase { | |
if (!emailChannel.template) throw new PlatformException('Email channel template not found'); | ||
|
||
const email = command.payload.email || subscriber.email; | ||
const { actor } = emailChannel.template; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed :) |
||
|
||
Sentry.addBreadcrumb({ | ||
message: 'Sending Email', | ||
|
@@ -143,6 +153,7 @@ export class SendMessageEmail extends SendMessageBase { | |
total_count: command.events?.length, | ||
}, | ||
subscriber, | ||
actor: actorSubscriber, | ||
}, | ||
}; | ||
|
||
|
@@ -165,6 +176,11 @@ export class SendMessageEmail extends SendMessageBase { | |
overrides, | ||
templateIdentifier: command.identifier, | ||
_jobId: command.jobId, | ||
...(actor && | ||
actor.type !== ActorTypeEnum.NONE && { | ||
actor, | ||
_actorId: command.job?._actorId, | ||
}), | ||
Comment on lines
+179
to
+183
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to be saved on message |
||
}); | ||
|
||
let replyToAddress: string | undefined; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,18 @@ export class SendMessageInApp extends SendMessageBase { | |
|
||
@InstrumentUsecase() | ||
public async execute(command: SendMessageCommand) { | ||
const subscriber = await this.getSubscriberBySubscriberId({ | ||
subscriberId: command.subscriberId, | ||
_environmentId: command.environmentId, | ||
}); | ||
const [subscriber, actorSubscriber] = await Promise.all([ | ||
this.getSubscriberBySubscriberId({ | ||
subscriberId: command.subscriberId, | ||
_environmentId: command.environmentId, | ||
}), | ||
command.job._actorId | ||
? this.getSubscriberById({ | ||
_id: command.job._actorId, | ||
_environmentId: command.environmentId, | ||
}) | ||
: Promise.resolve(null), | ||
]); | ||
if (!subscriber) throw new PlatformException('Subscriber not found'); | ||
if (!command.step.template) throw new PlatformException('Template not found'); | ||
|
||
|
@@ -103,6 +111,7 @@ export class SendMessageInApp extends SendMessageBase { | |
inAppChannel.template.content, | ||
command.payload, | ||
subscriber, | ||
actorSubscriber, | ||
command, | ||
organization | ||
); | ||
|
@@ -112,6 +121,7 @@ export class SendMessageInApp extends SendMessageBase { | |
inAppChannel.template.cta?.data?.url, | ||
command.payload, | ||
subscriber, | ||
actorSubscriber, | ||
command, | ||
organization | ||
); | ||
|
@@ -125,6 +135,7 @@ export class SendMessageInApp extends SendMessageBase { | |
action.content, | ||
command.payload, | ||
subscriber, | ||
actorSubscriber, | ||
command, | ||
organization | ||
); | ||
|
@@ -146,6 +157,7 @@ export class SendMessageInApp extends SendMessageBase { | |
_notificationId: command.notificationId, | ||
_environmentId: command.environmentId, | ||
_subscriberId: command._subscriberId, | ||
_actorId: command.job._actorId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed in searching for an old message |
||
_templateId: command._templateId, | ||
_messageTemplateId: inAppChannel.template._id, | ||
channel: ChannelTypeEnum.IN_APP, | ||
|
@@ -299,6 +311,7 @@ export class SendMessageInApp extends SendMessageBase { | |
content: string | IEmailBlock[], | ||
payload: any, | ||
subscriber: SubscriberEntity, | ||
actor: SubscriberEntity | null, | ||
command: SendMessageCommand, | ||
organization: OrganizationEntity | null | ||
): Promise<string> { | ||
|
@@ -316,6 +329,7 @@ export class SendMessageInApp extends SendMessageBase { | |
logo: organization?.branding?.logo, | ||
color: organization?.branding?.color || '#f47373', | ||
}, | ||
actor, | ||
...payload, | ||
}, | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be removed