如何使用 Slack API 调用 /poll 命令?
How do you invoke the /poll command using the Slack API?
我的 slack 频道支持来自 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, which doesn't allow specifying any OAuth permission scopes。遗留令牌已具有本案例所需的权限。
您必须使用 "undocumented" chat.command
API 函数而不是 chat.postMessage
。此函数对 channel
参数不太友好——您必须提供频道 ID 而不是人性化的频道名称。
channel_id = slack.channels.get_channel_id('test')
slack.chat.command(
channel=channel_id,
command='/poll',
text='"Do you prefer cats or dogs?" "Cats" "Dogs"'
)
感谢 V13Axel in this Wee-Slack bug tracker 为 chat.command
提供了一些调试信息,让我明白了。
根据@Erik_Kalkoken的unofficial documentation,chat.command
requires the scope post
. Since this scope does not seem to be available in the app config window you need to provide a legacy token for this to work.
我遇到了完全相同的问题,所以我做了一些编码,这里是一个工作示例:
https://github.com/dazlious/slack-cmd-trigger
您可以使用您的 api-token 通过命令触发任何频道。
我的 slack 频道支持来自 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, which doesn't allow specifying any OAuth permission scopes。遗留令牌已具有本案例所需的权限。
您必须使用 "undocumented" chat.command
API 函数而不是 chat.postMessage
。此函数对 channel
参数不太友好——您必须提供频道 ID 而不是人性化的频道名称。
channel_id = slack.channels.get_channel_id('test')
slack.chat.command(
channel=channel_id,
command='/poll',
text='"Do you prefer cats or dogs?" "Cats" "Dogs"'
)
感谢 V13Axel in this Wee-Slack bug tracker 为 chat.command
提供了一些调试信息,让我明白了。
根据@Erik_Kalkoken的unofficial documentation,chat.command
requires the scope
post
. Since this scope does not seem to be available in the app config window you need to provide a legacy token for this to work.
我遇到了完全相同的问题,所以我做了一些编码,这里是一个工作示例:
https://github.com/dazlious/slack-cmd-trigger
您可以使用您的 api-token 通过命令触发任何频道。