How can I get my bot to ignore conversation until it is addressed directly?

前端 未结 4 712
遇见更好的自我
遇见更好的自我 2021-01-26 08:57

I want to add my bot to a Slack channel. But I want it to ignore conversation until it is addressed directly, e.g.:

me: hi!
me: hi!
me: @bot hi!
bot: why hello t         


        
4条回答
  •  情书的邮戳
    2021-01-26 09:46

    While checking the activity text is certainly a valid option, I would instead use the Mentions capabilities provided by the library (at least in C#).

    if (activity.GetMentions().Any(x => x.Mentioned.Name == "botName") 
    {
      ...
    }
    

    IMessageActivity has a list of Entities. One of the possible entities coming in that list is the Mention entity.

    The GetMentions() method is just a filtering the list of entities to retrieve the ones of type "mention".

    Update

    Just realized that you were asking for Node.js. The Entities approach is still valid, as you can see in the Node.js docs. You can use session.message.entities.

提交回复
热议问题