twilio-webhook-architecture
БесплатноБез исполняемых скриптовНе проверенDesign, secure, and operate Twilio webhook endpoints. Covers inbound event handling, status callbacks, signature validation, connection overrides for retry…
от openai★ 8 494 звезды на GitHubОб этом скилле
Overview
Twilio 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.
Prerequisites
- Twilio account with a phone number or service configured with a webhook URL
-- New to Twilio? See
twilio-account-setup TWILIO_ACCOUNT_SIDandTWILIO_AUTH_TOKEN-- seetwilio-iam-auth-setup- SDK:
pip install twilio flask/npm install twilio express - Publicly accessible HTTPS endpoint (see Local Development section below)
Quickstart
Receive an inbound SMS and validate the request signature before replying.
Python (Flask)
import os
from flask import Flask, request, abort
from twilio.request_validator import RequestValidator
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
validator = RequestValidator(os.environ["TWILIO_AUTH_TOKEN"])
@app.route("/sms", methods=["POST"])
def incoming_sms():
sig = request.headers.get("X-Twilio-Signature", "")
if not validator.validate(request.url, request.form, sig):
abort(403)
resp = MessagingResponse()
resp.message(f"Got: {request.form.get('Body')}")
return str(resp), 200, {"Content-Type": "text/xml"}
Node.js (Express)
const express = require("express");
const twilio = require("twilio");
const app = express();
app.use(express.urlencoded({ extended: false }));
app.post("/sms", (req, res) => {
const valid = twilio.validateRequest(
process.env.TWILIO_AUTH_TOKEN,
req.headers["x-twilio-signature"],
`https://${req.headers.host}${req.originalUrl}`,
req.body
);
if (!valid) return res.status(403).send("Forbidden");
const twiml = new twilio.twiml.MessagingResponse();
twiml.message(`Got: ${req.body.Body}`);
res.type("text/xml").send(twiml.toString());
});
Set your webhook URL in Console: Phone Numbers > Active Numbers > (your number) > Messaging > "A Message Comes In".
Key Patterns
1. Webhook Types Across Products
| Webhook type | Trigger | Expected response | Products |
|---|---|---|---|
| Inbound event | Message received / call answered | TwiML (XML) | Messaging, Voice |
| Status callback | Resource state change | 200 or 204 (no body required) |
Messaging, Voice, Verify, Video |
| Action URL | TwiML verb completes (<Gather>, <Record>) |
Next TwiML | Voice |
| Recording status | Recording processing completes | 200 or 204 |
Voice |
| Debugger event | Error or warning on account | 200 or 204 |
All |
| Event Streams | Any subscribed event | 200 or 204 |
All (via Sink) |
2. Signature Validation
Twilio signs every webhook with an X-Twilio-Signature header (HMAC-SHA1 using your Auth Token). Always validate before processing.
Form-encoded requests (application/x-www-form-urlencoded):
Pass the full URL and POST body parameters to the validator.
Python
from twilio.request_validator import RequestValidator
validator = RequestValidator(os.environ["TWILIO_AUTH_TOKEN"])
is_valid = validator.validate(request.url, request.form, request.headers.get("X-Twilio-Signature", ""))
Node.js
const { validateRequest } = require("twilio");
const isValid = validateRequest(
process.env.TWILIO_AUTH_TOKEN,
req.headers["x-twilio-signature"],
`https://${req.headers.host}${req.originalUrl}`,
req.body
);
JSON requests (application/json):
Twilio appends a bodySHA256 query parameter to your URL. Use the SDK's JSON-specific validation.
Python
from twilio.request_validator import RequestValidator
validator = RequestValidator(os.environ["TWILIO_AUTH_TOKEN"])
is_valid = validator.validate_body(
request.url,
request.get_data(as_text=True),
request.headers.get("X-Twilio-Signature", "")
)
Node.js
const twilio = require("twilio");
// Use express.raw() or a verify callback to preserve the raw body
const isValid = twilio.validateRequestWithBody(
process.env.TWILIO_AUTH_TOKEN,
req.headers["x-twilio-signature"],
`https://${req.headers.host}${req.originalUrl}`,
req.rawBody // must be the exact bytes Twilio sent, not JSON.stringify(req.body)
);
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.
3. Status Callback Handling
Status callbacks are asynchronous POST requests Twilio sends when a resource changes state. They do not expect TwiML -- return 200 or 204.
Messaging status flow: queued -> sent -> delivered (or undelivered / failed)
When using Messaging Services, the flow starts with accepted -> queued -> ...
Voice status events: initiated, `rin
Установить twilio-webhook-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл twilio-webhook-architecture?
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.
Как установить скилл twilio-webhook-architecture?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл twilio-webhook-architecture запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic