[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CJ5HFJQPFSA9MF9WBFH786":3,"skill-same:01M7CJ5HFJQPFSA9MF9WBFH786":51},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7CJ5HFJQPFSA9MF9WBFH786","twilio-webhook-architecture",null,"Design, secure, and operate Twilio webhook endpoints. Covers inbound event handling, status callbacks, signature validation, connection overrides for retry and timeout tuning, local development tunneling, and production hardening. Use this skill whenever an agent needs to receive HTTP callbacks from Twilio for any product -- messaging, voice, verify, or event streams.","rossboyd\u002Fquickque","rossboyd","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F3195729?v=4","01M7CG99NTNRFV0TWTZX9JY9CQ","rbyd","01M7CG99PH4WEP5P45VTBNPDB0",0,"MIT","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Ftwilio-developer-kit\u002Fskills\u002Ftwilio-webhook-architecture\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: twilio-webhook-architecture\ndescription: >\n  Design, secure, and operate Twilio webhook endpoints. Covers inbound event\n  handling, status callbacks, signature validation, connection overrides for\n  retry and timeout tuning, local development tunneling, and production\n  hardening. Use this skill whenever an agent needs to receive HTTP callbacks\n  from Twilio for any product -- messaging, voice, verify, or event streams.\n---\n\n## Overview\n\nTwilio delivers events to your application via HTTP callbacks (webhooks). Inbound messages and calls trigger webhooks that expect a TwiML response; status callbacks and event streams push delivery and lifecycle data asynchronously. This skill covers the cross-product patterns that apply to every webhook integration.\n\n---\n\n## Prerequisites\n\n- Twilio account with a phone number or service configured with a webhook URL\n  -- New to Twilio? See `twilio-account-setup`\n- `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` -- see `twilio-iam-auth-setup`\n- SDK: `pip install twilio flask` \u002F `npm install twilio express`\n- Publicly accessible HTTPS endpoint (see Local Development section below)\n\n---\n\n## Quickstart\n\nReceive an inbound SMS and validate the request signature before replying.\n\n**Python (Flask)**\n```python\nimport os\nfrom flask import Flask, request, abort\nfrom twilio.request_validator import RequestValidator\nfrom twilio.twiml.messaging_response import MessagingResponse\n\napp = Flask(__name__)\nvalidator = RequestValidator(os.environ[\"TWILIO_AUTH_TOKEN\"])\n\n@app.route(\"\u002Fsms\", methods=[\"POST\"])\ndef incoming_sms():\n    sig = request.headers.get(\"X-Twilio-Signature\", \"\")\n    if not validator.validate(request.url, request.form, sig):\n        abort(403)\n    resp = MessagingResponse()\n    resp.message(f\"Got: {request.form.get('Body')}\")\n    return str(resp), 200, {\"Content-Type\": \"text\u002Fxml\"}\n```\n\n**Node.js (Express)**\n```node\nconst express = require(\"express\");\nconst twilio = require(\"twilio\");\nconst app = express();\napp.use(express.urlencoded({ extended: false }));\n\napp.post(\"\u002Fsms\", (req, res) => {\n    const valid = twilio.validateRequest(\n        process.env.TWILIO_AUTH_TOKEN,\n        req.headers[\"x-twilio-signature\"],\n        `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n        req.body\n    );\n    if (!valid) return res.status(403).send(\"Forbidden\");\n    const twiml = new twilio.twiml.MessagingResponse();\n    twiml.message(`Got: ${req.body.Body}`);\n    res.type(\"text\u002Fxml\").send(twiml.toString());\n});\n```\n\nSet your webhook URL in Console: **Phone Numbers > Active Numbers > (your number) > Messaging > \"A Message Comes In\"**.\n\n---\n\n## Key Patterns\n\n### 1. Webhook Types Across Products\n\n| Webhook type | Trigger | Expected response | Products |\n|---|---|---|---|\n| Inbound event | Message received \u002F call answered | TwiML (XML) | Messaging, Voice |\n| Status callback | Resource state change | `200` or `204` (no body required) | Messaging, Voice, Verify, Video |\n| Action URL | TwiML verb completes (`\u003CGather>`, `\u003CRecord>`) | Next TwiML | Voice |\n| Recording status | Recording processing completes | `200` or `204` | Voice |\n| Debugger event | Error or warning on account | `200` or `204` | All |\n| Event Streams | Any subscribed event | `200` or `204` | All (via Sink) |\n\n### 2. Signature Validation\n\nTwilio signs every webhook with an `X-Twilio-Signature` header (HMAC-SHA1 using your Auth Token). Always validate before processing.\n\n**Form-encoded requests (`application\u002Fx-www-form-urlencoded`):**\n\nPass the full URL and POST body parameters to the validator.\n\n**Python**\n```python\nfrom twilio.request_validator import RequestValidator\n\nvalidator = RequestValidator(os.environ[\"TWILIO_AUTH_TOKEN\"])\nis_valid = validator.validate(request.url, request.form, request.headers.get(\"X-Twilio-Signature\", \"\"))\n```\n\n**Node.js**\n```node\nconst { validateRequest } = require(\"twilio\");\n\nconst isValid = validateRequest(\n    process.env.TWILIO_AUTH_TOKEN,\n    req.headers[\"x-twilio-signature\"],\n    `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n    req.body\n);\n```\n\n**JSON requests (`application\u002Fjson`):**\n\nTwilio appends a `bodySHA256` query parameter to your URL. Use the SDK's JSON-specific validation.\n\n**Python**\n```python\nfrom twilio.request_validator import RequestValidator\n\nvalidator = RequestValidator(os.environ[\"TWILIO_AUTH_TOKEN\"])\nis_valid = validator.validate_body(\n    request.url,\n    request.get_data(as_text=True),\n    request.headers.get(\"X-Twilio-Signature\", \"\")\n)\n```\n\n**Node.js**\n```node\nconst twilio = require(\"twilio\");\n\n\u002F\u002F Use express.raw() or a verify callback to preserve the raw body\nconst isValid = twilio.validateRequestWithBody(\n    process.env.TWILIO_AUTH_TOKEN,\n    req.headers[\"x-twilio-signature\"],\n    `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n    req.rawBody  \u002F\u002F must be the exact bytes Twilio sent, not JSON.stringify(req.body)\n);\n```\n\n**Critical:** Use the SDK validator. Do not implement your own -- Twilio may add parameters without notice, and the exact algorithm (including port handling) has edge cases the SDK handles.\n\n### 3. Status Callback Handling\n\nStatus callbacks are asynchronous POST requests Twilio sends when a resource changes state. They do not expect TwiML -- return `200` or `204`.\n\n**Messaging status flow:** `queued` -> `sent` -> `delivered` (or `undelivered` \u002F `failed`)\n\nWhen using Messaging Services, the flow starts with `accepted` -> `queued` -> ...\n\n**Voice status events:** `initiated`, `ringing`, `answered`, `completed`\n\nSubscribe to specific events via `StatusCallbackEvent` parameter.\n\nStatus callbacks are signed with `X-Twilio-Signature` like all Twilio webhooks. Validate before acting on the payload -- an unvalidated endpoint lets anyone forge delivery status and drive downstream logic.\n\n**Python (Flask) -- messaging status handler**\n```python\n@app.route(\"\u002Fstatus\", methods=[\"POST\"])\ndef message_status():\n    sig = request.headers.get(\"X-Twilio-Signature\", \"\")\n    if not validator.validate(request.url, request.form, sig):\n        return \"Forbidden\", 403\n    sid = request.form.get(\"MessageSid\")\n    status = request.form.get(\"MessageStatus\")\n    error_code = request.form.get(\"ErrorCode\")\n    if status in (\"failed\", \"undelivered\") and error_code:\n        print(f\"Delivery failed {sid}: error {error_code}\")\n    return \"\", 204\n```\n\n**Node.js (Express) -- voice status handler**\n```node\napp.post(\"\u002Fcall-status\", (req, res) => {\n    const valid = twilio.validateRequest(\n        process.env.TWILIO_AUTH_TOKEN,\n        req.headers[\"x-twilio-signature\"],\n        `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n        req.body\n    );\n    if (!valid) return res.status(403).send(\"Forbidden\");\n    const { CallSid, CallStatus, Duration } = req.body;\n    console.log(`${CallSid}: ${CallStatus} (${Duration}s)`);\n    res.sendStatus(204);\n});\n```\n\n**Attach status callbacks when creating resources:**\n\n```python\n# Messaging\nmessage = client.messages.create(\n    to=\"+15558675310\", from_=\"+15017122661\", body=\"Hello!\",\n    status_callback=\"https:\u002F\u002Fyourapp.com\u002Fstatus\"\n)\n\n# Voice\ncall = client.calls.create(\n    to=\"+15558675310\", from_=\"+15017122661\",\n    url=\"https:\u002F\u002Fyourapp.com\u002Fvoice\",\n    status_callback=\"https:\u002F\u002Fyourapp.com\u002Fcall-status\",\n    status_callback_event=[\"initiated\", \"ringing\", \"answered\", \"completed\"],\n    status_callback_method=\"POST\"\n)\n```\n\n### 4. Connection Overrides (Retry and Timeout Tuning)\n\nAppend URL fragments to any webhook URL to override default connection behavior. Fragments are not included in signature computation.\n\n**Format:** `https:\u002F\u002Fyourapp.com\u002Fwebhook#key=value&key=value`\n\n| Parameter | Key | Default | Range | Description |\n|---|---|---|---|---|\n| Connect Timeout | `ct` | 5000ms | 100-10000 | TCP connection timeout |\n| Read Timeout | `rt` | 15000ms | 100-15000 | Time to wait for first response byte |\n| Total Time | `tt` | 15000ms | 100-15000 | Total time for all retries |\n| Retry Count | `rc` | 1 | 0-5 | Number of retry attempts |\n| Retry Policy | `rp` | `ct` | `4xx`, `5xx`, `ct`, `rt`, `all` | What triggers a retry |\n| Edge Location | `e` | `ashburn` | `ashburn`, `dublin`, `frankfurt`, `sao-paulo`, `singapore`, `sydney`, `tokyo`, `umatilla` | Egress edge |\n\n**Examples:**\n\n```text\n# Retry up to 3 times on connection or read timeout\nhttps:\u002F\u002Fyourapp.com\u002Fsms#rc=3&rp=ct,rt\n\n# Fast failover: 1s connect timeout, 2 retries\nhttps:\u002F\u002Fyourapp.com\u002Fvoice#ct=1000&rc=2\n\n# Rotate edge locations on retry\nhttps:\u002F\u002Fyourapp.com\u002Fstatus#e=ashburn,dublin&rc=1\n```\n\nTwilio adds an `I-Twilio-Idempotency-Token` header on retries for deduplication.\n\n**Limitations:** Connection overrides are not available on Twilio Conversations or Frontline webhooks. Voice webhooks have a hard 15-second ceiling regardless of override values.\n\n### 5. Configure Webhook URLs via API\n\n**Python**\n```python\n# Phone number -- messaging\nclient.incoming_phone_numbers(\"PNxxxxxxxxxx\").update(\n    sms_url=\"https:\u002F\u002Fyourapp.com\u002Fsms\",\n    sms_method=\"POST\",\n    sms_fallback_url=\"https:\u002F\u002Fyourapp.com\u002Fsms-fallback\",\n    sms_fallback_method=\"POST\"\n)\n\n# Phone number -- voice\nclient.incoming_phone_numbers(\"PNxxxxxxxxxx\").update(\n    voice_url=\"https:\u002F\u002Fyourapp.com\u002Fvoice\",\n    voice_method=\"POST\",\n    voice_fallback_url=\"https:\u002F\u002Fyourapp.com\u002Fvoice-fallback\",\n    voice_fallback_method=\"POST\",\n    status_callback=\"https:\u002F\u002Fyourapp.com\u002Fcall-status\",\n    status_callback_method=\"POST\"\n)\n```\n\n**Node.js**\n```node\n\u002F\u002F Phone number -- messaging\nawait client.incomingPhoneNumbers(\"PNxxxxxxxxxx\").update({\n    smsUrl: \"https:\u002F\u002Fyourapp.com\u002Fsms\",\n    smsMethod: \"POST\",\n    smsFallbackUrl: \"https:\u002F\u002Fyourapp.com\u002Fsms-fallback\",\n    smsFallbackMethod: \"POST\",\n});\n\n\u002F\u002F Phone number -- voice\nawait client.incomingPhoneNumbers(\"PNxxxxxxxxxx\").update({\n    voiceUrl: \"https:\u002F\u002Fyourapp.com\u002Fvoice\",\n    voiceMethod: \"POST\",\n    voiceFallbackUrl: \"https:\u002F\u002Fyourapp.com\u002Fvoice-fallback\",\n    voiceFallbackMethod: \"POST\",\n    statusCallback: \"https:\u002F\u002Fyourapp.com\u002Fcall-status\",\n    statusCallbackMethod: \"POST\",\n});\n```\n\n### 6. Local Development with Tunnels\n\nTwilio cannot reach `localhost`. Use a tunnel to expose your local server.\n\n**ngrok (recommended for development):**\n```bash\nngrok http 5000\n# Copy the HTTPS URL, e.g. https:\u002F\u002Fabc123.ngrok-free.app\n```\n\nThen set the ngrok URL as your webhook in Console or via API.\n\n**Twilio CLI:**\n```bash\n# Install and use the CLI webhook plugin\ntwilio phone-numbers:update +15017122661 \\\n  --sms-url=\"https:\u002F\u002Fabc123.ngrok-free.app\u002Fsms\"\n```\n\n**ngrok caveats:**\n- Free tier URLs change on restart -- update Twilio config each time\n- Free tier sessions expire after hours -- use a stable host for anything beyond quick tests\n- For persistent local dev, use ngrok with a custom domain (paid) or deploy to a cloud host\n\n### 7. Event Streams (Webhook Sink)\n\nFor high-volume or cross-product event delivery, use Event Streams instead of per-resource status callbacks. Event Streams deliver events to a Sink (webhook, Kinesis, or Segment). The Twilio SDK does not wrap Event Streams -- use `requests` \u002F `fetch` directly.\n\n**Python -- create a webhook sink and subscribe to error events**\n```python\nimport os, requests\n\naccount_sid = os.environ[\"TWILIO_ACCOUNT_SID\"]\nauth_token = os.environ[\"TWILIO_AUTH_TOKEN\"]\n\n# Create a webhook sink\nsink = requests.post(\n    \"https:\u002F\u002Fevents.twilio.com\u002Fv1\u002FSinks\",\n    auth=(account_sid, auth_token),\n    data={\n        \"Description\": \"Error log sink\",\n        \"SinkType\": \"webhook\",\n        \"SinkConfiguration\": '{\"destination\": \"https:\u002F\u002Fyourapp.com\u002Fevents\", \"method\": \"POST\"}'\n    }\n).json()\n\n# Subscribe to error log events\nrequests.post(\n    \"https:\u002F\u002Fevents.twilio.com\u002Fv1\u002FSubscriptions\",\n    auth=(account_sid, auth_token),\n    data={\n        \"Description\": \"Error log subscription\",\n        \"SinkSid\": sink[\"sid\"],\n        \"Types\": '[{\"type\": \"com.twilio.error-logs.error.logged\"}]'\n    }\n)\n```\n\nSink types: `webhook`, `kinesis`, `segment`. Subscriptions filter which event types route to which sinks.\n\n### 8. HTTP Authentication for Webhook URLs\n\nTwilio supports HTTP Basic and Digest authentication. Embed credentials in the URL:\n\n```text\nhttps:\u002F\u002Fusername:password@yourapp.com\u002Fsms\n```\n\nThis provides an additional layer of protection beyond signature validation. Note: these credentials are visible in Console webhook configuration and may appear in server access logs -- rotate them independently of your Auth Token.\n\n---\n\n## Common Webhook Parameters\n\n### Inbound SMS\n\n| Parameter | Description |\n|---|---|\n| `MessageSid` | Unique message identifier |\n| `AccountSid` | Your Twilio account SID |\n| `From` | Sender phone number (E.164) |\n| `To` | Your Twilio number |\n| `Body` | Message text |\n| `NumMedia` | Number of media attachments |\n| `MediaUrl0..N` | URL of each media attachment |\n| `MediaContentType0..N` | MIME type of each attachment |\n\n### Inbound Voice Call\n\n| Parameter | Description |\n|---|---|\n| `CallSid` | Unique call identifier |\n| `AccountSid` | Your Twilio account SID |\n| `From` | Caller phone number (E.164) |\n| `To` | Your Twilio number |\n| `CallStatus` | `queued`, `ringing`, `in-progress`, `completed`, `busy`, `failed`, `no-answer`, `canceled` |\n| `Direction` | `inbound` |\n| `ForwardedFrom` | Number that forwarded the call (if applicable) |\n\n### Message Status Callback\n\n| Parameter | Description |\n|---|---|\n| `MessageSid` | Unique message identifier |\n| `MessageStatus` | `accepted`, `queued`, `sending`, `sent`, `delivered`, `undelivered`, `failed`, `read` |\n| `ErrorCode` | Twilio error code (present on `failed`\u002F`undelivered`) |\n| `ErrorMessage` | Human-readable error description |\n\n### Debugger Event Callback\n\n| Parameter | Description |\n|---|---|\n| `Sid` | Debugger event identifier |\n| `AccountSid` | Account that generated the event |\n| `Level` | `Error` or `Warning` |\n| `Timestamp` | ISO 8601 time of occurrence |\n| `Payload` | JSON with `resource_sid`, `error_code`, `more_info`, `webhook` (request\u002Fresponse details) |\n\n---\n\n## CANNOT\n\n- **Cannot exceed 15-second voice webhook response time** — Twilio hangs up or falls back. Messaging webhooks retry on timeout.\n- **Cannot use HTTP in production** — HTTPS required. No self-signed certificates. Do not pin Twilio certificates — they rotate without notice.\n- **Cannot allowlist Twilio by IP** — Webhooks come from dynamic IPs. Use signature validation instead.\n- **Cannot guarantee status callback delivery or order** — Best-effort. Implement idempotency using `MessageSid` + `MessageStatus` or `CallSid` + `CallStatus` as composite keys.\n- **Cannot redirect without losing POST parameters** — HTTP 301\u002F302 redirects cause Twilio to follow with GET, dropping `Digits`, `RecordingUrl`, etc.\n- **Cannot use connection overrides on Conversations or Frontline webhooks** — Not supported for these products\n\n---\n\n## Next Steps\n\n- **Receive inbound SMS:** `twilio-messaging-webhooks`\n- **Voice call handling:** `twilio-voice-twiml`\n- **Scale webhook handling:** `twilio-reliability-patterns`\n- **Debug webhook failures:** `twilio-debugging-observability`\n- **Secure credentials:** `twilio-iam-auth-setup`\n","## Overview\n\nTwilio delivers events to your application via HTTP callbacks (webhooks). Inbound messages and calls trigger webhooks that expect a TwiML response; status callbacks and event streams push delivery and lifecycle data asynchronously. This skill covers the cross-product patterns that apply to every webhook integration.\n\n---\n\n## Prerequisites\n\n- Twilio account with a phone number or service configured with a webhook URL\n  -- New to Twilio? See `twilio-account-setup`\n- `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` -- see `twilio-iam-auth-setup`\n- SDK: `pip install twilio flask` \u002F `npm install twilio express`\n- Publicly accessible HTTPS endpoint (see Local Development section below)\n\n---\n\n## Quickstart\n\nReceive an inbound SMS and validate the request signature before replying.\n\n**Python (Flask)**\n```python\nimport os\nfrom flask import Flask, request, abort\nfrom twilio.request_validator import RequestValidator\nfrom twilio.twiml.messaging_response import MessagingResponse\n\napp = Flask(__name__)\nvalidator = RequestValidator(os.environ[\"TWILIO_AUTH_TOKEN\"])\n\n@app.route(\"\u002Fsms\", methods=[\"POST\"])\ndef incoming_sms():\n    sig = request.headers.get(\"X-Twilio-Signature\", \"\")\n    if not validator.validate(request.url, request.form, sig):\n        abort(403)\n    resp = MessagingResponse()\n    resp.message(f\"Got: {request.form.get('Body')}\")\n    return str(resp), 200, {\"Content-Type\": \"text\u002Fxml\"}\n```\n\n**Node.js (Express)**\n```node\nconst express = require(\"express\");\nconst twilio = require(\"twilio\");\nconst app = express();\napp.use(express.urlencoded({ extended: false }));\n\napp.post(\"\u002Fsms\", (req, res) => {\n    const valid = twilio.validateRequest(\n        process.env.TWILIO_AUTH_TOKEN,\n        req.headers[\"x-twilio-signature\"],\n        `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n        req.body\n    );\n    if (!valid) return res.status(403).send(\"Forbidden\");\n    const twiml = new twilio.twiml.MessagingResponse();\n    twiml.message(`Got: ${req.body.Body}`);\n    res.type(\"text\u002Fxml\").send(twiml.toString());\n});\n```\n\nSet your webhook URL in Console: **Phone Numbers > Active Numbers > (your number) > Messaging > \"A Message Comes In\"**.\n\n---\n\n## Key Patterns\n\n### 1. Webhook Types Across Products\n\n| Webhook type | Trigger | Expected response | Products |\n|---|---|---|---|\n| Inbound event | Message received \u002F call answered | TwiML (XML) | Messaging, Voice |\n| Status callback | Resource state change | `200` or `204` (no body required) | Messaging, Voice, Verify, Video |\n| Action URL | TwiML verb completes (`\u003CGather>`, `\u003CRecord>`) | Next TwiML | Voice |\n| Recording status | Recording processing completes | `200` or `204` | Voice |\n| Debugger event | Error or warning on account | `200` or `204` | All |\n| Event Streams | Any subscribed event | `200` or `204` | All (via Sink) |\n\n### 2. Signature Validation\n\nTwilio signs every webhook with an `X-Twilio-Signature` header (HMAC-SHA1 using your Auth Token). Always validate before processing.\n\n**Form-encoded requests (`application\u002Fx-www-form-urlencoded`):**\n\nPass the full URL and POST body parameters to the validator.\n\n**Python**\n```python\nfrom twilio.request_validator import RequestValidator\n\nvalidator = RequestValidator(os.environ[\"TWILIO_AUTH_TOKEN\"])\nis_valid = validator.validate(request.url, request.form, request.headers.get(\"X-Twilio-Signature\", \"\"))\n```\n\n**Node.js**\n```node\nconst { validateRequest } = require(\"twilio\");\n\nconst isValid = validateRequest(\n    process.env.TWILIO_AUTH_TOKEN,\n    req.headers[\"x-twilio-signature\"],\n    `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n    req.body\n);\n```\n\n**JSON requests (`application\u002Fjson`):**\n\nTwilio appends a `bodySHA256` query parameter to your URL. Use the SDK's JSON-specific validation.\n\n**Python**\n```python\nfrom twilio.request_validator import RequestValidator\n\nvalidator = RequestValidator(os.environ[\"TWILIO_AUTH_TOKEN\"])\nis_valid = validator.validate_body(\n    request.url,\n    request.get_data(as_text=True),\n    request.headers.get(\"X-Twilio-Signature\", \"\")\n)\n```\n\n**Node.js**\n```node\nconst twilio = require(\"twilio\");\n\n\u002F\u002F Use express.raw() or a verify callback to preserve the raw body\nconst isValid = twilio.validateRequestWithBody(\n    process.env.TWILIO_AUTH_TOKEN,\n    req.headers[\"x-twilio-signature\"],\n    `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n    req.rawBody  \u002F\u002F must be the exact bytes Twilio sent, not JSON.stringify(req.body)\n);\n```\n\n**Critical:** Use the SDK validator. Do not implement your own -- Twilio may add parameters without notice, and the exact algorithm (including port handling) has edge cases the SDK handles.\n\n### 3. Status Callback Handling\n\nStatus callbacks are asynchronous POST requests Twilio sends when a resource changes state. They do not expect TwiML -- return `200` or `204`.\n\n**Messaging status flow:** `queued` -> `sent` -> `delivered` (or `undelivered` \u002F `failed`)\n\nWhen using Messaging Services, the flow starts with `accepted` -> `queued` -> ...\n\n**Voice status events:** `initiated`, `ringing`, `answered`, `completed`\n\nSubscribe to specific events via `StatusCallbackEvent` parameter.\n\nStatus callbacks are signed with `X-Twilio-Signature` like all Twilio webhooks. Validate before acting on the payload -- an unvalidated endpoint lets anyone forge delivery status and drive downstream logic.\n\n**Python (Flask) -- messaging status handler**\n```python\n@app.route(\"\u002Fstatus\", methods=[\"POST\"])\ndef message_status():\n    sig = request.headers.get(\"X-Twilio-Signature\", \"\")\n    if not validator.validate(request.url, request.form, sig):\n        return \"Forbidden\", 403\n    sid = request.form.get(\"MessageSid\")\n    status = request.form.get(\"MessageStatus\")\n    error_code = request.form.get(\"ErrorCode\")\n    if status in (\"failed\", \"undelivered\") and error_code:\n        print(f\"Delivery failed {sid}: error {error_code}\")\n    return \"\", 204\n```\n\n**Node.js (Express) -- voice status handler**\n```node\napp.post(\"\u002Fcall-status\", (req, res) => {\n    const valid = twilio.validateRequest(\n        process.env.TWILIO_AUTH_TOKEN,\n        req.headers[\"x-twilio-signature\"],\n        `https:\u002F\u002F${req.headers.host}${req.originalUrl}`,\n        req.body\n    );\n    if (!valid) return res.status(403).send(\"Forbidden\");\n    const { CallSid, CallStatus, Duration } = req.body;\n    console.log(`${CallSid}: ${CallStatus} (${Duration}s)`);\n    res.sendStatus(204);\n});\n```\n\n**Attach status callbacks when creating resources:**\n\n```python\n# Messaging\nmessage = client.messages.create(\n    to=\"+15558675310\", from_=\"+15017122661\", body=\"Hello!\",\n    status_callback=\"https:\u002F\u002Fyourapp.com\u002Fstatus\"\n)\n\n# Voice\ncall = client.calls.create(\n    to=\"+15558675310\", from_=\"+15017122661\",\n    url=\"https:\u002F\u002Fyourapp.com\u002Fvoice\",\n    status_callback=\"https:\u002F\u002Fyourapp.com\u002Fcall-status\",\n    status_callback_event=[\"initiated\", \"ringing\", \"answered\", \"completed\"],\n    status_callback_method=\"POST\"\n)\n```\n\n### 4. Connection Overrides (Retry and Timeout Tuning)\n\nAppend URL fragments to any webhook URL to override default connection behavior. Fragments are not included in signature computation.\n\n**Format:** `https:\u002F\u002Fyourapp.com\u002Fwebhook#key=value&key=value`\n\n| Parameter | Key | Default | Range | Description |\n|---|---|---|---|---|\n| Connect Timeout | `ct` | 5000ms | 100-10000 | TCP connection timeout |\n| Read Timeout | `rt` | 15000ms | 100-15000 | Time to wait for first response byte |\n| Total Time | `tt` | 15000ms | 100-15000 | Total time for all retries |\n| Retry Count | `rc` | 1 | 0-5 | Number of retry attempts |\n| Retry Policy | `rp` | `ct` | `4xx`, `5xx`, `ct`, `rt`, `all` | What triggers a retry |\n| Edge Location | `e` | `ashburn` | `ashburn`, `dublin`, `frankfurt`, `sao-paulo`, `singapore`, `sydney`, `tokyo`, `umatilla` | Egress edge |\n\n**Examples:**\n\n```text\n# Retry up to 3 times on connection or read timeout\nhttps:\u002F\u002Fyourapp.com\u002Fsms#rc=3&rp=ct,rt\n\n# Fast failover: 1s connect timeout, 2 retries\nhttps:\u002F\u002Fyourapp.com\u002Fvoice#ct=1000&rc=2\n\n# Rotate edge locations on retry\nhttps:\u002F\u002Fyourapp.com\u002Fstatus#e=ashburn,dublin&rc=1\n```\n\nTwilio adds an `I-Twilio-Idempotency-Token` header on retries for deduplication.\n\n**Limitations:** Connection overrides are not available on Twilio Conversations or Frontline webhooks. Voice webhooks have a hard 15-second ceiling regardless of override values.\n\n### 5. Configure Webhook URLs via API\n\n**Python**\n```python\n# Phone number -- messaging\nclient.incoming_phone_numbers(\"PNxxxxxxxxxx\").update(\n    sms_url=\"https:\u002F\u002Fyourapp.com\u002Fsms\",\n    sms_method=\"POST\",\n    sms_fallback_url=\"https:\u002F\u002Fyourapp.com\u002Fsms-fallback\",\n    sms_fallback_method=\"POST\"\n)\n\n# Phone number -- voice\nclient.incoming_phone_numbers(\"PNxxxxxxxxxx\").update(\n    voice_url=\"https:\u002F\u002Fyourapp.com\u002Fvoice\",\n    voice_method=\"POST\",\n    voice_fallback_url=\"https:\u002F\u002Fyourapp.com\u002Fvoice-fallback\",\n    voice_fallback_method=\"POST\",\n    status_callback=\"https:\u002F\u002Fyourapp.com\u002Fcall-status\",\n    status_callback_method=\"POST\"\n)\n```\n\n**Node.js**\n```node\n\u002F\u002F Phone number -- messaging\nawait client.incomingPhoneNumbers(\"PNxxxxxxxxxx\").update({\n    smsUrl: \"https:\u002F\u002Fyourapp.com\u002Fsms\",\n    smsMethod: \"POST\",\n    smsFallbackUrl: \"https:\u002F\u002Fyourapp.com\u002Fsms-fallback\",\n    smsFallbackMethod: \"POST\",\n});\n\n\u002F\u002F Phone number -- voice\nawait client.incomingPhoneNumbers(\"PNxxxxxxxxxx\").update({\n    voiceUrl: \"https:\u002F\u002Fyourapp.com\u002Fvoice\",\n    voiceMethod: \"POST\",\n    voiceFallbackUrl: \"https:\u002F\u002Fyourapp.com\u002Fvoice-fallback\",\n    voiceFallbackMethod: \"POST\",\n    statusCallback: \"https:\u002F\u002Fyourapp.com\u002Fcall-status\",\n    statusCallbackMethod: \"POST\",\n});\n```\n\n### 6. Local Development with Tunnels\n\nTwilio cannot reach `localhost`. Use a tunnel to expose your local server.\n\n**ngrok (recommended for development):**\n```bash\nngrok http 5000\n# Copy the HTTPS URL, e.g. https:\u002F\u002Fabc123.ngrok-free.app\n```\n\nThen set the ngrok URL as your webhook in Console or via API.\n\n**Twilio CLI:**\n```bash\n# Install and use the CLI webhook plugin\ntwilio phone-numbers:update +15017122661 \\\n  --sms-url=\"https:\u002F\u002Fabc123.ngrok-free.app\u002Fsms\"\n```\n\n**ngrok caveats:**\n- Free tier URLs change on restart -- update Twilio config each time\n- Free tier sessions expire after hours -- use a stable host for anything beyond quick tests\n- For persistent local dev, use ngrok with a custom domain (paid) or deploy to a cloud host\n\n### 7. Event Streams (Webhook Sink)\n\nFor high-volume or cross-product event delivery, use Event Streams instead of per-resource status callbacks. Event Streams deliver events to a Sink (webhook, Kinesis, or Segment). The Twilio SDK does not wrap Event Streams -- use `requests` \u002F `fetch` directly.\n\n**Python -- create a webhook sink and subscribe to error events**\n```python\nimport os, requests\n\naccount_sid = os.environ[\"TWILIO_ACCOUNT_SID\"]\nauth_token = os.environ[\"TWILIO_AUTH_TOKEN\"]\n\n# Create a webhook sink\nsink = requests.post(\n    \"https:\u002F\u002Fevents.twilio.com\u002Fv1\u002FSinks\",\n    auth=(account_sid, auth_token),\n    data={\n        \"Description\": \"Error log sink\",\n        \"SinkType\": \"webhook\",\n        \"SinkConfiguration\": '{\"destination\": \"https:\u002F\u002Fyourapp.com\u002Fevents\", \"method\": \"POST\"}'\n    }\n).json()\n\n# Subscribe to error log events\nrequests.post(\n    \"https:\u002F\u002Fevents.twilio.com\u002Fv1\u002FSubscriptions\",\n    auth=(account_sid, auth_token),\n    data={\n        \"Description\": \"Error log subscription\",\n        \"SinkSid\": sink[\"sid\"],\n        \"Types\": '[{\"type\": \"com.twilio.error-logs.error.logged\"}]'\n    }\n)\n```\n\nSink types: `webhook`, `kinesis`, `segment`. Subscriptions filter which event types route to which sinks.\n\n### 8. HTTP Authentication for Webhook URLs\n\nTwilio supports HTTP Basic and Digest authentication. Embed credentials in the URL:\n\n```text\nhttps:\u002F\u002Fusername:password@yourapp.com\u002Fsms\n```\n\nThis provides an additional layer of protection beyond signature validation. Note: these credentials are visible in Console webhook configuration and may appear in server access logs -- rotate them independently of your Auth Token.\n\n---\n\n## Common Webhook Parameters\n\n### Inbound SMS\n\n| Parameter | Description |\n|---|---|\n| `MessageSid` | Unique message identifier |\n| `AccountSid` | Your Twilio account SID |\n| `From` | Sender phone number (E.164) |\n| `To` | Your Twilio number |\n| `Body` | Message text |\n| `NumMedia` | Number of media attachments |\n| `MediaUrl0..N` | URL of each media attachment |\n| `MediaContentType0..N` | MIME type of each attachment |\n\n### Inbound Voice Call\n\n| Parameter | Description |\n|---|---|\n| `CallSid` | Unique call identifier |\n| `AccountSid` | Your Twilio account SID |\n| `From` | Caller phone number (E.164) |\n| `To` | Your Twilio number |\n| `CallStatus` | `queued`, `ringing`, `in-progress`, `completed`, `busy`, `failed`, `no-answer`, `canceled` |\n| `Direction` | `inbound` |\n| `ForwardedFrom` | Number that forwarded the call (if applicable) |\n\n### Message Status Callback\n\n| Parameter | Description |\n|---|---|\n| `MessageSid` | Unique message identifier |\n| `MessageStatus` | `accepted`, `queued`, `sending`, `sent`, `delivered`, `undelivered`, `failed`, `read` |\n| `ErrorCode` | Twilio error code (present on `failed`\u002F`undelivered`) |\n| `ErrorMessage` | Human-readable error description |\n\n### Debugger Event Callback\n\n| Parameter | Description |\n|---|---|\n| `Sid` | Debugger event identifier |\n| `AccountSid` | Account that generated the event |\n| `Level` | `Error` or `Warning` |\n| `Timestamp` | ISO 8601 time of occurrence |\n| `Payload` | JSON with `resource_sid`, `error_code`, `more_info`, `webhook` (request\u002Fresponse details) |\n\n---\n\n## CANNOT\n\n- **Cannot exceed 15-second voice webhook response time** — Twilio hangs up or falls back. Messaging webhooks retry on timeout.\n- **Cannot use HTTP in production** — HTTPS required. No self-signed certificates. Do not pin Twilio certificates — they rotate without notice.\n- **Cannot allowlist Twilio by IP** — Webhooks come from dynamic IPs. Use signature validation instead.\n- **Cannot guarantee status callback delivery or order** — Best-effort. Implement idempotency using `MessageSid` + `MessageStatus` or `CallSid` + `CallStatus` as composite keys.\n- **Cannot redirect without losing POST parameters** — HTTP 301\u002F302 redirects cause Twilio to follow with GET, dropping `Digits`, `RecordingUrl`, etc.\n- **Cannot use connection overrides on Conversations or Frontline webhooks** — Not supported for these products\n\n---\n\n## Next Steps\n\n- **Receive inbound SMS:** `twilio-messaging-webhooks`\n- **Voice call handling:** `twilio-voice-twiml`\n- **Scale webhook handling:** `twilio-reliability-patterns`\n- **Debug webhook failures:** `twilio-debugging-observability`\n- **Secure credentials:** `twilio-iam-auth-setup`\n",{"name":5,"description":7},"main","907b1d897cc6743f7f133f8ea2021e1331b0b020",".codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Ftwilio-developer-kit\u002Fskills\u002Ftwilio-webhook-architecture","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque","https:\u002F\u002Fgithub.com\u002Frossboyd","www.bigideasgroup.co.uk","2026-09-22 02:03:50",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add rossboyd\u002Fquickque --skill twilio-webhook-architecture",{"tool":37,"command":38},"bunx","bunx skills add rossboyd\u002Fquickque --skill twilio-webhook-architecture",{"tool":40,"command":41},"pnpm","pnpm dlx skills add rossboyd\u002Fquickque --skill twilio-webhook-architecture","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Ftwilio-developer-kit\u002Fskills\u002Ftwilio-webhook-architecture\u002FSKILL.md",true,[45],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"agents\u002Fopenai.yaml","REFERENCE","参考文档",235,"https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Ftwilio-developer-kit\u002Fskills\u002Ftwilio-webhook-architecture\u002Fagents\u002Fopenai.yaml",[52,61,69,76,83,91],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":56,"licenseFileUrl":57,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M7CJSS21K09H3ZQZMPFR4ZAG","skill-installer","Install Codex skills into $CODEX_HOME\u002Fskills from a curated list or a GitHub repo path. Use when a user asks to list installable skills, install a curated skill, or install a skill from another repo (including private repos).","Apache-2.0","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-installer\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-installer\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":56,"licenseFileUrl":65,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M7CJSM1F4E7RBXCS3C18EFBY","skill-creator","Create or update a Codex skill with appropriately scoped instructions and any needed supporting resources.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-creator\u002Flicense.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-creator\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7CJSGF2PJM504Q6TZCNT27C","review-agent","Perform a read-only, defect-first review of a specified code change and return every actionable finding. Use when another agent delegates review of uncommitted changes, a base-branch diff, a commit, or custom review instructions.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Freview-agent\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7CJSBQTPFEQYZF4VWS7QZ3N","plugin-creator","Create and scaffold plugin directories for Codex with a required `.codex-plugin\u002Fplugin.json`, optional plugin folders\u002Ffiles, valid manifest defaults, and personal-marketplace entries by default. Use when Codex needs to create a new personal plugin, add optional plugin structure, generate or update marketplace entries for plugin ordering and availability metadata, or update an existing local plugin during development with the CLI-driven cachebuster and reinstall flow.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fplugin-creator\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":56,"licenseFileUrl":87,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M7CJS5BHJZKA16353PVZGC50","openai-docs","Use for Codex models\u002Fpricing, scheduled tasks, skills, settings, setup, troubleshooting, customization, automations, and self-knowledge—including 'you,' 'your,' 'this app,' or 'this coding agent' when they refer to Codex—and for OpenAI APIs\u002Fproducts and ChatGPT Work. Also use for model choice\u002Fmigration, prompting, SDKs, Responses, Realtime, agents, evals, and Chat\u002FWork\u002FCodex comparisons. Do not use for generic app\u002Fsoftware tasks that merely mention Codex.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fopenai-docs\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fopenai-docs\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":56,"licenseFileUrl":95,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":19},"01M7CJRY1FC048P3RF4YQZ6J8B","imagegen","Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG\u002Fvector\u002Fcode-native assets, extending an established icon or logo system, or building the visual directly in HTML\u002FCSS\u002Fcanvas.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fimagegen\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fimagegen\u002FSKILL.md",[],[]]