Skip to content

Commit

Permalink
feat(twilio): add support to have multiple numbers (#1450)
Browse files Browse the repository at this point in the history
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
  • Loading branch information
xal3xhx and jef committed Jan 11, 2021
1 parent c9cda1e commit 83508bc
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/notification/twilio.ts
Expand Up @@ -17,17 +17,24 @@ export function sendTwilioMessage(link: Link, store: Store) {
(async () => {
const givenUrl = link.cartUrl ? link.cartUrl : link.url;
const message = `${Print.inStock(link, store)}\n${givenUrl}`;

try {
await client.messages.create({
body: message,
from: twilio.from,
to: twilio.to
});
logger.info('✔ twilio message sent');
} catch (error: unknown) {
logger.error("✖ couldn't send twilio message", error);
const numbers = twilio.to.split(',');
const results = [];
for (const number of numbers) {
try {
results.push(
client.messages.create({
body: message,
from: twilio.from,
to: number
})
);
logger.info('✔ twilio message sent');
} catch (error: unknown) {
logger.error("✖ couldn't send twilio message", error);
}
}

await Promise.all(results);
})();
}
}

0 comments on commit 83508bc

Please sign in to comment.