fix: add question email

pull/100/head
Pierre-Louis Guhur 1 year ago
parent 85a622a75c
commit a2385269ba

@ -38,6 +38,7 @@ Handlebars.registerHelper('i18n',
interface RequestPayload {
recipients: {[email: string]: {[key: string]: string}};
question: string;
locale: string;
action: "invite" | "admin";
}
@ -55,7 +56,7 @@ const handler: Handler = async (event) => {
};
}
const {recipients, action, locale} = JSON.parse(event.body) as RequestPayload;
const {recipients, action, locale, question} = JSON.parse(event.body) as RequestPayload;
if (!recipients) {
return {
@ -64,6 +65,13 @@ const handler: Handler = async (event) => {
};
}
if (!question) {
return {
statusCode: 422,
body: 'The question is missing.',
};
}
if (!action || !["invite", "admin"].includes(action)) {
return {
statusCode: 422,
@ -94,7 +102,7 @@ const handler: Handler = async (event) => {
// from: `${i18next.t("Mieux Voter")} <mailgun@>`,
from: FROM_EMAIL_ADDRESS || '"Mieux Voter" <postmaster@mg.app.mieuxvoter.fr>',
to: Object.keys(recipients),
subject: i18next.t(`email.${action}.subject`),
subject: i18next.t(`email.${action}.subject`, {question}),
txt: contents[0],
html: contents[1],
'h:Reply-To': REPLY_TO_EMAIL_ADDRESS || 'app@mieuxvoter.fr',

@ -1,6 +1,6 @@
import { NextRouter } from 'next/router';
import { getLocaleShort } from './utils';
import { availableLanguages } from '@functions/i18next';
import {NextRouter} from 'next/router';
import {getLocaleShort} from './utils';
import {availableLanguages} from '@functions/i18next';
export const sendInviteMails = async (
mails: Array<string>,
@ -41,6 +41,7 @@ export const sendInviteMails = async (
},
body: JSON.stringify({
action: 'invite',
question: name,
recipients,
locale,
}),
@ -70,6 +71,7 @@ export const sendAdminMail = async (
body: JSON.stringify({
action: 'admin',
locale,
question: name,
recipients: {
[mail]: {
urlAdmin,

Loading…
Cancel
Save