Can an slack app reply to the person who mentioned me in a channel? - slack

I am looking to build a slack app which can auto-reply to a person whenever they mention me in a channel or DM me. However, i cannot find any method in the slack API for the same.
Is there any particular way i am missing or this cannot be done in Slack?

When you say 'mention me', if you mean the bot,
then you can subscribe to 'app_mention' event and take it from there.
https://api.slack.com/events/app_mention
If you mean - you as user and not the bot, then the bot needs to be part of the conversation to read the messages. This means that it will not work with the DMs.
For channels, you can invite the bot to the channel you want to monitor, and capture the 'message' event to parse the message and look for your id.
https://api.slack.com/events/message

Related

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 make Trigger Action by Reaction Posted on MS Teams

I am making bot works for Microsoft Teams.
Goal: To make bot to detect reaction posted for any messages in the user's MS teams channel.
Problems:
Using onReactionsAdded in activityhandler(MS BotFramework) , my bot detects the reaction posted only for the bot messages
Is there any possible way to make trigger action by posting reaction for users' posts in MS Teams?
This is similar to the fact that you Bot won't receive every single message posted in the channel / group chat - only those that "#mention" your bot. It's different in a 1-1 chat with the bot though - there it will receive everything. If you want to make sure you get every single reaction, you'd need to call the Graph for that. See Get a reply to a channel message as an example - right near the bottom of the page it shows "reactions" (it's empty in that example).
#Cambria a Bot receive's the reactionAdded event only when there is a reaction on a message the Bot itself posted. Reacting on a user's post does not trigger an event with the Bot.

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.

How to make Slack Bot not respond to all the messages in the private group?

I want my bot to respond only if anyone mentions its name like #mybot.
How to achieve this?
For that you need to use the Events API and subscribe to the event app_metion.
That way your app will receive all message that directly mention your bot with #mybot.
Those messages will be sent as request from Slack to the endpoint provided for receiving events.

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