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

Feat/prep before signal #191

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
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
41 changes: 41 additions & 0 deletions src/components/menu-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export default function MenuItem({
className="m-2 mr-6"
/>
),
"Caffè Latte": (
<LatteMacchiatoIcon
width="3rem"
height="3rem"
fill="text-black"
className="m-2 mr-6"
/>
),
"Flat White": (
<FlatWhiteIcon
width="3rem"
Expand All @@ -67,6 +75,7 @@ export default function MenuItem({
className="m-2 mr-6"
/>
),

Macchiato: (
<EspressoMacchiatoIcon
width="3rem"
Expand Down Expand Up @@ -115,6 +124,14 @@ export default function MenuItem({
className="m-2 mr-6"
/>
),
"Chocolate": (
<CoffeeCupIcon
width="3rem"
height="3rem"
fill="text-black"
className="m-2 mr-6"
/>
),
Mocha: (
<CupIcon
width="3rem"
Expand All @@ -131,6 +148,30 @@ export default function MenuItem({
className="m-2 mr-6"
/>
),
"British Breakfast Tea": (
<CupIcon
width="3rem"
height="3rem"
fill="text-black"
className="m-2 mr-6"
/>
),
"Apple Chamomile": (
<CupIcon
width="3rem"
height="3rem"
fill="text-black"
className="m-2 mr-6"
/>
),
"Earl Grey": (
<CupIcon
width="3rem"
height="3rem"
fill="text-black"
className="m-2 mr-6"
/>
),
"Herbal Tea": (
<CupIcon
width="3rem"
Expand Down
34 changes: 33 additions & 1 deletion src/config/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,21 @@ export default {
title: "Latte Macchiato",
description: "Milk marked with espresso",
},
{
shortTitle: "Caffè Latte",
title: "Caffè Latte",
description: "Espresso with steamed milk",
},
{
shortTitle: "Cappuccino",
title: "Cappuccino",
description: "Espresso with steamed milk",
},
{
shortTitle: "British Breakfast Tea",
title: "British Breakfast Tea",
description: "Blend of black teas",
},
{
shortTitle: "Espresso Macchiato",
title: "Espresso Macchiato",
Expand Down Expand Up @@ -102,13 +112,35 @@ export default {
title: "Herbal Tea",
description: "Classic, diverse, hot beverage infused with leaves",
},
{
shortTitle: "Apple Chamomile",
title: "Apple Chamomile",
description: "Apple and chamomile tea",
},
{
shortTitle: "Earl Grey",
title: "Earl Grey",
description: "Blend of black tea scented with oil of bergamot",
},
{
shortTitle: "Chai",
title: "Chai",
description: "Spiced tea with milk",
},
{
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
9 changes: 7 additions & 2 deletions src/lib/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export async function getReadyToOrderMessage(
contentVariables[key] = value;
});

const templateName = `${SERVICE_INSTANCE_PREFIX.toLowerCase()}_ready_to_order_${availableOptions.length}`;

const limitess = maxNumberOrders >= 50 ? "_limitless" : "";

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

if (!template) {
Expand Down Expand Up @@ -228,7 +231,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