把任意文本改写成可直接喂给 TTS 引擎的朗读稿,处理数字、单位、缩写、URL 与发音。
记忆
Elevenlabs Twilio Memory Bridge
为 ElevenLabs + Twilio 语音通话接入长期来电者记忆,并在每次来电时动态注入上下文。
它能做什么
基于 FastAPI 的个性化 Webhook 服务,每次 Twilio 来电时被 ElevenLabs 调用一次。它读取来电者的长期记忆事实与按日上下文笔记,与可自定义的人设模板合并,以系统提示词覆盖的形式返回,让 agent 在接听瞬间就拥有完整上下文。数据以 ./data/ 下的 JSON 文件持久化,零外部依赖;支持可选 Fernet 加密、HMAC-SHA256 电话号码哈希(可配置 salt)、生产环境强制 Webhook 签名校验,以及对管理接口的限流。
什么时候用它
- Twilio 重复来电者按姓名与历史工单被接待
- 把当日活动或排班动态注入语音 agent 的人设
- 不引入数据库,跨通话保存来电者偏好与备注
- 搭建带加密记忆与签名校验的 ElevenLabs 语音坐席
技能文档
elevenlabs-twilio-memory-bridge
Personalization webhook service for ElevenLabs + Twilio voice agents with persistent caller memory.
What It Does
When a call arrives on your Twilio number, ElevenLabs' native integration triggers this webhook. The bridge looks up the caller's history, loads long-term memory facts and daily context notes, combines them with a customizable soul/personality template, and returns everything as a system prompt override so your agent greets each caller with full context.
Architecture
- No audio proxying — ElevenLabs and Twilio handle media directly
- Webhook only — called once per inbound call to inject context
- File-based persistence — JSON files in
./data/, zero external dependencies - OpenClaw compatible — works with any OpenAI-compatible LLM endpoint
Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/webhook/personalize | POST | ElevenLabs calls this on inbound call |
/webhook/post-call | POST | Optional post-call cleanup |
/api/memory/{phone_hash} | POST | Add long-term fact about a caller |
/api/notes | POST | Add global or caller-scoped context note |
/health | GET | Health check |
Setup
- Clone repo,
pip install -r requirements.txt - Copy
.env.exampleto.env, fill in secrets - Configure ElevenLabs agent with Custom LLM pointing to your OpenClaw instance
- Enable system prompt + first message overrides in agent Security settings
- Add webhook URL
https://your-domain/webhook/personalizein ElevenLabs settings - Import Twilio number in ElevenLabs dashboard
- Run:
uvicorn app:app --host 0.0.0.0 --port 8000
Required Environment Variables
ELEVENLABS_API_KEY— scoped ElevenLabs keyELEVENLABS_AGENT_ID— your agent IDOPENCLAW_API_BASE_URL— your OpenClaw instance URLPUBLIC_BASE_URL— publicly reachable URL of this serviceADMIN_API_KEY— secret for admin endpoint authPHONE_HASH_SALT— salt for phone number hashing. Generate withopenssl rand -base64 32. Changing this invalidates all existing caller data.WEBHOOK_SECRET— shared secret for HMAC webhook verification. Must be set in production.
Optional Environment Variables
| Variable | Default | Purpose |
|---|---|---|
DATA_ENCRYPTION_KEY | (unset) | Fernet key for encrypting memories and notes at rest. Generate with python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())". When unset, data is stored as plain JSON. |
SOUL_TEMPLATE_PATH | ./soul_template.md | Path to personality template file |
DATA_DIR | ./data | Directory for JSON persistence |
ALLOWED_ORIGINS | (unset) | Comma-separated CORS origins |
HOST | 0.0.0.0 | Bind address for uvicorn |
PORT | 8000 | Listen port |
LOG_LEVEL | INFO | Python logging level |
Security
- Deterministic phone hashing — Phone numbers are hashed with HMAC-SHA256 using
PHONE_HASH_SALTas the key before storage. Changing the salt invalidates existing caller data. - Encryption at rest — Memories and notes are encrypted with Fernet when
DATA_ENCRYPTION_KEYis set. Data is stored as plain JSON when the key is not configured. - Mandatory webhook verification —
WEBHOOK_SECRETis required in production. Webhooks are rejected when the secret is not set (fail-closed). - Rate limiting — Admin endpoints (
/api/memory,/api/notes) are limited to 30 requests per minute. Webhook endpoints are limited to 60 per minute. - File locking — JSON reads and writes use POSIX advisory locks (
fcntl) to prevent race conditions under concurrent access. - Restrictive permissions — Data directory (
DATA_DIR) is created with0o700permissions. JSON files are written with0o600. - Secrets from env vars only — No hardcoded credentials in source.
- Safe for public GitHub repos — All sensitive config is loaded from environment variables.
Migration from v1.1.x to v1.2.x
v1.2.0 introduces breaking security changes:
-
PHONE_HASH_SALT is now required — Previously, phone numbers were hashed with unsalted SHA-256. Now HMAC-SHA256 with a salt is required. Existing caller data will be unreachable after upgrading because the hash keys change. You must accept data loss and start fresh (v1.2.0 uses a different hashing algorithm).
-
WEBHOOK_SECRET is now required — Previously optional for development. Now mandatory in all environments. Webhooks without a valid secret are rejected.
-
DATA_ENCRYPTION_KEY is optional but recommended — When set, all new memories and notes are encrypted at rest. Existing unencrypted data remains readable.
Migration checklist
- Generate a salt:
openssl rand -base64 32 - Generate a webhook secret:
openssl rand -hex 32 - Generate an encryption key (optional):
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())" - Add all to
.env - Review CORS settings —
ALLOWED_ORIGINSnow defaults to disabled - Update ElevenLabs webhook settings with the new
WEBHOOK_SECRET - Note: v1.2.0 requires fresh data — existing caller sessions will be recreated on first call
相关技能
为任意 agent 接通真实电话线路,对接 Twilio 与 OpenAI Realtime,支持来电筛选与确认式外呼。
通过文本提示和三家语音服务商,生成配音、音乐、音效及克隆语音音频。
通过托管 OAuth 代理调用 Slack API,实现发消息、管频道、列用户和定时投递。
把消息转发到任意 OpenAI 兼容的 AI 代理,并跨调用维持多轮会话。
通过托管认证调用 Instantly API v2,统一管理冷邮件活动、线索、发件账户与分析数据。