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

verify-reference

Skill2 starsChanged 8 months agoMITView on GitHub

Twilio development skill: verify-reference

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create a Verify Service in the Twilio Console with these options:

    line 194

≈ “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: Complete reference for Twilio Verify API patterns, code samples, and error handling. --><!-- ABOUTME: Companion to CLAUDE.md — contains detailed examples, rate limiting, and testing guidance. -->

Verify Reference

For essential patterns and quick reference, see CLAUDE.md.

API Examples

Start Verification (Full Options)

const verification = await client.verify.v2
  .services(serviceSid)
  .verifications.create({
    to: '+1234567890',
    channel: 'sms',
    locale: 'en',                    // Message language
    customFriendlyName: 'MyApp',     // Sender name in message
    customMessage: 'Your code is {{code}}', // Custom template
    sendDigits: 'wwww1928',          // DTMF to dial (voice)
    rateLimits: {
      uniqueName: 'end_user_phone_number',
      value: '+1234567890'
    }
  });

Check Verification

const verificationCheck = await client.verify.v2
  .services(serviceSid)
  .verificationChecks.create({
    to: '+1234567890',
    code: '123456'
  });

Common Patterns

Basic 2FA Flow

// Step 1: Start verification (user requests code)
exports.startVerification = async (context, event, callback) => {
  const client = context.getTwilioClient();
  const { phoneNumber } = event;

  const verification = await client.verify.v2
    .services(context.TWILIO_VERIFY_SERVICE_SID)
    .verifications.create({
      to: phoneNumber,
      channel: 'sms'
    });

  return callback(null, {
    success: true,
    status: verification.status
  });
};

// Step 2: Check verification (user submits code)
exports.checkVerification = async (context, event, callback) => {
  const client = context.getTwilioClient();
  const { phoneNumber, code } = event;

  const verificationCheck = await client.verify.v2
    .services(context.TWILIO_VERIFY_SERVICE_SID)
    .verificationChecks.create({
      to: phoneNumber,
      code: code
    });

  if (verificationCheck.status === 'approved') {
    // Grant access, create session, etc.
    return callback(null, { success: true, verified: true });
  }

  return callback(null, { success: false, verified: false });
};

Fallback to Voice

exports.handler = async (context, event, callback) => {
  const client = context.getTwilioClient();
  const { phoneNumber, attemptCount = 0 } = event;

  // Use voice after 2 failed SMS attempts
  const channel = attemptCount >= 2 ? 'call' : 'sms';

  const verification = await client.verify.v2
    .services(context.TWILIO_VERIFY_SERVICE_SID)
    .verifications.create({
      to: phoneNumber,
      channel: channel
    });

  return callback(null, {
    success: true,
    status: verification.status,
    channel: channel
  });
};

Rate Limiting

const verification = await client.verify.v2
  .services(serviceSid)
  .verifications.create({
    to: phoneNumber,
    channel: 'sms',
    rateLimits: {
      uniqueName: 'end_user_phone_number',
      value: phoneNumber
    }
  });

Error Handling

Error Handling Pattern

exports.handler = async (context, event, callback) => {
  const client = context.getTwilioClient();

  try {
    const verification = await client.verify.v2
      .services(context.TWILIO_VERIFY_SERVICE_SID)
      .verifications.create({
        to: event.phoneNumber,
        channel: 'sms'
      });

    return callback(null, { success: true, status: verification.status });
  } catch (error) {
    if (error.code === 60202) {
      return callback(null, {
        success: false,
        error: 'Too many attempts. Please wait before trying again.'
      });
    }
    if (error.code === 60223) {
      return callback(null, {
        success: false,
        error: 'Invalid phone number format.'
      });
    }
    throw error;
  }
};

Testing Verify Functions

Test Phone Numbers

Twilio provides magic phone numbers for testing:

  • +15005550006 - Always succeeds
  • +15005550009 - Always fails

Test Codes

With Custom Code enabled on your Verify Service:

  • Code 123456 works for test numbers in development

Integration Test Pattern

it('should start verification successfully', async () => {
  const context = createTestContext();
  const event = { to: '+15005550006', channel: 'sms' };

  await handler(context, event, callback);

  const [, response] = callback.mock.calls[0];
  expect(response.success).toBe(true);
  expect(response.status).toBe('pending');
});

Service Configuration

Create a Verify Service in the Twilio Console with these options:

  • Code Length: 4-10 digits (default: 6)
  • Code TTL: 60-600 seconds (default: 600)
  • Lookup Enabled: Validate phone numbers before sending
  • Skip SMS to Landlines: Auto-switch landlines to voice
  • Custom Code Enabled: Allow custom codes for testing

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.