Ignore weak changes in the room, but not directly to the bot

I have a bot using botkit. I want to give a warning message that edited messages are ignored when you speak directly to the bot, so I do:

controller.on('message_changed', function(bot, message) { bot.reply(message, ":warning: Your edit was ignored."); }); 

The bot is in a room with many people so that these people can "access" the bot privately.

Problem . When someone edits a message in the room, the bot sends a warning. What is the best way to avoid this?

I hope to avoid hard-coding the identifier of the room in the room that the bot should not respond to, since we may have a bot in other rooms.

+6
source share
1 answer

You can check the message channel to see if it is "direct_message" or not if the channel starts with D. If it starts with D, it was a direct message that is being edited. Something like this should work.

 controller.on('message_changed', function(bot, message) { if (message.channel.match(/^D/)) { bot.reply(message, ":warning: Your edit was ignored."); } }); 

Also, if you want this to work in chat rooms where the user directly sends a message to the bot, you can check the message text to see if it starts with @yourBotsName

+3
source

All Articles