agentleFS
wittyreferencewittyreference/twilio-claude-plugin/skills/voice-reference/SKILL.md

voice-reference

Skill2 starsChanged 8 months agoMITView on GitHub

Twilio development skill: voice-reference

  • Reads credentials

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When Twilio makes a request to your voice webhook, these parameters are included:

    line 48
  2. Distinctive:

    Use the Conferences Participants API for programmatic control:

    line 106
  3. Distinctive:

    Updating participant TwiML exits current state: If a participant is in a conference and you update their call with new TwiML, they …

    line 191
  4. Very specific:

    Conference teardown risk: If the exiting participant had endConferenceOnExit=true, the entire conference tears down - appearing as a …

    line 193
  5. Very specific:

    Use console.log for all logging, including error conditions and catch blocks.

    line 244
  6. Very specific:

    Response bodies: Always pass a string to Twilio.Response.setBody(), not a plain object.

    line 246

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- ABOUTME: Detailed reference material for TwiML verbs, patterns, and conference APIs. --><!-- ABOUTME: Contains code examples, options tables, and advanced call control patterns. -->

Voice Reference

For essential context, file inventory, and gotchas, see CLAUDE.md.

Say Verb Options

twiml.say({
  voice: 'Polly.Amy',      // Amazon Polly voice
  language: 'en-GB',       // Language code
  loop: 1                  // Number of times to repeat
}, 'Your message here');

Gather Verb Options

twiml.gather({
  input: 'dtmf speech',    // Input types to accept
  timeout: 5,              // Seconds to wait for input
  numDigits: 4,            // Expected DTMF digits
  finishOnKey: '#',        // Key to finish input
  action: '/next-handler', // URL to POST results
  method: 'POST',          // HTTP method
  speechTimeout: 'auto',   // Auto-detect end of speech
  hints: 'yes, no, help'   // Speech recognition hints
});

Dial Verb Options

twiml.dial({
  callerId: '+1234567890', // Caller ID to display
  timeout: 30,             // Ring timeout in seconds
  action: '/dial-complete',// Callback URL
  record: 'record-from-answer' // Recording option
}).number('+1987654321');

Voice Webhook Parameters

When Twilio makes a request to your voice webhook, these parameters are included:

ParameterDescription
CallSidUnique identifier for the call
AccountSidYour Twilio Account SID
FromCaller's phone number (E.164)
ToCalled phone number (E.164)
CallStatusCurrent call status
Directioninbound or outbound-api
CallerNameCaller name (if available)
FromCityCaller's city
FromStateCaller's state
FromCountryCaller's country

Gather Callback Parameters

ParameterDescription
DigitsDTMF digits pressed
SpeechResultTranscribed speech
ConfidenceSpeech recognition confidence (0-1)

Common Patterns

IVR Menu

const twiml = new Twilio.twiml.VoiceResponse();
twiml.say('Press 1 for sales, 2 for support.');
twiml.gather({
  numDigits: 1,
  action: '/ivr-handler'
});
twiml.redirect('/voice/incoming-call'); // No input, restart

Call Forwarding

const twiml = new Twilio.twiml.VoiceResponse();
twiml.dial({
  callerId: event.To,
  timeout: 20
}).number('+1234567890');
twiml.say('The person you called is unavailable.');

Voicemail

const twiml = new Twilio.twiml.VoiceResponse();
twiml.say('Please leave a message after the beep.');
twiml.record({
  maxLength: 60,
  action: '/recording-complete',
  transcribe: true,
  transcribeCallback: '/transcription-ready'
});

Conference via REST API (Preferred)

Use the Conferences Participants API for programmatic control:

// Create conference by adding first participant
const participant = await client.conferences('my-conference')
  .participants
  .create({
    from: context.TWILIO_PHONE_NUMBER,
    to: participantNumber,
    timeout: 30,           // Ring timeout
    timeLimit: 600,        // Max call duration (prevent runaway)
    startConferenceOnEnter: true,
    endConferenceOnExit: false,
    muted: false,
    beep: true
  });

// Add additional participants
await client.conferences('my-conference')
  .participants
  .create({
    from: context.TWILIO_PHONE_NUMBER,
    to: anotherParticipant,
    timeout: 30,
    timeLimit: 600
  });

