From 971fec20e441e2b12a38d5c8d17d2d4cb5e64d6b Mon Sep 17 00:00:00 2001 From: admon84 Date: Fri, 18 Sep 2020 19:39:30 -0600 Subject: [PATCH] fix: sms carrier config, add google carrier (#44) --- .env.example | 2 +- README.md | 2 +- src/config.ts | 2 +- src/notification/index.ts | 5 +++-- src/notification/sms.ts | 14 +++++++------- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 3ff82b9b8b..4aa1dab2c5 100644 --- a/.env.example +++ b/.env.example @@ -7,4 +7,4 @@ SLACK_CHANNEL="SlackChannelName" SLACK_TOKEN="slack-token" STORES="bestbuy,bandh,nvidia" PHONE_NUMBER="1234567890" -CARRIER="tmobile" \ No newline at end of file +PHONE_CARRIER="tmobile" \ No newline at end of file diff --git a/README.md b/README.md index f72d6342b0..f963c31b01 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ First, you're going to need to copy the `.env.example` to `.env`. The current op | `NOTIFICATION_TEST` | Test all the notifications configured; optional, default: `false` | | `PAGE_TIMEOUT` | Navigation Timeout in milliseconds (`0` for infinite); optional, default: `30000` | | `PHONE_NUMBER` | 10 digit phone number, only USA, SMS may apply (e.g., `1234567890`); optional, email configuration required | -| `PHONE_CARRIER` | Service provider for SMS, supports `["sprint", "tmobile", "att", "verizon"]`; optional, email configuration required | +| `PHONE_CARRIER` | Service provider for SMS, supports `["sprint", "tmobile", "att", "verizon", "google"]`; optional, email configuration required | | `RATE_LIMIT_TIMEOUT` | Rate limit timeout for each full store cycle; optional, default: `5000` | | `SLACK_CHANNEL` | Slack channel for posting (e.g., `update`); optional | | `SLACK_TOKEN` | Slack API token; optional diff --git a/src/config.ts b/src/config.ts index 7aba1d3e5a..27e249caad 100644 --- a/src/config.ts +++ b/src/config.ts @@ -9,7 +9,7 @@ const notifications = { password: process.env.EMAIL_PASSWORD ?? '' }, phone: { - availableCarriers: ['sprint', 'verizon', 'tmobile', 'att'], + availableCarriers: ['sprint', 'verizon', 'tmobile', 'att', 'google'], carrier: process.env.PHONE_CARRIER, number: process.env.PHONE_NUMBER }, diff --git a/src/notification/index.ts b/src/notification/index.ts index 63fcc5fa5a..113db25139 100644 --- a/src/notification/index.ts +++ b/src/notification/index.ts @@ -12,8 +12,9 @@ export default function sendNotification(cartUrl: string) { sendSlaskMessage(cartUrl); } - if (Config.notifications.phone.number && Config.notifications.phone.carrier) { - if (Config.notifications.phone.availableCarriers.includes(Config.notifications.phone.carrier.toLowerCase())) { + if (Config.notifications.phone.number) { + const carrier = Config.notifications.phone.carrier?.toLowerCase(); + if (carrier && Config.notifications.phone.availableCarriers.includes(carrier)) { sendSMS(cartUrl); } } diff --git a/src/notification/sms.ts b/src/notification/sms.ts index f1552a4c9e..e93f97cc57 100644 --- a/src/notification/sms.ts +++ b/src/notification/sms.ts @@ -9,7 +9,8 @@ enum carrierAddress { sprint = 'messaging.sprintpcs.com', verizon = 'vtext.com', tmobile = 'tmomail.net', - att = 'txt.att.net' + att = 'txt.att.net', + google = 'msg.fi.google.com' } const transporter = nodemailer.createTransport({ @@ -34,16 +35,15 @@ export default function sendSMS(text: string) { Logger.error(error); } else { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - Logger.info(`✔ email sent: ${info.response}`); + Logger.info(`✔ sms sent: ${info.response}`); } }); } function generateAddress() { - for (const carrier of Object.keys(carrierAddress)) { - if (Config.notifications.phone.carrier && carrier === Config.notifications.phone.carrier.toLowerCase()) { - // @ts-expect-error - return [Config.phone.number, carrierAddress[carrier]].join('@'); - } + const carrier = Config.notifications.phone.carrier?.toLowerCase(); + if (carrier && Object.keys(carrierAddress).includes(carrier)) { + // @ts-expect-error + return [Config.notifications.phone.number, carrierAddress[carrier]].join('@'); } }