Skip to content
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

fix: so preheader can contain variables #2162

Merged
merged 2 commits into from
Dec 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ export class SendMessageEmail extends SendMessageType {
}
const overrides = command.overrides[integration?.providerId] || {};
let subject = '';
let preheader = emailChannel.template.preheader;
let content: string | IEmailBlock[] = '';

const payload = {
subject: emailChannel.template.subject,
preheader: emailChannel.template.preheader,
preheader,
branding: {
logo: organization.branding?.logo,
color: organization.branding?.color || '#f47373',
Expand All @@ -117,10 +118,22 @@ export class SendMessageEmail extends SendMessageType {
organization,
subscriber,
command,
emailChannel.template.preheader
preheader
);

content = await this.getContent(isEditorMode, emailChannel, command, subscriber, subject, organization);
content = await this.getContent(
isEditorMode,
emailChannel,
command,
subscriber,
subject,
organization,
preheader
);

if (preheader) {
preheader = await this.renderContent(preheader, subject, organization, subscriber, command, preheader);
}
} catch (e) {
await this.createExecutionDetails.execute(
CreateExecutionDetailsCommand.create({
Expand Down Expand Up @@ -178,7 +191,7 @@ export class SendMessageEmail extends SendMessageType {
customTemplate: emailChannel.template.contentType === 'customHtml' ? (content as string) : undefined,
data: {
subject,
preheader: emailChannel.template.preheader,
preheader,
branding: {
logo: organization.branding?.logo,
color: organization.branding?.color || '#f47373',
Expand Down Expand Up @@ -360,7 +373,8 @@ export class SendMessageEmail extends SendMessageType {
command: SendMessageCommand,
subscriber: SubscriberEntity,
subject,
organization: OrganizationEntity
organization: OrganizationEntity,
preheader
): Promise<string | IEmailBlock[]> {
if (isEditorMode) {
const content: IEmailBlock[] = [...emailChannel.template.content] as IEmailBlock[];
Expand All @@ -369,23 +383,8 @@ export class SendMessageEmail extends SendMessageType {
* We need to trim the content in order to avoid mail provider like GMail
* to display the mail with `[Message clipped]` footer.
*/
block.content = await this.renderContent(
block.content,
subject,
organization,
subscriber,
command,
emailChannel.template.preheader
);
block.content = block.content.trim();
block.url = await this.renderContent(
block.url || '',
subject,
organization,
subscriber,
command,
emailChannel.template.preheader
);
block.content = await this.renderContent(block.content, subject, organization, subscriber, command, preheader);
block.url = await this.renderContent(block.url || '', subject, organization, subscriber, command, preheader);
}

return content;
Expand All @@ -402,7 +401,7 @@ export class SendMessageEmail extends SendMessageType {
command: SendMessageCommand,
preheader?: string
) {
return await this.compileTemplate.execute(
const renderedContent = await this.compileTemplate.execute(
CompileTemplateCommand.create({
templateId: 'custom',
customTemplate: content as string,
Expand All @@ -424,5 +423,7 @@ export class SendMessageEmail extends SendMessageType {
},
})
);

return renderedContent.trim();
}
}