Kabir Pathak
Kabir Pathak

Reputation: 83

How can i make my slack bot read all messages ( and not just app_mention) in a particular channel?

I'm currently creating a slack bot that reads messages from a slack channel and then parses the message.

I have successfully created this using app_mention. But the problem now is that only the messages that mention my bot are being read by the bot.

I would like my bot to read and respond to All messages inside a particular channel.

Current code :

//listen to messages
const slackEvents = createEventAdapter(slackSigningSecret);
//post messages
const slackClient = new WebClient(slackToken);

//all messages 
slackEvents.on('message', (event) => {
    console.log('This is not working. Please help!');
});

//when the bot is mentioned
slackEvents.on('app_mention', (event) => {
    console.log('This is working.);

My code slackEvents.on('app_mention', (event) => () is working perfectly. However, the slackEvents.on('message', (event) => () is not working.

I have added all the scopes that i thought were required for this. channels:history, groups:history, but still nothing happens.

How can i make the bot listen to all the messages in a particular channel? Please help!

Upvotes: 2

Views: 4877

Answers (2)

Anshit Bansal
Anshit Bansal

Reputation: 1

Adding to the above answer -

You can use message event to subscribe to all the messages sent in a channel.

For this you'll need:

  1. Scopes channels:history (public channel) groups:history (private channel)
  2. Subscribe to the event You need to subscribe to "message.channels" event under Subscribe to events on behalf of users if you want to trigger event for every message sent by any user.

Invite the bot to the channel

This worked for me.

Upvotes: 0

Suyash Gaur
Suyash Gaur

Reputation: 2881

You can use message event to subscribe to all the messages sent in a channel.

For this you'll need:

  1. Scopes
    channels:history (public channel)
    groups:history (private channel)
  2. Subscribe to the event
  3. Invite the bot to the channel

If configured properly, you'll receive event whenever a message is posted in the channel.

Upvotes: 4

Related Questions