microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

[Skype] Groups: Chatbot responds to any message #1669

Closed tpernice closed 7 years ago

tpernice commented 8 years ago

Hi, I enabled groups conversations on the Skype channel. Expected behaviour is that Chatbot included in group conversation should only respond to messages beginning with "@CHATBOT_NAME", but actually mine is responding to any message. I am using Bot Framework 3.2 with C#.

Best Regards Tom

srozga commented 8 years ago

I disagree. If the bot is part of a group chat, the bot should be able to see all messages, whether someone explicitly said @chatbot_name or not. It should be up to the bot developer to handle the two scenarios. We're run into this exact same scenario and we chose to handle only @chatbot_name messages. Each IMessageActivity has a Conversation.IsGroup property that we key off.

tpernice commented 8 years ago

Hi, Thanks for your comment. Please have a look of Bot Framework documentation (https://docs.botframework.com/en-us/skype/getting-started/#groups). It clearly writes: "A bot can be enabled for groups in the Skype settings for the bot. It can be added to a group chat in the same way as adding a participant to a chat. In a group the bot will only receive messages directly addressed to it e.g. “@YourBot This is the message”. It will not receive other messages sent by group participants or notifications of users joining or leaving the group." This is in contradiction with the scenario you describe. I don't see any indication that this should be managed by the developer in the code, but that it is handled by the Bot Connector itself. Infact this feature was introduced in one of the later versions of Bot Framework. In any case thanks for your hint. I will use it in order to overcome the issue

nickcordrey commented 8 years ago

Skype channel bots should only respond to @ mention so this looks like a bug. Please can you send your bot details to Skype Bot Support skypebotsupport@microsoft.com and we'll look into it. We are working on extending this so that developers can choose private mode or all messages mode.

rjacqu commented 7 years ago

I to am encountering this issue except using node.js bot framework 3.4.4. not doing anything special, except a simple rest api call. I have removed the actual URL for personal reasons.

`var restify = require('restify'); var builder = require('botbuilder'); const roi = require('roi'); //========================================================= // Bot Setup //=========================================================

// Setup Restify Server var server = restify.createServer(); server.listen(process.env.port || process.env.PORT || 3978, function () { console.log('%s listening to %s', server.name, server.url); });

// Create chat bot var connector = new builder.ChatConnector({ appId: process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD }); var bot = new builder.UniversalBot(connector); server.post('/api/messages', connector.listen());

//========================================================= // Bots Dialogs //=========================================================

bot.dialog('/', function (session) { const options = { 'endpoint': 'http://api.temptester.com/v0/define?term=' + session.message.text } roi.get(options) .then(x => session.send("%s", JSON.parse(x.body).list[0].definition)) .catch(e => session.send("Didn't find a definition for: %s ", session.message.text)); });`

nickcordrey commented 7 years ago

Thanks for this we're investigating - I replied to your email to ask for some further details.

tpernice commented 7 years ago

Hi, This is my C# workaround until the bug get fixed . Feel free to suggest a better one.

In async Post method of MessagesController.cs insert the following code

int mentionsNumb = activity.GetMentions().Length;

// THIS SHOULD BECOME A LOOP IN ORDER TO SUPPORT MULTIPLE MENTIONS
  if (mentionsNumb > 0)
   {
          mentionId = activity.GetMentions()[0].Mentioned.Id;
     }

 if ((activity.Conversation.IsGroup != true || mentionId == activity.Recipient.Id))
     {

            // IF CHATBOT MENTIONED, THE STRING BELOW IS INSERTED TO ALL INCOMING MESSAGES SCREWING UP LUIS UNDERSTANDING.
           //  THIS IS WHY I FILTERED OUT
          // REPLACE ID STRING WITH YOUR CHATBOT ONE
             string tmp = activity.Text;
             string textWithoutMention = tmp.Replace(@"<at id=""28:a91f4ea3-7104-4137-b280-e32263bcb153"">@MyBot</at> ", "");
              activity.Text = textWithoutMention;

               await Conversation.SendAsync(activity, () => new LuisDialogHandler());
      }
lee-soft commented 7 years ago

I can't seem to reproduce your bug in C#. I actually want this functionality. I have tried downgrading bot builder frameworks but I still couldn't reproduce the bug. Which version are you using?

soulfly commented 7 years ago

We are working on extending this so that developers can choose private mode or all messages mode.

Would be great to have this feature where chat bot can receive all messages in a group. Do you have any specific plans where this can be available for developers?

toyg commented 7 years ago

@nickcordrey any news on this feature? I'd really like to be able to receive all messages. It's a bit funny that when a bot joins a Skype groupchat, users are alerted that the bot can receive all messages when in fact it's not true. When I explain this to others, it feels like I'm some sort of scammer.

jviksne commented 7 years ago

I was quite disappointed by discovering this "feature" that bots in group chats see only those messages where they are mentioned (I can say that for my Node.js client it works for sure - I don't get messages that do not include the mention). There is no technical justification for such choice as it would be very easy to filter out all the messages that do not include the mentions in case that would be necessary (I can imagine such parameter being easy to be implemented in the framework or in the custom code). While now with this restriction one of my use-cases where the bot would be following the conversion to record and extract the knowledge from the discussion to be able to retrieve it later (with some advanced natural language processing) basically becomes useless (people won't type the mention after each message, or will forget it etc). Is the justification some kind of security concern? If not, I would like to vote to unfix this:)

