A Twilio Serverless application for making outbound voice calls using Twilio Programmable Voice. Connects agents and recipients using Conferences, featuring Twilio Verify for OTP validation during setup, along with a JWT-based authentication for starting call.
- Setup: Agents verify email and phone via Twilio Verify OTP
- Call: Use JWT token to initiate authenticated calls
- Dual email/phone verification with JWT tokens with long validity
- Phone uniqueness enforcement per email
- Automatic agent detection from JWT
- Configurable email domain restrictions (set via
ALLOWED_EMAIL_DOMAINS)
Source: setup/init.js
POST /setup/init - Send OTPs to email and phone
Parameters:
email(required): Email address from allowed domains (if configured)phone(required): Phone number for agent calls
curl -X POST 'https://{{domain}}/setup/init' \
-H 'Content-Type: application/json' \
-d '{"email": "user@alloweddomain.com", "phone": "+19087654321"}'Source: setup/validate.js
POST /setup/validate - Validate OTPs and get JWT token
Parameters:
email,email_code,phone,phone_code(all required)
curl -X POST 'https://{{domain}}/setup/validate' \
-H 'Content-Type: application/json' \
-d '{"email": "user@alloweddomain.com", "email_code": "123456", "phone": "+19087654321", "phone_code": "789012"}'Returns: JWT token in data.token field
Source: call/start.js
POST /call/start - Start conference call using JWT token
Parameters:
token(required): JWT from setup validationto(required): Customer phone numberconfName(optional): Conference identifier
curl -X POST 'https://{{domain}}/call/start' \
-H 'Content-Type: application/json' \
-d '{"token": "JWT_TOKEN", "to": "+1234567890", "confName": "Call with Owl from Twilio"}'- Signup for a Twilio account and login to the Twilio Console
- Setup Twilio CLI + Serverless Toolkit, and login to the CLI your using Twilio account credentials.
- Set up a Twilio Phone Number for outbound calls: choose an existing phone number or buy a new one.
- Setup a Twilio Verify service with authentication channels for Email and SMS channels. (See
verify_email_tmpl.htmlfor an example template). (Twilio Console -> Verify -> Services) - Setup a Twilio Sync Service (Twilio Console -> Sync -> Services)
- Generate a strong JWT secret:
openssl rand -base64 32 - Copy
sample.envto.envwith values from Twilio Console
CALLER_ID: Twilio phone number for outgoing callsALLOWED_EMAIL_DOMAINS: Comma-separated list of allowed email domains (optional, leave empty to allow any domain)VERIFY_SERVICE_SID: Twilio Verify Service SIDSYNC_SERVICE_SID: Twilio Sync Service SIDJWT_SECRET: Strong secret key (32+ chars) for JWT signing.DOMAIN_NAME: For local testing only, set this to the ngrok domain if you're using ngrok. This is automatically set when deploying to Twilio.
twilio serverless:deployMIT