How do you invoke the /poll command using the Slack API?

旧街凉风 提交于 2019-11-29 04:35:30

You have to use the "undocumented" chat.command API function instead of chat.postMessage. This function is a little less friendly with the channel parameter -- you have to provide the channel ID and not the human-friendly channel name.

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"'
)

Thanks to V13Axel in this Wee-Slack bug tracker for providing some debugging info for the chat.command that clued me in.

According to @Erik_Kalkoken's 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.

I was stumbling across the exact same problem, so I did a bit of coding and a working example is here:

https://github.com/dazlious/slack-cmd-trigger

You can trigger with your api-token any channel with a command.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!