Skip to content Skip to sidebar Skip to footer

How To Make Slackbot Reply If The Message Starts Only With A Tag

so I'm finishing programming a cool slackbot with Nodejs. But i would like the bot to answer only if the command begins with a tag followed by the botname, for example: @joe greet

Solution 1:

A very elegant solution for this problem is to use the Events API and subscribe to the app_mention event. Then your bot will only receive message events when he is explicitly mentioned in a channel, e.g. @my_bot hi.

In addition to you may also want to subscribe to the message.im event, so you can react to direct messages from users.

Solution 2:

Have you tried regular expressions? perhaps something like

var command = msg.toLowerCase().match(/^@joe (.*)/)[1] 

to capture the message in the first group

Post a Comment for "How To Make Slackbot Reply If The Message Starts Only With A Tag"