Template for deploying an AI voice assistant with Twilio, OpenAI Realtime API, and Cloudflare Workers
View the Project on GitHub jmoore2333/twilio-openai-voice-assistant-cloudflare-template
Use this path if you want the simplest Cloudflare-native storage option.
The included ./scripts/setup.sh script is the easiest way to get started. It automates the main setup steps described below so you can go from clone to deployed Worker with less manual Wrangler work.
Run the setup script:
./scripts/setup.sh
It can:
wrangler.tomlworkers.dev or an optional custom domainIf you prefer to do the steps manually, use the workflow below.
npx wrangler d1 create voice-assistant-template
Copy the returned database_id.
wrangler.tomlUncomment the [[d1_databases]] block and fill in your values:
[[d1_databases]]
binding = "DB"
database_name = "voice-assistant-template"
database_id = "replace-with-your-d1-database-id"
Create the local development database:
npx wrangler d1 execute voice-assistant-template --local --file=docs/schema-d1.sql
Create the remote database schema:
npx wrangler d1 execute voice-assistant-template --remote --file=docs/schema-d1.sql
wrangler secret put OPENAI_API_KEY
wrangler secret put TWILIO_AUTH_TOKEN
wrangler secret put RESEND_API_KEY
RESEND_API_KEY is optional. If you skip it, email delivery will be disabled.
Copy .dev.vars.example to .dev.vars and set:
OPENAI_API_KEYTWILIO_AUTH_TOKENSTORAGE_BACKEND=d1 if you also have DATABASE_URL in the same filenpm run deploy
After deploy:
POST https://<your-domain>/voice/incomingIf your Worker sits behind Cloudflare Access, create bypass rules for the Twilio-facing paths:
/voice/incoming/voice/ws/*If you turn on the optional outbound starter later, also bypass:
/voice/outbound/twiml/voice/statusKeep /voice/outbound behind your own authentication. That route is for your app or admin tooling, not for Twilio.
DATABASE_URL is set and the DB binding exists, the app will use D1 automatically.undici override in package.json to avoid a tooling-only audit issue in the current wrangler dependency chain. Check future wrangler releases before keeping it forever.