// End conference
await client.conferences(conferenceSid)
  .update({ status: 'completed' });

Conference Options

OptionTypeDefaultDescription
startConferenceOnEnterbooleantrueStart when participant joins
endConferenceOnExitbooleanfalseEnd when participant leaves (moderator)
mutedbooleanfalseJoin muted
beepbooleantruePlay beep on join/leave
timeoutnumber30Ring timeout in seconds
timeLimitnumber14400Max call duration in seconds

Finding Conferences by Name

// List in-progress conferences by friendly name
const conferences = await client.conferences.list({
  friendlyName: 'my-conference',
  status: 'in-progress',
  limit: 1
});

if (conferences.length > 0) {
  const conference = conferences[0];
  console.log(`SID: ${conference.sid}`);
}

TwiML Control Model

Critical: In almost all cases, only ONE TwiML document controls a call at any given time.

Exception: Background Operations

Some TwiML verbs start background processes that continue running even after the call moves to subsequent TwiML documents:

  • <Start><Stream> - Media streaming continues in the background
  • <Start><Recording> - Recording continues until explicitly stopped
  • <Start><Siprec> - SIPREC streaming continues in the background

These operations "fork off" and run concurrently with whatever TwiML executes next. The call can proceed through multiple TwiML documents while the stream/recording remains active.

// Recording starts and continues through subsequent TwiML
const start = twiml.start();
start.recording({
  recordingStatusCallback: `https://${context.DOMAIN_NAME}/recording-complete`,
  recordingStatusCallbackEvent: 'completed',
});
twiml.say('This is being recorded...');
twiml.redirect('/next-handler'); // Recording continues!

Key Implications

  1. Updating participant TwiML exits current state: If a participant is in a conference and you update their call with new TwiML, they immediately exit the conference and execute the new TwiML.
  2. Conference teardown risk: If the exiting participant had endConferenceOnExit=true, the entire conference tears down - appearing as a "dropped call" to other participants.
  3. Call transfer in conference context: "Transfer" means adding a new participant to the existing conference, NOT replacing TwiML. The original parties stay in the conference.

Safe Conference Transfer Pattern

// "Transfer" a call by adding a new party to the conference
// Original caller and agent stay in conference with the new party

// 1. Agent is on call with customer in conference "support-12345"
// 2. Agent wants to bring in specialist

// Add specialist to existing conference (they join, nobody leaves)
await client.conferences('support-12345')
  .participants
  .create({
    from: context.TWILIO_PHONE_NUMBER,
    to: specialistNumber,
    startConferenceOnEnter: true,  // Start immediately
    endConferenceOnExit: false     // Don't end when they leave
  });

// 3. All three parties now in conference
// 4. Agent can drop off by having their participant removed:
await client.conferences('support-12345')
  .participants(agentCallSid)
  .update({ status: 'completed' });

Dangerous Pattern (Avoid)

// DON'T: Update participant with new TwiML - exits them from conference
await client.calls(participantCallSid)
  .update({
    twiml: '<Response><Dial>+15551234567</Dial></Response>'
  });
// This removes them from conference and may tear it down!

Logging and Response Rules

Twilio Functions generate debugger alerts based on log level:

Log LevelAlert CodeEffect
console.logNoneSilent — use for all operational logging
console.warn82004Generates warning alert — never use
console.error82005Generates error alert — never use

Use console.log for all logging, including error conditions and catch blocks.

Response bodies: Always pass a string to Twilio.Response.setBody(), not a plain object. Use JSON.stringify() and set Content-Type: application/json. Passing an object causes Buffer.from(object) TypeError in the runtime.

// WRONG — triggers Buffer TypeError
response.setBody({ success: true });

// RIGHT — explicit JSON serialization
response.appendHeader('Content-Type', 'application/json');
response.setBody(JSON.stringify({ success: true }));

Gotchas

Env Vars Can Reset on Deploy

twilio serverless:deploy doesn't preserve runtime env vars set via the Console or CLI. Always verify env vars after deployment and re-set any that were added outside of .env.

<Start><Recording> Syntax is .recording(), Not .record()

The correct TwiML builder syntax is twiml.start().recording({...}). Using .record() is a different verb entirely (<Record>, which has different behavior — see below).

Conference Has No Parent/Child Relationships

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.