import type { SubBlockConfig } from '@/blocks/types' import type { TriggerOutput } from '@/triggers/types' export const twilioSmsTriggerOptions = [ { label: 'SMS Received', id: 'twilio_sms_received' }, { label: 'Message Status', id: 'twilio_sms_status' }, ] /** * Account SID + Auth Token fields, used to verify the `X-Twilio-Signature` * header. Added to each trigger (conditioned on its own `selectedTriggerId`) so * the values are captured into `providerConfig` whichever trigger is deployed — * the inner subBlock IDs stay shared so the values persist across trigger types. */ export function buildTwilioSmsAuthFields(triggerId: string): SubBlockConfig[] { const condition = { field: 'selectedTriggerId', value: triggerId, } return [ { id: 'accountSid', title: 'Twilio Account SID', type: 'short-input', placeholder: 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', description: 'Your Twilio Account SID from the Twilio Console', required: true, mode: 'trigger', condition, }, { id: 'authToken', title: 'Auth Token', type: 'short-input', placeholder: 'Your Twilio Auth Token', description: 'Your Twilio Auth Token, used to verify the X-Twilio-Signature header', password: true, paramVisibility: 'user-only', required: true, mode: 'trigger', condition, }, ] } function renderInstructions(steps: string[]): string { return steps .map((step, index) => `
X-Twilio-Signature on every request.',
'Go to your Twilio Console Phone Numbers page and select the number that will receive messages (or open Messaging Services if you use one).',
'In the Messaging Configuration section, set "A MESSAGE COMES IN" to Webhook and paste the Webhook URL.',
'Ensure the HTTP method is set to POST.',
'Save your changes in the Twilio Console, then click "Save" above to activate your trigger.',
])
}
export function twilioSmsStatusInstructions(): string {
return renderInstructions([
'Copy the Webhook URL above — this is your Status Callback URL.',
'Enter your Account SID and Auth Token above so Sim can verify the X-Twilio-Signature on every request.',
'Set the Status Callback URL where your outbound messages are sent from: pass StatusCallback when sending via the API, set the Status Callback URL on your Messaging Service, or set it on your phone number.',
'Twilio will POST a request to this URL each time a message status changes (sent, delivered, undelivered, failed).',
'Ensure the HTTP method is set to POST.',
'Save your changes in the Twilio Console, then click "Save" above to activate your trigger.',
])
}
/**
* Trigger outputs for Twilio SMS webhooks. Shared by both the inbound-message
* and status-callback triggers. Keys MUST stay aligned with the `formatInput`
* implementation in `apps/sim/lib/webhooks/providers/twilio.ts`.
* @see https://www.twilio.com/docs/messaging/guides/webhook-request
* @see https://www.twilio.com/docs/messaging/guides/track-outbound-message-status
*/
export function buildTwilioSmsOutputs(): Record