Unable to get timestamp of the message posted by Slack App - slack

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.

Related

How to add my slack bot's message to a user's message?

Here's what I need,
A user sends a message, and my slack bot return a message that should be attached to the specific user, whose message I processed.
The image below explains it clearly, the user named Changming sends a message in Chinese, and then the slack app attaches it's translation in English, to the original message. How can I do that?
Until now, I've been able to send a block in a message, but I don't know how to attach it to the original message.
As the problem occurs, if there are multiple messages being sent in a single second, then the bot's messaged will not be in the correct position, as the bot will also take certain amount of time in processing and sending the messages back to slack.

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.

Gmail API push notification duplicate message ids

I am using Gmail push notifications for email processing. When I receive a message notification from Google, I use the history list API with the previously stored historyId and can see new messages using messagesAdded. Once I have retrieved the messages, I store the last historyId for the next request.
When testing, if I send two mail messages (about 30 seconds apart) to the watched mailbox, I see two messages notifications from Google and when I call the history API for each of the notifications I see the message ids. This is all good.
If I repeat the same test but send the two mail messages immediately after each other, I get the two notifications from Google but when I call the history API for the first message, I get the two message ids in that history API call. When I call the history API call for the second notification, I get a duplicate of the last message id.
How can I prevent seeing duplicate message ids in this scenario? Any help or pointers would be much appreciated.
Updated: Added request and response example for second test.
I noticed in the response from the Google History API a historyId showing the latest messages that have been processed. If I store this value as the next start point instead of the historyId sent in the notification message, it works around the duplicate issue as on the second request there are no more messages. Not sure if this is the right way to do this as it means I don't store or use the historyId sent in the notification message.

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.
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.

How do I receive only the messages that are direct messages to my bot user?

I have successfully setup my slack bot app, have enabled events etc. I want to receive any direct messages that the members of my slack team send to my bot. For this, I have only enabled Bot Events and No Team Events like below
However, I do not get any event on my webhook on this setting.
If I enable message.im event under Team Events, then I start getting events. But then, I get every message that the user (who has installed the app) sends to any other user in the team.
How do I get only the messages that are sent to my bot user?
Update 1
Based on this SO question I created a private channel with the bot user. Even then, the messages in the private channel do not arrive in my webhook with the above event subscriptions.
Update 2
After reinstalling the app, it seems to be working fine. I have only used it for few minutes after the reinstall so far. I will keep posting here how it goes. It would still be interesting to know what went wrong where.
It is normal behavior that your script receives all messages (for every channel your bot is a member of), not only the messages sent directly to your bot. At this time you can not filter further in the event configuration. So you need to filter out any unwanted message in your script handling the event.
See also this answer.

Resources