conversation-relay
Skill2 starsChanged 8 months agoMITView on GitHub
Twilio development skill: conversation-relay
- Reads credentials
In this repository66 other files it gives its agents.
- adversarial-reviewSkill
- agent-connectSkill
- agent-teams-guideSkill
- agent-testingSkill
- android-sdkSkill
- brainstormSkill
- branded-callingSkill
- callbacksSkill
- compliance-regulatorySkill
- conferenceSkill
- context-engineeringSkill
- context-hubSkill
- conversational-intelligenceSkill
- conversation-relay-referenceSkill
- conversationrelaySkill
- conversations-v2Skill
- customer-memorySkill
- deepgramSkill
- deep-validationSkill
- elastic-sip-trunkingSkill
- env-doctorSkill
- event-streamsSkill
- getting-startedSkill
- hooks-referenceSkill
- iamSkill
- ios-sdkSkill
- ivr-crawlerSkill
- ivr-migratorSkill
- lookupSkill
- media-streamsSkill
- memory-systemsSkill
- messaging-services-referenceSkill
- messaging-servicesSkill
- messagingSkill
- multi-agent-patternsSkill
- operational-gotchasSkill
- paymentsSkill
- paySkill
- phone-numbersSkill
- proxySkill
- real-time-transcriptionSkill
- recordingsSkill
- segmentSkill
- sendgrid-emailSkill
- sip-byocSkill
- sipSkill
- sync-referenceSkill
- syncSkill
- taskrouter-referenceSkill
- taskrouterSkill
- tdd-workflowSkill
- tool-boundariesSkill
- twilio-cliSkill
- twilio-invariantsSkill
- verify-referenceSkill
- verifySkill
- video-patternsSkill
- videoSkill
- voice-insightsSkill
- voice-referenceSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 174
Use source_sid (not media_url) for Twilio recordings — Intelligence API can't authenticate to api.twilio.com.
- Very specific: line 196
Use console.log for ALL logging — console.error() generates 82005, console.warn() generates 82004.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- ABOUTME: Essential context for ConversationRelay voice AI functions. --><!-- ABOUTME: Covers file inventory, WebSocket protocol, prerequisites, and troubleshooting. -->Conversation Relay Functions Context
Service: prototype-ai (AI_BASE_URL). Deploy: ./scripts/deploy-services.sh dev
For LLM integration code, ngrok setup, full configuration, and code patterns, see REFERENCE.md.
Files
Public Handlers
| File | Access | Description |
ai-assistant-inbound.js | Public | Connects incoming calls to ConversationRelay AI agent |
relay-handler.js | Public | Entry point for connecting phone calls to LLM-powered voice agents |
Callbacks
| File | Access | Description |
transcript-complete.protected.js | Protected | Handles Voice Intelligence transcript completion callback; sends SMS summary |
Demo Flow
| File | Access | Description |
start-ai-demo.protected.js | Protected | Initiates outbound AI demo call with recording and ConversationRelay |
finalize-demo.protected.js | Protected | Processes completed demo call — stores transcript in Sync, sends SMS |
Agent-to-Agent Testing Infrastructure
| File | Access | Description |
agent-a-inbound.protected.js | Protected | Inbound call handler for Agent A (questioner) |
agent-b-inbound.protected.js | Protected | Inbound call handler for Agent B (answerer) |
start-agent-test.protected.js | Protected | Test orchestrator that initiates agent-to-agent calls |
validate-agent-test.protected.js | Protected | Validates agent-to-agent test results via Sync transcripts |
Payment Testing Infrastructure
| File | Access | Description |
payment-test-start.protected.js | Protected | Orchestrates 3-participant conference (Payment Agent, Customer Agent, DTMF Injector) |
payment-agent-inbound.protected.js | Protected | Payment Agent ConversationRelay handler |
customer-agent-inbound.protected.js | Protected | Customer Agent ConversationRelay handler |
dtmf-hold.js | Public | Hold endpoint for DTMF Injector — returns long pause TwiML |
Recording Validation
| File | Access | Description |
recording-test-inbound.protected.js | Protected | Parameterized TwiML handler for recording validation — accepts query params to configure recording method, then connects to ConversationRelay |
Callbacks
| File | Access | Description |
recording-complete.protected.js | Protected | Recording completion → Sync update + Voice Intelligence transcription |
What is Conversation Relay?
Real-time, bidirectional communication between phone calls and AI/LLM backends via WebSockets. Handles speech transcription, TTS, audio streaming, DTMF detection, and interruption handling.
Not Media Streams (<Connect><Stream>): Media Streams sends raw audio (mulaw 8kHz base64). ConversationRelay sends structured JSON (type: "prompt", type: "text"). They are incompatible — a CR handler cannot be used with <Stream> and vice versa.
Quickstart (5 Minutes)
Minimum viable ConversationRelay setup:
- TwiML function — Returns
<Connect><ConversationRelay>pointing to your WebSocket URL - WebSocket server — Handles
setup,prompt, andinterruptevents; sendstextresponses - Phone number — Configure voice webhook to your TwiML function
- Call it — Dial the number, speak, hear AI response
// Minimal TwiML (relay-connect.js)
const twiml = new Twilio.twiml.VoiceResponse();
const connect = twiml.connect();
connect.conversationRelay({
url: 'wss://your-server.ngrok.dev/ws',
ttsProvider: 'ElevenLabs',
voice: 'cgSgspJ2msm6clMCkdW9', // ElevenLabs Jessica
elevenlabsTextNormalization: 'on',
transcriptionProvider: 'deepgram',
speechModel: 'flux-general-en',
});
return callback(null, twiml);// Minimal WebSocket handler (3 events)
ws.on('message', (data) => {
const msg = JSON.parse(data);
if (msg.type === 'setup') { /* session started, msg.callSid available */ }
if (msg.type === 'prompt') {
ws.send(JSON.stringify({ type: 'text', token: 'Hello! How can I help?' }));
}
if (msg.type === 'interrupt') { /* user interrupted, stop current response */ }
});For full implementations: pizza-agent-connect.js (TwiML) and __tests__/e2e/agent-server-template.js (WebSocket server).
Basic TwiML Setup
const twiml = new Twilio.twiml.VoiceResponse();
const connect = twiml.connect();
connect.conversationRelay({
url: 'wss://your-server.com/relay',
ttsProvider: 'ElevenLabs',
voice: 'cgSgspJ2msm6clMCkdW9', // ElevenLabs Jessica
elevenlabsTextNormalization: 'on',
transcriptionProvider: 'deepgram',
speechModel: 'flux-general-en',
language: 'en-US',
});
return callback(null, twiml);WebSocket Protocol
Incoming (from Twilio)
| Type | Key Fields | Description |
setup | callSid, sessionId, from, to | Connection established |
prompt | voicePrompt, last | User speech (process when last: true) |
dtmf | digit | DTMF tone detected |
interrupt | — | User interrupted AI response |
Outgoing (to Twilio)
| Type | Key Fields | Description |
text | token | TTS response (stream individual tokens for natural speech) |
end | — | End the conversation |
Voice & Transcription Options
Important: Some voice/provider combos cause error 64101. ElevenLabs requires account enablement (error 64101 with block_elevenlabs if not enabled). Google Neural2 is the fallback if ElevenLabs is unavailable.
| Setting | Options | Recommended |
| TTS Provider | ElevenLabs, Google, Amazon | ElevenLabs |
| Voice (ElevenLabs) | Voice IDs: cgSgspJ2msm6clMCkdW9 (Jessica), cjVigY5qzO86Huf0OWal (Eric), EXAVITQu4vr4xnSDxMaL (Sarah) | Jessica (cgSgspJ2msm6clMCkdW9) |
| Voice (Google fallback) | Google.en-US-Neural2-F, -J, -A | Google.en-US-Neural2-F |
| Transcription | google, deepgram (case-insensitive) | deepgram |
| Speech Model (Deepgram) | flux-general-en, nova-3-general, nova-2-general | flux-general-en |
| Speech Model (Google) | telephony, default | telephony (phone-optimized) |
| Text Normalization | elevenlabsTextNormalization: 'on' | Always set with ElevenLabs |
For the full Deepgram attribute reference, model compatibility matrix, and per-product syntax differences, see the Deepgram skill.
Prerequisites
Voice Intelligence Service
You must create a CI Service in the Twilio Console (no API for this). Go to Console → Voice → Voice Intelligence → Create new Service → copy the GA... SID → add to .env as TWILIO_INTELLIGENCE_SERVICE_SID.
Without this, transcript creation fails with 404.
Dual Service Pattern
| Service | Env Var | Operators | Use Case |
twilio-agent-factory | TWILIO_INTELLIGENCE_SERVICE_SID | Summary + Sentiment (auto) | Validation, demo calls |
no-auto-transcribe | TWILIO_INTELLIGENCE_SERVICE_MANUAL_SID | None | Manual transcript creation |
Why two? Operators are per-service and auto-run on all transcripts. No per-transcript bypass. PII redaction is also per-service — separate services for redacted vs unredacted access.
Transcript Creation
Use source_sid (not media_url) for Twilio recordings — Intelligence API can't authenticate to api.twilio.com. Language Operators run automatically when configured on the service.
ConversationRelay in Conferences
Each agent's CR runs on their individual call leg (child), while conference membership is on the parent leg. Audio bridges through. Use the Participants API to add agents — make_call(url=conference-TwiML) won't work because the url parameter only controls the parent leg.
Troubleshooting
| Symptom | Cause | Fix |
| AI greets but doesn't respond | Using isFinal instead of last | Check for message.last |
| "Extra inputs are not permitted" | Extra fields in Anthropic messages | Strip to role + content only |
| WebSocket doesn't connect | URL not HTTPS/WSS | Use ngrok HTTPS, convert to wss:// |
| No transcript after call | Missing Sync Service SID | Set TWILIO_SYNC_SERVICE_SID |
| Interruption not working | interruptible not set | Add interruptible: 'true' |
| DTMF not detected | dtmfDetection not enabled | Add dtmfDetection: 'true' |
| Transcript status "error" | Using media_url for recordings | Use source_sid instead |
| Error 82005 in notifications | Stray console.error() call | Use console.log() only |
| ngrok tunnel dies mid-session | Tunnel expires/disconnects | Verify with curl localhost:4040 |
Logging Rules
Use console.log for ALL logging — console.error() generates 82005, console.warn() generates 82004. Always pass a string to Twilio.Response.setBody() (use JSON.stringify()).
Environment Variables
CONVERSATION_RELAY_URL=wss://your-server.com/relay
ANTHROPIC_API_KEY=sk-ant-...
OPENAI_API_KEY=sk-...Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

