Not receiving notifications in thread when sending messages as bot - slack

I am facing a weird bug when using my bot app to send messages in a thread.
I am sending DMs as a bot app user - the message will appear in the app channel.
When I send the first message, I get a notification from this message (right).
I get the thread ts, and then send a message again as a bot, replying in a thread. I receive the message in the channel, as a thread, but I don't get any notification.
Next I reply it as the user receiving this DM - works ok
Then, from the moment I reply to this thread, after the first interaction from the user, I start to get notifications from my own bot messages.
The issue? I'd like to get notifications from the start, doesn't matter if the user interacted with me in this thread or not. Any way to do it?
Thanks!
I am using https://slack.com/api/chat.postMessage to do it all.

Related

How to trigger a Slack Workflow when someone sends a message

How do you trigger a Slack Workflow when someone sends a message? I want to react to a person sending a message, preferably try to read the message they sent and respond back with some helpful links as a thread automatically.

Is it possible for a Slack bot to listen to user #-mention events?

In Slack, users are pinged when they are #-mentioned in a channel. Is it possible for a bot or app to receive an event when a user is tagged this way? It doesn't seem to be on the Event Types API.
The app_mention event is meant to handle just this scenario.
Any time a message references your app by its bot username (e.g. #myBot), your app will receive this event along with metadata like the user ID who wrote the message, the text of the message, timestamp, and channel ID.

How to get a welcome message on teams even before user sends any message

I have deployed my bot on teams channel.
I would like to send a welcome message to a new user even before user sends a message to the bot.
can we achieve this for teams channel?
If yes, which event can be used to get that user is accessing bot for the first time.
You can use the ConversationUpdate event ActivityTypes.ConversationUpdate // in c#
When a bot is installed, your bot receives a conversationUpdate event. You can then send a proactive message to the user. Could you please try sending a proactive message and let us know if you face any issues?
The conversationUpdate event with the membersAdded object in the payload is sent when either a bot is added to a team or a new user is added to a team where a bot has been added. It is always a good practice to send a welcome message introducing the bot to all the users. Ensure that your bot responds to the conversationUpdate message, with the teamsAddMembers eventType in the channelData object. Also, keep in mind that the memberAdded ID is the bot's App ID itself, because the same event is sent when a user is added to a team.
Hope this helps.

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.

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