Skip to content

Commit

Permalink
add template for limitless orders
Browse files Browse the repository at this point in the history
  • Loading branch information
IObert committed Oct 14, 2024
1 parent a67cf83 commit af5b43b
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/config/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default {
shortTitle: "British Breakfast Tea",
title: "British Breakfast Tea",
description: "Blend of black teas",
}
},
{
shortTitle: "Espresso Macchiato",
title: "Espresso Macchiato",
Expand Down Expand Up @@ -121,7 +121,7 @@ export default {
shortTitle: "Earl Grey",
title: "Earl Grey",
description: "Blend of black tea scented with oil of bergamot",
}
},
{
shortTitle: "Chai",
title: "Chai",
Expand All @@ -131,9 +131,16 @@ export default {
shortTitle: "Chocolate",
title: "Hot Chocolate",
description: "Hot cocoa",
}
},
],
modifiers: [
"Milk",
"Soy Milk",
"Almond Milk",
"Oat Milk",
"Coconut Milk",
"Rice Milk",
],
modifiers: ["Milk", "Soy Milk", "Almond Milk", "Oat Milk", "Coconut Milk", "Rice Milk"],
},
smoothie: {
items: [
Expand Down
4 changes: 3 additions & 1 deletion src/lib/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ export async function getReadyToOrderWithoutEmailValidationMessage(
contentVariables[key] = value;
});

const templateName = `${SERVICE_INSTANCE_PREFIX.toLowerCase()}_ready_to_order_without_email_${availableOptions.length}`;
const limitess = maxNumberOrders >= 50 ? "_limitless" : "";

const templateName = `${SERVICE_INSTANCE_PREFIX.toLowerCase()}_ready_to_order_${limitess}without_email_${availableOptions.length}`;
const template = templates.find((t) => t.friendly_name === templateName);

if (!template) {
Expand Down
35 changes: 33 additions & 2 deletions src/scripts/createTwilioRes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
getWrongOrderTemplate,
getReadyToOrderTemplate,
getReadyToOrderWithoutEmailValidationTemplate,
getReadyToOrderLimitlessTemplate,
getReadyToOrderLimitlessWithoutEmailValidationTemplate,
getEventRegistrationTemplate,
WhatsAppTemplate,
} from "./getTemplates";
Expand Down Expand Up @@ -95,13 +97,42 @@ async function createWhatsAppTemplates() {
);
console.log(`Created Template "${templateName}" ${template.sid}`);
}

// 5. Check the post_registration_limitless-templates
templateName = `${CONTENT_PREFIX}ready_to_order_limitless_${numOptions}`;
if (templates.find((c) => c.friendly_name === templateName)) {
console.log(
`Skip creating Template because "${templateName}" already exists`,
);
} else {
template = await createWhatsAppTemplate(
getReadyToOrderLimitlessTemplate(numOptions, templateName),
);
console.log(`Created Template "${templateName}" ${template.sid}`);
}

// 6. Check the post_registration_limitless_without_email-templates
templateName = `${CONTENT_PREFIX}ready_to_order_limitless_without_email_${numOptions}`;
if (templates.find((c) => c.friendly_name === templateName)) {
console.log(
`Skip creating Template because "${templateName}" already exists`,
);
} else {
template = await createWhatsAppTemplate(
getReadyToOrderLimitlessWithoutEmailValidationTemplate(
numOptions,
templateName,
),
);
console.log(`Created Template "${templateName}" ${template.sid}`);
}
}
for (
let numOptions = 2;
numOptions <= MAX_CONCURRENT_EVENTS;
numOptions++
) {
// 4. Check the event_registration-templates
// 6. Check the event_registration-templates
templateName = `${CONTENT_PREFIX}event_registration_${numOptions}`;
if (templates.find((c) => c.friendly_name === templateName)) {
console.log(
Expand All @@ -120,4 +151,4 @@ async function createWhatsAppTemplates() {
}
export async function createTwilioRes() {
await createWhatsAppTemplates();
}
}
93 changes: 93 additions & 0 deletions src/scripts/getTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,52 @@ export function getReadyToOrderTemplate(
};
}

export function getReadyToOrderLimitlessTemplate(
numOptions: number,
templateName: string,
): WhatsAppTemplateConfig {
// The first variable defines the mode and second is not used
// and then 3 additional vars (short title, full title, desc) per options => numOptions * 3 + 1

const variables = Array.from(Array(numOptions * 3 + 1).keys()).reduce(
(accu: any, idx) => {
accu[idx] = "";
return accu;
},
{},
);

const indiciesOfFullTitles = [],
items = [];
for (let i = 0; i < numOptions; i++) {
indiciesOfFullTitles.push(`- {{${i * 3 + 2}}}`);
items.push({
item: `{{${i * 3 + 3}}}`,
id: `{{${i * 3 + 3}}}`,
description: `{{${i * 3 + 4}}}`,
});
}

const body = `Thank you! Your email address has been verified. What would you like? The options are:\n${indiciesOfFullTitles.join(
"\n",
)}\n`;

return {
friendly_name: templateName,
language: "en",
variables,
types: {
"twilio/list-picker": {
body,
items,
button: "More Details",
},
"twilio/text": {
body: body,
},
},
};
}

export function getReadyToOrderWithoutEmailValidationTemplate(
numOptions: number,
Expand Down Expand Up @@ -182,6 +228,53 @@ export function getReadyToOrderWithoutEmailValidationTemplate(
};
}

export function getReadyToOrderLimitlessWithoutEmailValidationTemplate(
numOptions: number,
templateName: string,
): WhatsAppTemplateConfig {
// The first variable defines the mode and second is not used
// and then 3 additional vars (short title, full title, desc) per options => numOptions * 3 + 1

const variables = Array.from(Array(numOptions * 3 + 1).keys()).reduce(
(accu: any, idx) => {
accu[idx] = "";
return accu;
},
{},
);

const indiciesOfFullTitles = [],
items = [];
for (let i = 0; i < numOptions; i++) {
indiciesOfFullTitles.push(`- {{${i * 3 + 2}}}`);
items.push({
item: `{{${i * 3 + 3}}}`,
id: `{{${i * 3 + 3}}}`,
description: `{{${i * 3 + 4}}}`,
});
}

const body = `What would you like? The options are:\n${indiciesOfFullTitles.join(
"\n",
)}\n`;

return {
friendly_name: templateName,
language: "en",
variables,
types: {
"twilio/list-picker": {
body,
items,
button: "More Details",
},
"twilio/text": {
body: body,
},
},
};
}

export function getEventRegistrationTemplate(
numOptions: number,
templateName: string,
Expand Down

0 comments on commit af5b43b

Please sign in to comment.