如何模拟您的聊天机器人 "writing" 使用 Facebook Messenger API 的响应?

How to simulate your chat bot is "writing" a response using the Facebook Messenger API?

我看到一些聊天机器人在 F8 会议期间发布,在回答之前显示三点 "writing" 气泡。尚未找到有关如何在我的聊天机器人中重现该行为的任何文档,它是必须发送的特殊负载还是某种配置或特殊消息?

当您有按钮模板并且有人点击 "button" 以获得 "postback"(documentation 部分 "button teplate")时。

然后在您解析消息的过程中发送回复,它显示为 "writing"。

借助 THIS 方法 sendTyping

这就是文档所说的

Sends the user an indication that the bot is typing. For long running operations this should be called every few seconds.

这可以使用 api(文档 here)中的发件人操作字段来完成。

例如

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "sender_action":"typing_on"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN" 

将启动 3 点动画。这会在 20 秒后或 "typing_off" 发送者操作后自动停止。