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

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.

Related

Slack event message.im not being triggered

I'm trying to get the event to be triggered when someone sends a message on a private conversation in slack, I've already registered the event subscription (message.im) in the subscribe to bot events section, made sure that the needed scope was added (im:history), and reinstalled the app on my workspace.
Also tried signing out of the workspace and logging in again.
Yet, even if it is the admin sending a message to a user or a user sending a message to the admin (or in any other case with other users) the Event is not being triggered.
Any help or suggestion of why could this be happening?
Thanks!
You receive this event when a user sends a direct message to your bot/app.
You wouldn't receive this event when a user sends a message to another user, because the bot is not a part of that conversation.

What happens to the activity if my end point is not accessible or returns a 500?

I have a Microsoft bot app that can be installed in Teams on a team.
For now, I save the tenant ID + team id in our DB when the app gets installed, via a received activity on our end point.
What happens if my prod is not up at the moment of the installation? (for whatever reason, could be an update or just a technical downtime...)
Is it lost forever? Is it retried?
Same question with a 500 error?
This activity is an example, it could be any other activity. Ex: a user is added/removed, a message has been sent etc...
For OnMembersAddedAsync; unfortunately there is no retry from the Teams side, it fires and forgets.
The information in that Activity will be included in any subsequent send from Teams - so the bot can recover, if the user interacts with the bot again. Messages would just be sent when the bot recovers.
You can find a bit more info on Teams and events here:
How do I send a 1:1 welcome message?

Slack App API - Can I subscribe to and monitor all #username mentions for the current user?

When someone mentions a specific username by their handle in Slack, the user typically gets notified about that mention by Slack. I would like to make a Slack app that subscribes to those notifications for the current user. Any time a user gets notified that they were directly mentioned, I'd like to be informed of that in my app, along with the contents of that message.
I've looked through the API docs for quite a while and I can't seem to find support for this functionality. Am I missing something? Can this be done?
There is no event in the Slack Event API that handles mentions of users (although if you create a slack bot you can handle mentions of the slack bot's user with the app_mention event).
You can still listen for the message event and manually look through the text for any #UserMentions and handle them there. Note that this will only work for channels that the Slackbot has been granted access to.

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.

Proactive Interruptions

I am using an Azure Function to send a Proactive message to the client. How do i "reset" a conversation when a Proactive message is sent.
Within the bot, a user might be prompted for something (ex. time of day). A proactive message may get sent to them before they respond. In this scenario, I would like to reset/cancel the previous dialog and start fresh.
I am already able to reset the dialog using CancelAllDialogsAsync which works fine for user-driven messages.
I am sending my proactive message using ConnectorClient, which bypasses the framework, and sends directly to the client, thus never hitting my middleware to reset the dialog.
How can I get the proactive message sent to the framework (i can send the response from the bot no problem)
I would highly recommend you solve this by having your function send your bot a backchannel event under the context of the ConversationReference via the ConnectorClient. This way the bot maintains ownership for all the details about state and what should happen when this event occurs rather than that responsibility leaking to the function. The bot then watches for this custom event and responds to it however it sees fit.
If you need any more details let me know and I'll update my answer.

Resources