diff --git a/docs/examples/connectors/twilio/fixture.json b/docs/examples/connectors/twilio/fixture.json new file mode 100644 index 0000000..2b9c72e --- /dev/null +++ b/docs/examples/connectors/twilio/fixture.json @@ -0,0 +1,24 @@ +{ + "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + "api_version": "2010-04-01", + "body": "Hello from Vejas! Your verification code is 123456.", + "date_created": "Mon, 23 Nov 2026 12:00:00 +0000", + "date_sent": "Mon, 23 Nov 2026 12:00:01 +0000", + "date_updated": "Mon, 23 Nov 2026 12:00:01 +0000", + "direction": "outbound-api", + "error_code": null, + "error_message": null, + "from": "+15551234567", + "messaging_service_sid": null, + "num_media": "0", + "num_segments": "1", + "price": "-0.00750", + "price_unit": "USD", + "sid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + "status": "sent", + "subresource_uris": { + "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json" + }, + "to": "+15559876543", + "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json" +} diff --git a/docs/examples/connectors/twilio/mock.mjs b/docs/examples/connectors/twilio/mock.mjs new file mode 100644 index 0000000..61d4bf1 --- /dev/null +++ b/docs/examples/connectors/twilio/mock.mjs @@ -0,0 +1,130 @@ +#!/usr/bin/env node +// Mock Twilio API server for admission testing +// Simulates /2010-04-01/Accounts/{AccountSid}/Messages.json endpoint + +import http from 'http'; + +const server = http.createServer((req, res) => { + // CORS headers + res.setHeader('Access-Control-Allow-Origin', '*'); + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); + res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type'); + + if (req.method === 'OPTIONS') { + res.writeHead(200); + res.end(); + return; + } + + const url = new URL(req.url, `http://${req.headers.host}`); + + // POST /2010-04-01/Accounts/{AccountSid}/Messages.json - send SMS + if (req.method === 'POST' && url.pathname.match(/^\/2010-04-01\/Accounts\/[^\/]+\/Messages\.json$/)) { + let body = ''; + req.on('data', chunk => body += chunk); + req.on('end', () => { + // Parse URL-encoded form data + const params = new URLSearchParams(body); + const to = params.get('To'); + const from = params.get('From'); + const messageBody = params.get('Body'); + + if (!to || !from || !messageBody) { + res.writeHead(400, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ + code: 21602, + message: 'Message body is required', + status: 400 + })); + return; + } + + const now = new Date().toUTCString(); + res.writeHead(201, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ + account_sid: 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + api_version: '2010-04-01', + body: messageBody, + date_created: now, + date_sent: now, + date_updated: now, + direction: 'outbound-api', + error_code: null, + error_message: null, + from: from, + messaging_service_sid: null, + num_media: '0', + num_segments: '1', + price: '-0.00750', + price_unit: 'USD', + sid: 'SM' + Date.now().toString(36).toUpperCase(), + status: 'sent', + subresource_uris: { + media: `/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SM${Date.now()}/Media.json` + }, + to: to, + uri: `/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SM${Date.now()}.json` + })); + }); + return; + } + + // GET /2010-04-01/Accounts/{AccountSid}/Messages.json - list messages + if (req.method === 'GET' && url.pathname.match(/^\/2010-04-01\/Accounts\/[^\/]+\/Messages\.json$/)) { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ + messages: [ + { + account_sid: 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + sid: 'SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + body: 'Test message', + from: '+15551234567', + to: '+15559876543', + status: 'delivered', + date_created: new Date().toUTCString() + } + ], + page: 0, + page_size: 50, + uri: '/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json' + })); + return; + } + + // POST /2010-04-01/Accounts/{AccountSid}/Calls.json - make call + if (req.method === 'POST' && url.pathname.match(/^\/2010-04-01\/Accounts\/[^\/]+\/Calls\.json$/)) { + let body = ''; + req.on('data', chunk => body += chunk); + req.on('end', () => { + const params = new URLSearchParams(body); + const to = params.get('To'); + const from = params.get('From'); + const url = params.get('Url'); + + res.writeHead(201, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ + account_sid: 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + sid: 'CA' + Date.now().toString(36).toUpperCase(), + from: from, + to: to, + status: 'queued', + direction: 'outbound-api', + date_created: new Date().toUTCString() + })); + }); + return; + } + + // 404 for unknown endpoints + res.writeHead(404, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ + code: 20404, + message: 'The requested resource was not found', + status: 404 + })); +}); + +const PORT = process.env.PORT || 8082; +server.listen(PORT, () => { + console.log(`Mock Twilio API listening on port ${PORT}`); +}); diff --git a/docs/examples/connectors/twilio/overrides.json b/docs/examples/connectors/twilio/overrides.json new file mode 100644 index 0000000..c99747d --- /dev/null +++ b/docs/examples/connectors/twilio/overrides.json @@ -0,0 +1,4 @@ +{ + "BASE_URL": "http://localhost:8082/2010-04-01", + "SUBJECT": "vx.twilio.test.send" +} diff --git a/docs/examples/connectors/twilio/twilio.vjs.example b/docs/examples/connectors/twilio/twilio.vjs.example new file mode 100644 index 0000000..96ce29b --- /dev/null +++ b/docs/examples/connectors/twilio/twilio.vjs.example @@ -0,0 +1,43 @@ +# connector: twilio — Comprehensive Twilio API integration +# +# Platform connector for Twilio communications. Supports multiple operations: +# - SMS (send, retrieve, list messages) +# - Voice (make calls, retrieve call logs) +# - WhatsApp (send messages via WhatsApp Business API) +# - Verify (send verification codes, check verification) +# - Programmable Messaging (send bulk messages) +# +# Uses http-out driver for outbound API calls. Flows consume from subjects +# and make direct API calls to Twilio endpoints. +# +# Subjects: +# IN: vx.twilio.sms.send (send SMS messages) +# IN: vx.twilio.voice.call (initiate voice calls) +# IN: vx.twilio.whatsapp.send (send WhatsApp messages) +# +# Secrets: +# twilio/account_sid - Twilio Account SID (ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX) +# twilio/auth_token - Twilio Auth Token +# +# Rate limits: Varies by account type (default: 1 req/s for trial accounts) +# Pagination: Cursor-based via PageToken parameter +# +# Authentication: HTTP Basic Auth (Account SID as username, Auth Token as password) +# API Version: 2010-04-01 (in URL path) + +driver "http-out" + +# Base configuration +SUBJECT = "vx.twilio.sms.send" +BASE_URL = "https://api.twilio.com/2010-04-01" +METHOD = "POST" + +# Authentication - Basic Auth with Account SID and Auth Token +HEADERS = { + Authorization: "Basic " + base64(secret("twilio/account_sid") + ":" + secret("twilio/auth_token")), + "Content-Type": "application/x-www-form-urlencoded" +} + +# SMS endpoint template +# Actual endpoint: /Accounts/{AccountSid}/Messages.json +# Body parameters: To, From, Body (URL-encoded form data)