Slack polls with HTTP Response - slack

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.

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.

Related

How can i ignore user messages in MS Bot framework using direct line channel

I have created a bot in one scenario it will call an API and it will take same time to get the output from that API, if in between user type anything it will start working on the text which user sent recently. I want till API output is not received, if user sent any messages it will get ignored.
If your bot is integrated into some app then you can actually disable the send button until you receive an answer for the previous question.
I am setting one session when user is requesting to talk with Live Agent, Then i am checking if that session is in progress and any new message is coming from user then i am just ignoring them.

Slack API - clicking a button in a Slack conversation sends a message on the channel

In a Slack conversation, is it possible to click on a button to send a message to the Slack channel?
The Slack conversation could be:
The user types a word (or message)
A slackbot shows some text and two buttons
The user clicks on a button to send a TEXT message to the Slack channel
The Slackbot reacts on the 'action' message.
It is not possible to create an REST service for my Slackbot, because the Slackbot is behind a firewall. So, registering commands is not possible.
So sending a message as the result of a button click is needed. The Slackbot can react on that message.
I read that attachments could be a good way to do this, BUT the is 'outmoded'.
I tried to send an secondary attachment, which is outmoded, but that was not possible.
The next approach was adding a webhook. So pushing a button resulted in using the url, but that is of course not possible because I cannot send a POST request via a simple (get) url.
Please give a short example.
This will not work.
Every interactive feature (e.g. buttons) require your app to be able to receive POST requests from Slack through the public Internet. Since you say you can not provide that (e.g. behind a company firewall) you will not be able to use any interactive features.
See also this answer: How to integrate internal APIs (Not accessible outside office network) to slack slash commands

Unable to get timestamp of the message posted by Slack App

Whenever my app posts ephemeral message to Slack channel (in response to a query by a user), I am unable to get the timestamp of my Slack app response. As I want to delete it once the user has made a selection using one of the buttons. Although I have subscribed to 'message.channels' event, I don't get a notification to my app whenever my app posts in the channel (in response to the user input), therefore, I am unable to get the timestamp of the message which I'll use to delete it. All I want is the timestamp of the message posted by my app so that I can delete it but I am unable to receive the timestamp. Please help!
For e.g. in Giphy app for Slack. Let's say the user invokes the app by calling '/giphy [dog]' where 'dog' is just an example of a search term. The app responds by sending a gif and user can either send it, shuffle to the next one or cancel it. I want a similar capability of cancelling the app response but I need the timestamp of the message in order to do so therefore I am asking for help.
Thanks.
Your approach can not work, because Slack is handling ephemeral messages differently from "normal" messages. They are only visible by one user and can not be modified by API methods (e.g. deletion).
But of course its possible to replace ephemeral messages. Here is how:
Your app can just reply to the interactive message request from Slack with a new message. That new message will by default override the original message including ephemeral messages.
You can reply in two ways:
Directly reply to the request from Slack with a message within 3 seconds
Send a message to the response_url from the Slack request within 30 minutes.
See here for the official documentation on how to respond to interactive messages.
This approach works both with interactive messages and slash commands.
See also this answer for a similar situation.

Design Slackbot service to send automated messages

It is my very first time to write a slack bot and i am wondering how to design it.
The bot supposed to be available and respond to end-users' messages immediately.
The thing is that I need that the bot will also send schedules messages to registered users with automation results.
Use case example:
A user sends a message to the bot and registered to a service that
will check for changes in X. On a specific interval, my backend will
call an automation that checks for those changes and will send a
message to the user with the results.
What will be the best practice for this scenario?
Here is a basic outline.
1. Basic setup
Slack app with bot user
Database
Scheduler (e.g. local CRON service, or web-cron like cron-job.org)
2. Registration
Use Events API to listen to messages from users send via mention (app_mention) or direct message (message.im)
You app needs to store the received "registration" from each user in a database
Respond to user request directly if needed with chat.postMessage
3. Scheduled response
Scheduler calls your app
Your app check if responses are due with a database query
If yes: App sends responses to users via chat.postMessage (but not more than one message per sec due to rate limiting)

Difference between Sash Command and Out going webhook

I know following about slack slash commands and out going webhooks
1) Slash Commands:
- When user types slash command, it Will trigger external URL (URL of external web service), with all required data and message
- Web service would process that as required, and would respond with HTTP Response.
2) Outgoing webhook:
- When user sends message with triggering words(optional) in specified channel, it will trigger external URL (URL of external web service), with all required data and message
- Web service would process that as required, and would respond with HTTP Response
Purpose of both these functionalities is same. Only difference I can see is - with slash command, there is no way to define triggering criteria. If this command is used, external URL is called irrespective of channel and words in the message. While with outgoing webhook, we can apply filters(matching criteria) to call external URL conditionally, whenever criteria matches.
Is there any other difference?
When should we use slash command over outgoing webhook and vice versa?
I want to listen to a particular channel, and sends its data to google sheet when they type "OOO, away, late".
I can create 3 slash commands or can create a outgoing webhook for these three triggering words for this channel.
What is the best approach to accomplish this? I think I should go with out going webhook, considering its capability of matching criteria.
The main difference is how they are triggered.
A slash command is only triggered when a user enters its specific command into a channel, e.g. /who to see members of a channel.
The outgoing webhook automatically sends all message of a channel to a web service or all messages that include a specific trigger word.
However, I would strongly recommend to use Slack events instead of outgoing webhooks for your use case, since the latter is marked as legacy integration. Also events are way more powerful, e.g. they also work in private channels.

Resources