跳到主要内容

SMS 设置

概述

SMS channel 把 Anyy 连接到 Twilio SMS。入站短信通过 Twilio webhook 到达,Anyy 通过 Twilio Messages API 回复。

SMS 是 direct-message channel。当前 adapter 不支持群组、thread 或 media。

前提条件

  • Twilio account SID。
  • Twilio auth token。
  • Twilio sender number。
  • 一个能访问 Anyy gateway 的公网 webhook endpoint。

配置

创建凭据

创建或复用 Twilio Messaging number。把 Twilio 入站 SMS webhook 配置到 Anyy SMS webhook path:

/channels/sms/twilio

配置 Anyy

anyy setup channels sms \
--set account_sid=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--set from_number='+15551234567' \
--secret auth_token='twilio-auth-token' \
--write-config

setup 默认值:

字段默认值
account_idtwilio
webhook_path/channels/sms/twilio
dm_policyopen
send_chunk_chars1500

启动 Gateway

anyy gateway start
anyy channels reload

通过你自己的 HTTPS ingress 暴露 gateway webhook endpoint。Adapter 会注册 path,但 Anyy 不会自动配置公网 DNS 或 TLS。

运行 Doctor 检查

anyy channels doctor sms

访问策略

私信

私有助手建议使用 dm_policy: allowlist,并在 allow_from 中写 E.164 电话号码:

channels:
sms:
dm_policy: allowlist
allow_from:
- "+15557654321"

群组

这个 adapter 没有实现 SMS 群组消息。

管理员

SMS admission policy 与 messaging command 授权是两层。

Sessions

每个被接受的电话号码映射到一个 Anyy session。

媒体支持

入站媒体

SMS 没有声明 inbound media 能力。

出站媒体

SMS 只发送文本回复。

命令

把共享 messaging commands 当作普通短信文本发送。短信投递可能拆分长回复。

Cron 投递

anyy cron create \
--name "SMS reminder" \
--schedule "30m" \
--prompt "Remind me to leave" \
--delivery-target current_user_default \
--delivery-channel sms

故障排查

  • Webhook 没有被调用:检查 Twilio 中配置的公网 URL。
  • 无法回复:检查 account_sidauth_token_reffrom_number
  • 意外发件人被接受:切换到 dm_policy: allowlist
  • 长回复显示混乱:如果运营商处理长短信不好,降低 send_chunk_chars