-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add Twilio SMS notification channel #3534
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
Merged
ajhollid
merged 3 commits into
bluewave-labs:develop
from
egeoztass:feat/twilio-sms-notification
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
server/src/service/infrastructure/notificationProviders/twilio.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| const SERVICE_NAME = "TwilioProvider"; | ||
| import type { Notification } from "@/types/index.js"; | ||
| import { NotificationProvider } from "@/service/infrastructure/notificationProviders/INotificationProvider.js"; | ||
| import type { NotificationMessage } from "@/types/notificationMessage.js"; | ||
| import { getTestMessage } from "@/service/infrastructure/notificationProviders/utils.js"; | ||
| import got from "got"; | ||
|
|
||
| export class TwilioProvider extends NotificationProvider { | ||
| async sendTestAlert(notification: Partial<Notification>): Promise<boolean> { | ||
| if (!notification.accountSid || !notification.accessToken || !notification.phone || !notification.twilioPhoneNumber) { | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| await got.post(`https://api.twilio.com/2010-04-01/Accounts/${notification.accountSid}/Messages.json`, { | ||
| form: { | ||
| To: notification.phone, | ||
| From: notification.twilioPhoneNumber, | ||
| Body: getTestMessage(), | ||
| }, | ||
| username: notification.accountSid, | ||
| password: notification.accessToken, | ||
| ...this.gotRequestOptions(), | ||
| }); | ||
| return true; | ||
| } catch (error) { | ||
| const errMsg = error instanceof Error ? error.message : "unknown error"; | ||
| const errStack = error instanceof Error ? error.stack : undefined; | ||
| this.logger.warn({ | ||
| message: "Twilio test alert failed", | ||
| service: SERVICE_NAME, | ||
| method: "sendTestAlert", | ||
| stack: errStack, | ||
| details: { error: errMsg }, | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| async sendMessage(notification: Notification, message: NotificationMessage): Promise<boolean> { | ||
| if (!notification.accountSid || !notification.accessToken || !notification.phone || !notification.twilioPhoneNumber) { | ||
| return false; | ||
| } | ||
|
|
||
| const text = this.buildSmsText(message); | ||
|
|
||
| try { | ||
| await got.post(`https://api.twilio.com/2010-04-01/Accounts/${notification.accountSid}/Messages.json`, { | ||
| form: { | ||
| To: notification.phone, | ||
| From: notification.twilioPhoneNumber, | ||
| Body: text, | ||
| }, | ||
| username: notification.accountSid, | ||
| password: notification.accessToken, | ||
| ...this.gotRequestOptions(), | ||
| }); | ||
|
|
||
| this.logger.info({ | ||
| message: "Twilio SMS notification sent", | ||
| service: SERVICE_NAME, | ||
| method: "sendMessage", | ||
| }); | ||
| return true; | ||
| } catch (error) { | ||
| const errMsg = error instanceof Error ? error.message : "unknown error"; | ||
| const errStack = error instanceof Error ? error.stack : undefined; | ||
| this.logger.warn({ | ||
| message: "Twilio SMS alert failed", | ||
| service: SERVICE_NAME, | ||
| method: "sendMessage", | ||
| stack: errStack, | ||
| details: { error: errMsg }, | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private buildSmsText(message: NotificationMessage): string { | ||
| const lines: string[] = []; | ||
|
|
||
| lines.push(message.content.title); | ||
| lines.push(message.content.summary); | ||
| lines.push(""); | ||
| lines.push(`URL: ${message.monitor.url}`); | ||
| lines.push(`Status: ${message.monitor.status}`); | ||
|
|
||
| if (message.content.thresholds && message.content.thresholds.length > 0) { | ||
| message.content.thresholds.forEach((breach) => { | ||
| lines.push(`${breach.metric.toUpperCase()}: ${breach.formattedValue}`); | ||
| }); | ||
| } | ||
|
|
||
| return lines.join("\n"); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care if these are returned unmasked? I don't know if these are sensitive or not