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
+17 -10
View File
@@ -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);
})();
}
}