fix: use dedicated Twilio fields and add service switch case tests

- Added `accountSid` and `twilioPhoneNumber` fields to Notification
  type, MongoDB model, and frontend type instead of reusing
  `address` and `homeserverUrl`
- Updated provider, validation, form hook, and form UI to use new fields
- Added Pushover and Twilio to notificationsService routing tests
  (both handleNotifications and sendTestNotification)
- All 59 tests passing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
egeoztassandClaude Opus 4.6 committed 2026-04-17 23:11:11 +03:00
1 parent 9210259511
commit d5d6797f91
10 files changed
+40 -27

No files matched your search

+2
View File
@@ -37,6 +37,8 @@ const NotificationSchema = new Schema<NotificationDocument>(
homeserverUrl: { type: String },
roomId: { type: String },
accessToken: { type: String },
accountSid: { type: String },
twilioPhoneNumber: { type: String },
},
{
timestamps: true,
@@ -7,18 +7,18 @@ import got from "got";
export class TwilioProvider extends NotificationProvider {
async sendTestAlert(notification: Partial<Notification>): Promise<boolean> {
if (!notification.address || !notification.accessToken || !notification.phone || !notification.homeserverUrl) {
if (!notification.accountSid || !notification.accessToken || !notification.phone || !notification.twilioPhoneNumber) {
return false;
}
try {
await got.post(`https://api.twilio.com/2010-04-01/Accounts/${notification.address}/Messages.json`, {
await got.post(`https://api.twilio.com/2010-04-01/Accounts/${notification.accountSid}/Messages.json`, {
form: {
To: notification.phone,
From: notification.homeserverUrl,
From: notification.twilioPhoneNumber,
Body: getTestMessage(),
},
username: notification.address,
username: notification.accountSid,
password: notification.accessToken,
...this.gotRequestOptions(),
});
@@ -38,20 +38,20 @@ export class TwilioProvider extends NotificationProvider {
}
async sendMessage(notification: Notification, message: NotificationMessage): Promise<boolean> {
if (!notification.address || !notification.accessToken || !notification.phone || !notification.homeserverUrl) {
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.address}/Messages.json`, {
await got.post(`https://api.twilio.com/2010-04-01/Accounts/${notification.accountSid}/Messages.json`, {
form: {
To: notification.phone,
From: notification.homeserverUrl,
From: notification.twilioPhoneNumber,
Body: text,
},
username: notification.address,
username: notification.accountSid,
password: notification.accessToken,
...this.gotRequestOptions(),
});
+2
View File
@@ -23,6 +23,8 @@ export interface Notification {
homeserverUrl?: string;
roomId?: string;
accessToken?: string;
accountSid?: string;
twilioPhoneNumber?: string;
createdAt: string;
updatedAt: string;
}
@@ -83,10 +83,10 @@ export const createNotificationBodyValidation = z.discriminatedUnion("type", [
z.object({
notificationName: z.string().min(1, "Notification name is required"),
type: z.literal("twilio"),
address: z.string().min(1, "Account SID is required"),
accountSid: z.string().min(1, "Account SID is required"),
accessToken: z.string().min(1, "Auth token is required"),
phone: z.string().min(1, "Recipient phone number is required"),
homeserverUrl: z.string().min(1, "Twilio phone number is required"),
twilioPhoneNumber: z.string().min(1, "Twilio phone number is required"),
}),
]);