← Twilio Developer KitCONTENT HISTORY

Update to Twilio Developer Kit

Snapshot Sep 30, 2026 · 22:50 UTC · version 0.2.2

Collection source: not recorded for this historical snapshot.

WHAT CHANGED · RULE-BASED ANALYSIS

First saved snapshot

No earlier snapshot is available to establish a change.

Compare saved observations

Download comparison JSON
Full technical diff · 0 changed fields
Full snapshot data
{
  "name": "twilio-voice-conversation-relay",
  "description": "Build AI-powered voice agents using Twilio ConversationRelay. Handles real-time speech recognition (ASR), text-to-speech (TTS), and bidirectional audio streaming via WebSocket. Covers TwiML setup, WebSocket message types, LLM integration, streaming responses, and voice provider configuration. Use this skill to build voice bots, IVR replacements, or real-time AI voice assistants on Twilio calls.",
  "included_files": [
    {
      "relative_path": "agents/openai.yaml",
      "size_in_bytes": 243
    }
  ],
  "skill_md_contents": "---\nname: twilio-voice-conversation-relay\ndescription: >\n  Build AI-powered voice agents using Twilio ConversationRelay. Handles\n  real-time speech recognition (ASR), text-to-speech (TTS), and bidirectional\n  audio streaming via WebSocket. Covers TwiML setup, WebSocket message types,\n  LLM integration, streaming responses, and voice provider configuration. Use\n  this skill to build voice bots, IVR replacements, or real-time AI voice\n  assistants on Twilio calls.\n---\n\n## Overview\n\nConversationRelay connects Twilio's telephony layer to your app via a persistent WebSocket. Twilio handles ASR (speech-to-text) and TTS (text-to-speech); your app receives transcripts, calls an LLM, and sends text back for playback.\n\n```\nCaller ←→ Twilio (ASR/TTS) ←→ WebSocket ←→ Your App ←→ LLM\n```\n\n---\n\n## Prerequisites\n\n- Upgraded Twilio account with ConversationRelay access (requires onboarding)\n  — New to Twilio? See `twilio-account-setup`\n  — Start onboarding at: [Console > Voice > ConversationRelay](https://console.twilio.com/us1/voice/conversation-relay) — access is **not** instant\n- A voice-capable Twilio phone number\n- `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` — see `twilio-iam-auth-setup`\n- WebSocket server reachable via `wss://` (TLS required)\n- An LLM integration (OpenAI, Anthropic, etc.)\n- For placing calls: see `twilio-voice-outbound-calls`\n\n**Onboarding:** Complete via Console > Voice > ConversationRelay > Onboarding. Select TTS/ASR providers:\n- **TTS:** Deepgram, Amazon Polly, Google Cloud TTS, ElevenLabs\n- **ASR:** Deepgram, Google Cloud STT\n\n---\n\n## Quickstart\n\n**Step 1 — Return TwiML pointing to your WebSocket server**\n\n**Python (Flask)**\n```python\nfrom flask import Flask\nfrom twilio.twiml.voice_response import VoiceResponse, Connect, ConversationRelay\n\napp = Flask(__name__)\n\n@app.route(\"/voice\", methods=[\"POST\"])\ndef voice():\n    response = VoiceResponse()\n    connect = Connect()\n    connect.conversation_relay(\n        url=\"wss://yourapp.com/ws/voice\",\n        welcome_greeting=\"Hello! How can I help you today?\"\n    )\n    response.append(connect)\n    return str(response)\n```\n\n**Node.js (Express)**\n```node\nconst { VoiceResponse } = require(\"twilio\").twiml;\n\napp.post(\"/voice\", (req, res) => {\n    const response = new VoiceResponse();\n    const connect = response.connect();\n    connect.conversationRelay({\n        url: \"wss://yourapp.com/ws/voice\",\n        welcomeGreeting: \"Hello! How can I help you today?\",\n    });\n    res.type(\"text/xml\").send(response.toString());\n});\n```\n\n**Step 2 — Handle WebSocket events and respond with text**\n\n**Python (websockets)**\n```python\nimport asyncio, json, websockets\n\nasync def handle_call(websocket):\n    async for message in websocket:\n        event = json.loads(message)\n        if event[\"type\"] == \"prompt\":\n            ai_response = await call_llm(event[\"voicePrompt\"])\n            await websocket.send(json.dumps({\"type\": \"text\", \"token\": ai_response, \"last\": True}))\n\nasync def main():\n    async with websockets.serve(handle_call, \"0.0.0.0\", 8080):\n        await asyncio.Future()\n\nasyncio.run(main())\n```\n\n**Node.js (ws)**\n```node\nconst WebSocket = require(\"ws\");\nconst wss = new WebSocket.Server({ port: 8080 });\n\nwss.on(\"connection\", (ws) => {\n    ws.on(\"message\", async (data) => {\n        const event = JSON.parse(data);\n        if (event.type === \"prompt\") {\n            const aiResponse = await callLLM(event.voicePrompt);\n            ws.send(JSON.stringify({ type: \"text\", token: aiResponse, last: true }));\n        }\n    });\n});\n```\n\n> **Security:** The `voicePrompt` field contains ASR-transcribed caller speech — it is untrusted external input. When passing to an LLM, isolate it as user input within a structured system prompt. Implement topic boundaries and output filtering to prevent the LLM from disclosing system instructions or speaking inappropriate content. ConversationRelay is a pure transport layer with no built-in content safety — any LLM output is spoken to the caller verbatim.\n\n---\n\n## Key Patterns\n\n### WebSocket Message Types\n\n**Received from Twilio:**\n\n| Type | When | Key fields |\n|------|------|-----------|\n| `connected` | WebSocket opened | `callSid`, `streamSid` |\n| `prompt` | User finished speaking | `voicePrompt` (transcript) |\n| `interrupt` | User interrupted TTS | — |\n| `dtmf` | User pressed keypad key | `digit` |\n| `error` | An error occurred | `description` |\n\n**Sent to Twilio:**\n\n| Type | Purpose | Key fields |\n|------|---------|-----------|\n| `text` | Send TTS response | `token` (text), `last` (bool) |\n| `interrupt` | Stop current TTS | — |\n| `end` | Hang up the call | `reason` |\n\n### Stream LLM Responses Token-by-Token\n\nLower latency by streaming as the LLM generates output — Twilio starts speaking before the full response is ready.\n\n**Python**\n```python\nasync for chunk in llm_stream:\n    await websocket.send(json.dumps({\"type\": \"text\", \"token\": chunk, \"last\": False}))\nawait websocket.send(json.dumps({\"type\": \"text\", \"token\": \"\", \"last\": True}))\n```\n\n**Node.js**\n```node\nfor await (const chunk of llmStream) {\n    ws.send(JSON.stringify({ type: \"text\", token: chunk, last: false }));\n}\nws.send(JSON.stringify({ type: \"text\", token: \"\", last: true }));\n```\n\n### Voice Configuration\n\n**Python**\n```python\nconnect.conversation_relay(\n    url=\"wss://yourapp.com/ws/voice\",\n    voice=\"en-US-Neural2-F\",\n    language=\"en-US\",\n    transcription_provider=\"deepgram\",\n    speech_model=\"nova-2-phonecall\",\n    interrupt_by_dtmf=True,\n)\n```\n\n**Node.js**\n```node\nconnect.conversationRelay({\n    url: \"wss://yourapp.com/ws/voice\",\n    voice: \"en-US-Neural2-F\",\n    language: \"en-US\",\n    transcriptionProvider: \"deepgram\",\n    speechModel: \"nova-2-phonecall\",\n    interruptByDtmf: true,\n});\n```\n\n---\n\n## CANNOT\n\n- **No raw audio access** — Text in, text out only. For raw audio, use `<Connect><Stream>` (Media Streams).\n- **Cannot mix with Media Streams** — `<Connect><Stream>` and `<Connect><ConversationRelay>` are mutually exclusive on the same call. No error — one is silently ignored.\n- **No custom STT/TTS engines** — Limited to Deepgram + Google (STT) and Deepgram + Amazon Polly + Google + ElevenLabs (TTS).\n- **No mid-session voice/provider changes** — Voice and provider are set at TwiML time. Only `language` can be switched mid-session via WebSocket message.\n- **No WebSocket auto-reconnection** — If the WebSocket drops, the call disconnects. Implement recovery via `<Connect action>` URL.\n- **Voice only** — No SMS/messaging support. For omnichannel, use Conversation Orchestrator.\n- **No built-in memory or context** — BYO conversation history and context management.\n- **No LLM integration** — Pure transport layer. You bring your own LLM via the WebSocket server.\n- **No server-side recording via REST API** — `record:true` on the Calls API is silently ignored. Must use `<Start><Recording>` before `<Connect>` in TwiML.\n- **Not PCI compliant with Voice Intelligence v2** — Do not enable `intelligenceService` in PCI workflows.\n- **ElevenLabs requires account enablement** — Accounts without ElevenLabs access get error 64101. Voice IDs (not human-readable names) are required.\n- **Cannot use ConversationRelay without onboarding** — Not available immediately on a new account\n- **Cannot use non-TLS WebSocket** — Server must be reachable via `wss://` (TLS required)\n- **Cannot stream audio without `last: true`** — Twilio won't play audio until it sees a `last: true` token in the stream\n\n---\n\n## Next Steps\n\n- **Place outbound calls:** `twilio-voice-outbound-calls`\n- **Standard IVR without AI:** `twilio-voice-twiml`\n"
}

SHA-256: b8a691a1b4a4bd7926ff2377af176f5d1fc661cc47d0112b8c1b9bd1b762fbfa