Search code examples
slackslack-api

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


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?


Solution

  • 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