feat(twilio): add support to have multiple numbers (#1450)

Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
xal3xhx
2021-01-11 13:48:03 -05:00
committed by GitHub
parent c9cda1e4e5
commit 83508bc5ea
+11 -4
View File
@@ -17,17 +17,24 @@ export function sendTwilioMessage(link: Link, store: Store) {
(async () => { (async () => {
const givenUrl = link.cartUrl ? link.cartUrl : link.url; const givenUrl = link.cartUrl ? link.cartUrl : link.url;
const message = `${Print.inStock(link, store)}\n${givenUrl}`; const message = `${Print.inStock(link, store)}\n${givenUrl}`;
const numbers = twilio.to.split(',');
const results = [];
for (const number of numbers) {
try { try {
await client.messages.create({ results.push(
client.messages.create({
body: message, body: message,
from: twilio.from, from: twilio.from,
to: twilio.to to: number
}); })
);
logger.info('✔ twilio message sent'); logger.info('✔ twilio message sent');
} catch (error: unknown) { } catch (error: unknown) {
logger.error("✖ couldn't send twilio message", error); logger.error("✖ couldn't send twilio message", error);
} }
}
await Promise.all(results);
})(); })();
} }
} }