Twilio Comms
Automate SMS, voice calls, WhatsApp messaging, and two-factor authentication flows via the Twilio API. Send and track messages, place and monitor outbound calls, send WhatsApp templates or free-form messages, and run complete Verify 2FA flows — all from a single Python CLI tool.
Setup
CODEBLOCK0
Get credentials: console.twilio.com → Account Info.
Commands / Usage
CODEBLOCK1
Requirements
- - Python 3.8+
- INLINECODE0 (
pip install requests) - Environment variables:
TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, INLINECODE4 - Optional:
TWILIO_VERIFY_SERVICE_SID for Verify/2FA commands
Twilio Comms
通过Twilio API自动执行短信、语音通话、WhatsApp消息和双因素认证流程。发送并跟踪消息、发起并监控外呼、发送WhatsApp模板或自由格式消息、运行完整的Verify 2FA流程——全部通过一个Python CLI工具完成。
设置
bash
export TWILIOACCOUNTSID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export TWILIOAUTHTOKEN=yourauthtoken_here
export TWILIOFROMNUMBER=+15550001234 # 你的Twilio号码
export TWILIOVERIFYSERVICE_SID=VAxx... # 可选,用于Verify/2FA
获取凭证:console.twilio.com → 账户信息。
命令/用法
bash
── 短信 ─────────────────────────────────────────────────
发送短信
python3 scripts/twilio_comms.py sms-send --to +61400000000 --body 来自Twilio的问候!
python3 scripts/twilio_comms.py sms-send --to +61400000000 --body 自定义发送者 --from +15550001234
列出最近消息
python3 scripts/twilio_comms.py sms-list
python3 scripts/twilio_comms.py sms-list --limit 50 --to +61400000000
获取消息投递状态
python3 scripts/twilio_comms.py sms-status --sid SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
── 语音 ───────────────────────────────────────────────
发起外呼(播放TwiML消息)
python3 scripts/twilio_comms.py call-make --to +61400000000 --message 你好,这是一通自动语音电话。
python3 scripts/twilio_comms.py call-make --to +61400000000 --twiml-url https://demo.twilio.com/docs/voice.xml
列出最近通话
python3 scripts/twilio_comms.py call-list
python3 scripts/twilio_comms.py call-list --limit 25 --status completed
获取通话详情和状态
python3 scripts/twilio_comms.py call-status --sid CAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
获取通话录音
python3 scripts/twilio_comms.py call-recordings --call-sid CAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
── WHATSAPP ────────────────────────────────────────────
发送自由格式WhatsApp消息(24小时会话窗口内)
python3 scripts/twilio_comms.py wa-send --to +61400000000 --body 来自通过Twilio发送的WhatsApp的问候!
发送模板消息(24小时窗口外)
python3 scripts/twilio_comms.py wa-template --to +61400000000 --template 您的预约已确认为{{1}}。 --params 周一 下午3点
── 验证/2FA ────────────────────────────────────────
发送验证码(短信或语音)
python3 scripts/twilio_comms.py verify-send --to +61400000000
python3 scripts/twilio_comms.py verify-send --to +61400000000 --channel voice
检查/验证验证码
python3 scripts/twilio_comms.py verify-check --to +61400000000 --code 123456
要求
- - Python 3.8+
- requests(pip install requests)
- 环境变量:TWILIOACCOUNTSID、TWILIOAUTHTOKEN、TWILIOFROMNUMBER
- 可选:用于Verify/2FA命令的TWILIOVERIFYSERVICE_SID