我的松弛通道支持Simple Poll应用程序的 /poll
命令 . 如何使用Slack API调用此命令?
使用python slack(er) API module:
from slacker import Slacker
# Using what's now called a "legacy token"
slack = Slacker('my-token')
slack.chat.post_message(
'#test',
'/poll "Do you prefer cats or dogs?" "Cats" "Dogs"',
as_user=False,
username="Poll Bot",
icon_emoji=':question:',
parse='full')
该消息仅作为纯文本显示在#test通道中,未转换为轮询 .
我尝试在消息中使用 <!poll>
而不是 /poll
,如message formatting documenation中所暗示的那样,但结果相同 .
注意:这个问题现在有点旧了,在重新访问时我发现我的代码正在使用现在称为legacy token的代码,它不允许指定任何OAuth permission scopes . 旧版令牌已具有此案例所需的权限 .
2 回答
您必须使用"undocumented" chat.command API函数而不是
chat.postMessage
. 使用channel
参数时,此功能不太友好 - 您必须提供通道ID,而不是人性化的通道名称 .感谢V13Axel in this Wee-Slack bug tracker为
chat.command
提供了一些调查信息 .根据@ Erik_Kalkoken的unofficial documentation,
chat.command
我遇到了完全相同的问题,所以我做了一些编码,这里有一个工作示例:
https://github.com/dazlious/slack-cmd-trigger
您可以使用命令触发任何通道的api-token .