agentleFS
wittyreferencewittyreference/twilio-claude-plugin/skills/video-patterns/SKILL.md

video-patterns

Skill2 starsChanged 8 months agoMITView on GitHub

Twilio development skill: video-patterns

  • Reads credentials

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 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.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use MCP tool validate_video_room after room creation to verify:

    line 133
  2. Very specific:

    Use console.log() for ALL logging, including errors.

    line 170
  3. Very specific:

    Always use JSON.stringify() for response bodies:

    line 174

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

Video Functions Context

This directory contains Twilio Video API functions for video rooms, token generation, and status callbacks.

Functions

FunctionAccessPurpose
token.jsPublic (auth-gated)Generate Video SDK access tokens
callbacks/room-status.protected.jsProtectedRoom and participant status callbacks
callbacks/recording-status.protected.jsProtectedTrack recording callbacks
callbacks/composition-status.protected.jsProtectedComposition callbacks
callbacks/transcription-status.protected.jsProtectedReal-time transcription callbacks

token.js is public (not .protected) because browser clients cannot generate Twilio request signatures. Auth is enforced via TOKEN_API_KEY — callers must pass a matching apiKey parameter. The endpoint returns 403 if TOKEN_API_KEY is not configured.

Room Types

ALWAYS use group rooms. Other types lack features and HIPAA eligibility.

Room TypeRecommendationWhy
group✅ ALWAYSHIPAA-eligible, full features, scalable
group-small❌ AVOIDLegacy alias, use group instead
peer-to-peer❌ NEVERNot HIPAA-eligible, limited features
go❌ NEVERNot HIPAA-eligible, legacy WebRTC

Token Generation

The token.js endpoint generates JWT access tokens for the Video SDK.

Parameters:

  • identity (optional): Participant identity, defaults to video-user-{timestamp}
  • room (optional): Room name to restrict access to specific room

Required environment variables:

  • TWILIO_ACCOUNT_SID
  • TWILIO_API_KEY
  • TWILIO_API_SECRET

Example request:

curl "https://your-domain.twil.io/video/token?identity=alice&room=my-room"

Example response:

{
  "token": "eyJ...",
  "identity": "alice",
  "room": "my-room"
}

Status Callbacks

Room Status Callback

Configure on room creation:

const room = await client.video.v1.rooms.create({
  uniqueName: 'my-room',
  type: 'group',
  statusCallback: 'https://your-domain.twil.io/video/callbacks/room-status',
  statusCallbackMethod: 'POST'
});

Events received:

  • room-created - Room was created
  • room-ended - Room ended
  • participant-connected - Participant joined
  • participant-disconnected - Participant left
  • recording-started - Recording began
  • recording-completed - Recording finished
  • track-added - Track published
  • track-removed - Track unpublished

Recording Status Callback

Configure on room creation:

const room = await client.video.v1.rooms.create({
  uniqueName: 'my-room',
  type: 'group',
  recordParticipantsOnConnect: true,
  recordingStatusCallback: 'https://your-domain.twil.io/video/callbacks/recording-status',
  recordingStatusCallbackMethod: 'POST'
});

Composition Status Callback

Configure on composition creation or via hooks:

// Manual composition
const composition = await client.video.v1.compositions.create({
  roomSid: 'RM...',
  audioSources: ['*'],
  videoLayout: { grid: { video_sources: ['*'] } },
  statusCallback: 'https://your-domain.twil.io/video/callbacks/composition-status'
});

// Auto-composition via hook
await client.video.v1.compositionHooks.create({
  friendlyName: 'auto-compose',
  enabled: true,
  audioSources: ['*'],
  videoLayout: { grid: { video_sources: ['*'] } },
  statusCallback: 'https://your-domain.twil.io/video/callbacks/composition-status'
});

Events received:

  • composition-enqueued - Queued for processing
  • composition-started - Processing started
  • composition-progress - Progress update (includes PercentageDone)
  • composition-available - Completed successfully
  • composition-failed - Failed (includes ErrorCode, ErrorMessage)

Deep Validation

Callbacks log to Sync for deep validation:

  • callbacks-video-room-{RoomSid} - Room/participant events
  • callbacks-video-recording-{RecordingSid} - Recording events
  • callbacks-video-composition-{CompositionSid} - Composition events

Use MCP tool validate_video_room after room creation to verify:

  • Room status and type
  • Participant connections
  • Published tracks
  • Recording/composition status

Gotchas

Composition Timing

CRITICAL: Compositions can only be created AFTER the room ends.

// WRONG - fails if room is in-progress
await client.video.v1.compositions.create({ roomSid: 'RM...' });

// RIGHT - wait for room to end first
const room = await client.video.v1.rooms(roomSid).fetch();
if (room.status === 'completed') {
  await client.video.v1.compositions.create({ roomSid });
}

Recording vs Composition

FeatureTrack RecordingsCompositions
FormatRaw per-track filesSingle combined file
TimingCreated during roomCreated after room ends
Use caseML training, proctoringSharing, playback

Storage Retention

Without external S3 storage, recordings are deleted after 24 hours. Configure S3 in Console → Video → Recording Settings for production.

Logging Rules

Use console.log() for ALL logging, including errors. Never use console.error() or console.warn() - they generate debugger alerts (82005/82004).

Response Bodies

Always use JSON.stringify() for response bodies:

// WRONG - causes Buffer TypeError
response.setBody({ success: true });

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

E2E Testing

A complete E2E test suite exists at __tests__/e2e/video-sdk/:

# Run video SDK tests
npm run test:video-sdk

# Run with visible browser
npm run test:video-sdk:headed

Tests verify:

  • Token generation and room connection
  • Two-party video calls
  • Video stream rendering (dimensions > 0)
  • Audio stream detection (Web Audio API)
  • Room API state (type, participants)
  • Disconnect handling

See skills/video/SKILL.md for detailed testing patterns.

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.