From af5b43b5c23ecf591b4ffead73307beb5d70cd0b Mon Sep 17 00:00:00 2001 From: Marius Obert Date: Mon, 14 Oct 2024 11:37:34 +0200 Subject: [PATCH] add template for limitless orders --- src/config/menus.ts | 15 ++++-- src/lib/templates.ts | 4 +- src/scripts/createTwilioRes.ts | 35 ++++++++++++- src/scripts/getTemplates.ts | 93 ++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 7 deletions(-) diff --git a/src/config/menus.ts b/src/config/menus.ts index 5349feb..e8f863b 100644 --- a/src/config/menus.ts +++ b/src/config/menus.ts @@ -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", @@ -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", @@ -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: [ diff --git a/src/lib/templates.ts b/src/lib/templates.ts index 55bbe32..64cf9a1 100644 --- a/src/lib/templates.ts +++ b/src/lib/templates.ts @@ -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) { diff --git a/src/scripts/createTwilioRes.ts b/src/scripts/createTwilioRes.ts index 0ad1a34..4177b03 100644 --- a/src/scripts/createTwilioRes.ts +++ b/src/scripts/createTwilioRes.ts @@ -9,6 +9,8 @@ import { getWrongOrderTemplate, getReadyToOrderTemplate, getReadyToOrderWithoutEmailValidationTemplate, + getReadyToOrderLimitlessTemplate, + getReadyToOrderLimitlessWithoutEmailValidationTemplate, getEventRegistrationTemplate, WhatsAppTemplate, } from "./getTemplates"; @@ -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( @@ -120,4 +151,4 @@ async function createWhatsAppTemplates() { } export async function createTwilioRes() { await createWhatsAppTemplates(); -} \ No newline at end of file +} diff --git a/src/scripts/getTemplates.ts b/src/scripts/getTemplates.ts index 821f21d..2007b72 100644 --- a/src/scripts/getTemplates.ts +++ b/src/scripts/getTemplates.ts @@ -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, @@ -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,