【发布时间】:2016-10-02 14:22:44
【问题描述】:
我是 Slack Bot 集成的新手。我想在我的消息上有按钮,所以我的代码是
message = {
"text": "Would you like to play a game?",
"attachments": [
{
"text": "Choose a game to play",
"attachment_type": "default",
"actions": [
{
"name": "chess",
"text": "Chess",
"type": "button",
"value": "chess"
}
]
}
]
}
return sc.api_call("chat.postMessage",
as_user="true",
channel=channel_id,
text=message)
但在 Slack 频道我看到了这个
text=Would+you+like+to+play+a+game%3F&attachments=%5B%7B%27text%27%3A+%27Choose+a+game+to+play%27%2C+%27attachment_type%27%3A+%27default%27%2C+%27actions%27%3A+%5B%7B%27text%27%3A+%27Chess%27%2C+%27type%27%3A+%27button%27%2C+%27name%27%3A+%27chess%27%2C+%27value%27%3A+%27chess%27%7D%5D%7D%5
为什么会这样??
谢谢
【问题讨论】:
-
这看起来可能与您正在使用的 slack API 包装器有关。您是否尝试过使用带有
requests的HTTP 调用手动执行此操作?你也在格式化消息looks fine. -
请记住,
chat.postMessage不接受 JSON 帖子正文。您需要将消息作为x-www-form-urlencoded参数发送。此外,attachments字段实际上需要 JSON,但它必须是 URL 编码的 JSON。像这样的纯 JSON 消息体不适用于 Web API。
标签: python django bots slack-api