向松弛的机器人发送直接消息并获得响应

Sending direct message to a bot in slack and get the response

我正在尝试弄清楚如何使用 Slack API 向 Slack 中的机器人发送直接消息并获得机器人的响应。例如,我使用 chat.postMessage:

curl -X POST -d 'token=xoxp-xxxx-xxxxxxxxx-xxxx&channel=BOT_ID&text=where?&as_user=true' https://slack.com/api/chat.postMessage

机器人响应:

I'm at hubot-server1.local
I'm at hubot-server2.local

我想捕获响应。我可以使用什么 Slack API 来捕获? chat.postMessage 没有 return 它。

感谢您的回复。

此致...

没有 API 方法可以直接 return 来自机器人的响应。要捕获机器人(和用户)的响应,您需要从频道中读取消息。

通过网络 API 您可以通过调用 channels.history for public channels (or groups.history private channels and similar names methods for other conversation types. you can also use the new conversations.history 方法来访问所有类型的频道)。

这些方法会给你一个频道的所有消息,你需要在你的应用程序中过滤出正确的消息。

您还可以通过 RTM API and the Events API.

获取频道的所有新消息