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(twilio): add support to have multiple numbers #1450

Merged
merged 6 commits into from
Jan 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/notification/twilio.ts
Original file line number Diff line number Diff line change
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);
})();
}
}