d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
118 lines
3.6 KiB
TypeScript
118 lines
3.6 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import type { TwilioSendSMSParams, TwilioSMSBlockOutput } from '@/tools/twilio/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
const logger = createLogger('Twilio Send SMS Tool')
|
|
|
|
export const sendSMSTool: ToolConfig<TwilioSendSMSParams, TwilioSMSBlockOutput> = {
|
|
id: 'twilio_send_sms',
|
|
name: 'Twilio Send SMS',
|
|
description: 'Send text messages to single or multiple recipients using the Twilio API.',
|
|
version: '1.0.0',
|
|
|
|
params: {
|
|
phoneNumbers: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'Phone numbers to send the message to in E.164 format (e.g., +15551234567), separated by newlines',
|
|
},
|
|
message: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'Message to send',
|
|
},
|
|
accountSid: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Twilio Account SID',
|
|
},
|
|
authToken: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Twilio Auth Token',
|
|
},
|
|
fromNumber: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'Twilio phone number to send the message from in E.164 format (e.g., +15551234567)',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params) => {
|
|
if (!params.accountSid) {
|
|
throw new Error('Twilio Account SID is required')
|
|
}
|
|
const url = `https://api.twilio.com/2010-04-01/Accounts/${params.accountSid}/Messages.json`
|
|
return url
|
|
},
|
|
method: 'POST',
|
|
headers: (params) => {
|
|
if (!params.accountSid || !params.authToken) {
|
|
throw new Error('Twilio credentials are required')
|
|
}
|
|
// Use Buffer instead of btoa for Node.js compatibility
|
|
const authToken = Buffer.from(`${params.accountSid}:${params.authToken}`).toString('base64')
|
|
const headers = {
|
|
Authorization: `Basic ${authToken}`,
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
}
|
|
return headers
|
|
},
|
|
body: (params) => {
|
|
if (!params.phoneNumbers) {
|
|
throw new Error('Phone numbers are required but not provided')
|
|
}
|
|
if (!params.message) {
|
|
throw new Error('Message content is required but not provided')
|
|
}
|
|
if (!params.fromNumber) {
|
|
throw new Error('From number is required but not provided')
|
|
}
|
|
|
|
// Get first phone number if multiple are provided
|
|
const toNumber = params.phoneNumbers.split('\n')[0].trim()
|
|
|
|
// Create a URLSearchParams object and convert to string
|
|
const formData = new URLSearchParams()
|
|
formData.append('To', toNumber)
|
|
formData.append('From', params.fromNumber)
|
|
formData.append('Body', params.message)
|
|
|
|
const formDataString = formData.toString()
|
|
return { body: formDataString }
|
|
},
|
|
},
|
|
|
|
transformResponse: async (response) => {
|
|
const data = await response.json()
|
|
|
|
logger.info('Twilio Response:', data)
|
|
logger.info('Twilio Response type:', typeof data)
|
|
return {
|
|
success: true,
|
|
output: {
|
|
success: true,
|
|
messageId: data.sid,
|
|
status: data.status,
|
|
},
|
|
error: undefined,
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
success: { type: 'boolean', description: 'SMS send success status' },
|
|
messageId: { type: 'string', description: 'Unique Twilio message identifier (SID)' },
|
|
status: { type: 'string', description: 'Message delivery status from Twilio' },
|
|
fromNumber: { type: 'string', description: 'Phone number message was sent from' },
|
|
toNumber: { type: 'string', description: 'Phone number message was sent to' },
|
|
},
|
|
}
|