|
| 1 | +<!-- Auto-synced from AGENTS.md — do not edit directly. --> |
| 2 | + |
| 3 | +# Twilio Verify - One-Time Passcode Verification |
| 4 | + |
| 5 | +Serverless one-time passcode (OTP) verification using Twilio Verify with multi-channel support (SMS, voice call, WhatsApp, email) deployed on Twilio Functions. |
| 6 | + |
| 7 | +## Commands |
| 8 | + |
| 9 | +```bash |
| 10 | +# Install dependencies |
| 11 | +npm install |
| 12 | + |
| 13 | +# Run locally |
| 14 | +npm start |
| 15 | +# Opens at http://localhost:3000/index.html |
| 16 | + |
| 17 | +# Test |
| 18 | +npm test |
| 19 | + |
| 20 | +# Deploy to Twilio |
| 21 | +twilio serverless:deploy |
| 22 | +``` |
| 23 | + |
| 24 | +## Environment Variables |
| 25 | + |
| 26 | +Copy `.env.example` to `.env`. Never commit `.env`. |
| 27 | + |
| 28 | +```bash |
| 29 | +cp .env.example .env |
| 30 | +``` |
| 31 | + |
| 32 | +| Variable | Where to find | Format | |
| 33 | +| -------- | ------------- | ------ | |
| 34 | +| `ACCOUNT_SID` | [Console](https://console.twilio.com) homepage | Starts with `AC` | |
| 35 | +| `AUTH_TOKEN` | Console homepage → click to reveal | 32-char string. Treat as a password. | |
| 36 | +| `VERIFY_SERVICE_SID` | Console → Verify → Services | Starts with `VA` | |
| 37 | + |
| 38 | +## Project Structure |
| 39 | + |
| 40 | +``` |
| 41 | +functions/ |
| 42 | + start-verify.js # Sends OTP via SMS, call, WhatsApp, or email |
| 43 | + check-verify.js # Validates user-provided OTP code |
| 44 | +assets/ |
| 45 | + index.html # Web UI for testing verification flow |
| 46 | + styles.css # Twilio Paste design system styles |
| 47 | + locales.js # Multi-language support options |
| 48 | +tests/ # Unit tests for both functions |
| 49 | +``` |
| 50 | + |
| 51 | +## Agent Boundaries |
| 52 | + |
| 53 | +**Always:** |
| 54 | +- Confirm `.env` is configured before running any command |
| 55 | +- Use the Environment Variables section to guide the user to each credential — don't ask them to find values without direction |
| 56 | +- Confirm the app is running before asking the user to test it |
| 57 | +- Verify the Verify Service is created at https://console.twilio.com/verify/services |
| 58 | + |
| 59 | +**Never:** |
| 60 | +- Run the app with missing or placeholder credentials |
| 61 | +- Hardcode credentials or phone numbers in source files |
| 62 | +- Skip the `cp .env.example .env` step |
| 63 | +- Use invalid phone number formats (must be E.164: +15551234567) |
| 64 | + |
| 65 | +## Verify It's Working |
| 66 | + |
| 67 | +1. Open http://localhost:3000/index.html in your browser |
| 68 | +2. Select a verification channel (SMS, WhatsApp, voice call, or email) |
| 69 | +3. Enter your phone number (with country code) or email address |
| 70 | +4. Click "Get a one-time passcode" to receive the OTP |
| 71 | +5. Enter the code in the modal dialog and click "Verify code" |
| 72 | +6. You should see "Verification success!" in green |
| 73 | + |
| 74 | +**Expected behavior:** |
| 75 | +- SMS/WhatsApp/Call: You receive a code on your phone within 30 seconds |
| 76 | +- Email: Check your inbox for a verification code email |
| 77 | +- After entering the correct code, the system confirms "Verification success!" |
| 78 | +- Incorrect codes show "Incorrect token!" in red |
| 79 | + |
| 80 | +## Twilio Resources |
| 81 | + |
| 82 | +- [Twilio Console](https://console.twilio.com) — credentials, Verify service configuration |
| 83 | +- [Verify API Documentation](https://www.twilio.com/docs/verify/api) |
| 84 | +- [Verify Quickstart](https://www.twilio.com/docs/verify/quickstarts) |
| 85 | +- [Supported Languages](https://www.twilio.com/docs/verify/supported-languages) |
| 86 | +- [Email Verification Setup](https://www.twilio.com/docs/verify/email) |
0 commit comments