nickcordrey commented 7 years ago

@toyg please could you email me with your bot ID at Skype Bot Support skypebotsupport@microsoft.com. At this time bots should only be able to receive messages sent to them using at mention. We hope to release an optional setting to have your bot in all messages mode soon.

suja-balan commented 7 years ago

@nickcordrey @tpernice @srozga Hi all, I have created a chat bot application and registered in dev.botframework.com. Also added the bot service to skype and added to contact list. I am facing an issue.This bot is added as contacts by different users in their skype account.But it is not maintaining a separate session for each user.How can i maintain bot contact unique to each user?

soulfly commented 7 years ago

@nickcordrey do you have any updates regarding an optional setting ? I really want to see this checkbox or so. It works this way in Telegram and it's awesome.

tpernice commented 7 years ago

@suja-balan Which language and tecnique are you using to implement the conversation?

suja-balan commented 7 years ago

@tpernice

I have created a bot application in visual studio 2015 and used c# coding language. Also used LUIS template bot service.

tpernice commented 7 years ago

Ok thanks. Which incorrect behaviour are you experiencing related to session?

suja-balan commented 7 years ago

@tpernice Hi I implemented the logic as explained below. I have a static variable count.On each reply from the customer, the count value will get incremented.Based on the count value chatbot will ask next question. For eg: If the count is 1 it will ask "What is your name?" If the count is 2 it will ask"How are you?". If two customers have added my chatbot to their skype contact. The first customer will enter Hi and count will be 1.Then chat bot will reply "What is your name?". Now the second customer will enter Hi here also count should be 1.But in my case, it is 2 since it is updated when the first customer entered hi.

Because it is not maintaining a separate session.How could I solve this?

tpernice commented 7 years ago

@suja-balan Static variables are neither by user or conversation group. In order to store and read a variable at the user level see the sample code below.

Tom

private void SaveData(IDialogContext context, string name, string value) {

        context.UserData.SetValue<string>(name, value);

    }

private string ReadData(IDialogContext context, string name) { string value; context.UserData.TryGetValue(name, out value);

        return value;

    }
suja-balan commented 7 years ago

@tpernice Hi Tom Is this something like a session? Let me try it out once.Thanks for you help

suja-balan commented 7 years ago

@tpernice Hi Tom, I have tried this but facing an issue. I have saved and read the value as you mentioned.But when the value reaches 2 I stopped the solution running in visual studio and again started it now the previous count is retaining.I need to start the count initially when I started it again. Is there any way to do it?

santiagodoldan commented 7 years ago

Are there any news about having a flag to receive all messages or only mentions?

Kisamegr commented 7 years ago

I really need the feature to receive all messages instead of mentions... No updates?

nwhitmont commented 7 years ago

@santiagodoldan @Kisamegr You are commenting on a closed issue.

If you have a question, problem, or feature request, please open a new issue.

nwhitmont commented 6 years ago

relates to #3825

nwhitmont commented 6 years ago

Update 2017-11-27: There are no immediate plans to add this feature.

decadence commented 6 years ago

I need reading all group messages as well

wiradikusuma commented 6 years ago

We need our bot to passively listen to all messages in the group as well. There are valid uses cases for this e.g. bot as fallback for human support.

We're using custom API generated from swagger (we're Java shop), so I believe this behavior is not client-specific.

chinchang commented 6 years ago

Just to confirm here, if I use the same bot-builder bot on a slack channel, it receives all the messages (even ones without mention). Is that intentional? @nwhitmont

wiradikusuma commented 6 years ago

@chinchang this behavior is set by the platform. E.g. on LINE, bots receive all messages in group.

chinchang commented 6 years ago

@wiradikusuma Got it. Thanks!