Search code examples
slackslack-api

Slack polls with HTTP Response


I'm trying to have my backend create a poll for a given user and when the user responds to the poll receive the response on the backend. However I cannot find a way to do the second part with an API available.

I know I can use Incoming Webhooks to send a command to users slackbot channel: /poll .. ... ... however I'm unsure how to receive a response from when user selects one of the options in the poll.


Solution

  • OK, one approach would be

    • Slash command for the /pollcommand, it will send a request to your app every time a user enters the command
    • Your app can then sends the actual message containing the poll details back to the channel incl. message menus simply by responding to the slash request or with Web API e.g. chat.PostMessage
    • User chooses polls option from message menus. Chosen option is send back to your app by Slack.

    This is just one approach. Alternatively you could also show the options as message buttons or open a Dialog for the user.

    I would advise against using outgoing webhooks, since its no longer part of the main features (and slash commands and interactive menus will send a request directly to your app anyway). Also Web API / chat.PostMessage is better than Incoming webhooks.