Templating for names and surnames
This commit is contained in:
@@ -16,6 +16,16 @@ interface EmailResult {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces template variables in a string with participant data
|
||||
* Currently supports {name} and {surname} placeholders
|
||||
*/
|
||||
function replaceTemplateVariables(template: string, participant: Participant): string {
|
||||
return template
|
||||
.replace(/{name}/gi, participant.name || '')
|
||||
.replace(/{surname}/gi, participant.surname || '');
|
||||
}
|
||||
|
||||
async function generateQRCode(participantId: string): Promise<string> {
|
||||
const qrCodeBase64 = await QRCode.toDataURL(participantId, {
|
||||
type: 'image/png',
|
||||
@@ -38,11 +48,15 @@ async function sendEmailToParticipant(
|
||||
try {
|
||||
const qrCodeBase64Data = await generateQRCode(participant.id);
|
||||
|
||||
// Replace template variables in subject and body
|
||||
const personalizedSubject = replaceTemplateVariables(subject, participant);
|
||||
const personalizedText = replaceTemplateVariables(text, participant);
|
||||
|
||||
// Send email with QR code
|
||||
await sendGmail(refreshToken, {
|
||||
to: participant.email,
|
||||
subject: subject,
|
||||
text: text,
|
||||
subject: personalizedSubject,
|
||||
text: personalizedText,
|
||||
qr_code: qrCodeBase64Data
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user