1

I'm writing a BotFramework bot, and have integrated it with Slack and Teams and in 1-to-1 chats it's working quite nicely.

I'd like to have it work in a group channel as well, but I don't want it to respond to every comment (as most responses would be "I didn't understand the question") - I'm using a Luis Dialog along with a FormFlow form and some Prompts.

I initially tried the following setup within my MessagesController Post method:

if (questionIsToMe(activity))
{
  await Conversation.SendAsync(activity, () => new OctopusLuisDialog());
}

with the questionIsToMe defined as:

private bool questionIsToMe(Activity activity)
{
  // IsGroup is null => 1-1 conversation with non-group capable client
  // IsGroup is False => 1-1 conversation within group capable client
  // IsGroup is True AND message starts with OctoBot => group conversation with question 
  // to me
  return !activity.Conversation.IsGroup.HasValue ||
         !activity.Conversation.IsGroup.Value ||
         (activity.Conversation.IsGroup.Value &&
         activity.Text.StartsWith("OctoBot", StringComparison.InvariantCultureIgnoreCase));
    }

Which works for most of the intents fairly well, but causes problems when the user is responding to the FormFlow or Prompts - as I need to include "Octobot" in the response to send the value, which I can strip out of my FormFlow, but the prompts all fail with my fallback text.

How can I distinguish between normal channel chatter and responses to my bots questions?

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117

2 Answers2

2

If the bot is @mentioned it will show up in the Entities field of the Activity.

activity.Entities.Items[0] = {{ "mentioned": { "id": "{your bot slack id}", "name": "{your bot name}" }, "text": "@{your bot name}" }}

Lars
  • 9,976
  • 4
  • 34
  • 40
  • What's the best way of mentioning it within a form flow response though? – Zhaph - Ben Duguid Nov 23 '16 at 18:40
  • 3
    Valid point. I see your problem. The Prompt and FormFlow are still problematic as the @ mention is included in the returned text. Let me think about the best way to address this. The BF could strip prefixed @ mentions from the returned text but this could break other users that are detecting @ mentions via text parsing rather than by checking the entity list. – Lars Nov 23 '16 at 19:29
  • Yes, I've worked on it through my form flow as I'm accepting free text throughout, but prompts aren't there. I think I might be able to do something with the usertobot and bottouser bits... – Zhaph - Ben Duguid Nov 23 '16 at 19:44
0

There is no way of knowing when a message is directed to your bot. You can try to:

  • only respond to messages when it knows the answer
  • respond only when the message includes the name of the bot
Bouke Stam
  • 79
  • 3