botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Transfer the chat control to a human chat executive.

Open Ani110591 opened this issue 10 years ago • 15 comments

I read a lot about chatbots, and am in the process of implementing a chat bot which can search information within the website and return the user a relevant set of listing results. But till the bot is completely trained, I would like to have in place a transfer of control of the chat from the bot to a human executive to answer the queries manually. Is such a transfer possible with the Bot Builder framework. I've gone through the documentation but could not find any such an implementation possible. Is it possible? Has it been done anywhere.

Ani110591 avatar Aug 29 '16 11:08 Ani110591

I think the Bot Builder itself doesn't have any utilities helping with this. You could store a flag in the bot state service indicating whether the bot or the human is in control. If it is the bot, start (resume) the dialog; if it is the human, start your custom logic connecting the user to this human agent.

Thegaram avatar Aug 29 '16 17:08 Thegaram

Hi, I'm having the same scenario. What I did was using a predicate to determine whether the bot should answer or not. The predicate is currently a boolean flag stored in the bot data but it's meant to evolve to depend on the online status of our human assistants and availability in outlook cals. The point is you want full control of this predicate yourself as it can get very domain specific.

Secondly, I stored all incoming message activities as full json in a persistent storage (we use azure table storage). This allows you to use the ConnectorClient to always be able to send replies from an assistant: new ConnectorClient(serviceUrlFromMessageToReplyTo).Conversations.ReplyToActivityAsync(reply)

We do not use the built in form states so I don't know how this affects form flows.

One of our concerns of this approach is if conversations "die" in the connector service. Then replies won't be sent due to conversation 404.

@Thegaram Do you know how / when conversations expire? And can the bot keep conversations alive for a long time (weeks) by pinging them regularly?

rzmoz avatar Aug 30 '16 04:08 rzmoz

@rzmoz. I think pinging continuously might not be a good solution as the messenger channel might be active but the user might have left the chat. There can be a timeout mechanism implemented but it night seem more brute force than an actual solution.

Ani110591 avatar Aug 30 '16 05:08 Ani110591

@rzmoz I remember something like 20 minutes from V1 (i.e. inactive conversations will expire after this time interval). I haven't found anything like this in the new docs though. Have you experienced problems with this yourself?

Some channels support the GetMembers action (see the REST API docs). You can check if there are other members in addition to your bot and ping the conversation in that case.

Thegaram avatar Aug 30 '16 17:08 Thegaram

@Thegaram I realized it's supposed to be the client that keeps the conversation alive. So I assume there's a sliding window expiration cause that seems to work. For example, the webchat client long polls the conversation for messages as long as the window is open (thus conversation is active)

Thanks, makes sense

rzmoz avatar Aug 31 '16 02:08 rzmoz

Hi all, most of what's in the thread is correct but I wanted to clarify one thing.

In the Bot Framework, conversations don't have a fixed expiration and they don't expire the same way across channels. Web Chat conversations are fairly ephemeral, whereas SMS conversations (which are identified by two phone numbers) don't have a fixed start or end. In most cases, the client is not involved in determining the conversation lifetime.

However, you can add your own conversation data expiration by just adding an expiration timestamp to any records you store. This allows you to flush the data if it's sufficiently stale.

dandriscoll avatar Sep 14 '16 03:09 dandriscoll

Closing for now. Feel free to open another issue if you have a related question.

dandriscoll avatar Sep 18 '16 02:09 dandriscoll

Hi @dandriscoll, I'm with you on the general concepts of conversations but part of this conversation is about the technical implementation in the Bot Framework. For our scenario - its strictly sms via directline, We do pass the conversation control to the human assistant but our concern is not regarding how to flush stale conversations but how to keep conversations open / active - specifically in the direct line channel since this it what is used for custom channels.

Our MVP scenario for our bot is not to answer intelligently but to mimic interaction 24/7. So, lets say we get a customer who sends an sms, then we'd like to reply with something basic as "thanks for your request, we will get back to you soon". Then, when the human assistant comes back, he will make a more through reply. The issue is that this can be several days later (lets say the customer contacts us Friday 9PM and the human assistant doesn't meet in until Monday morning). If the technical conversation in directline line is closed by then, then the bot will get a 404 when replying to the conversation thus the customer will never receive the reply.

Hopes this clarifies our concerns. All scenarios on the demoes revolve around short term conversations such as pizza orders etc. Our logic conversations can span weeks and replies can sometimes span days but we're happy to re-use the same technical conversation forever as long as we can get in contact with our customer.

Hope it clarifies our scenario

rzmoz avatar Sep 19 '16 02:09 rzmoz

Direct Line is unique in that it does not have a user directory, so it's technically not possible to reach out to an existing user to initiate a new conversation.

Some options:

  1. You could create an out-of-band protocol where you notify the client that it has a new message waiting in an existing Direct Line conversation. This allows you to work around the lack of a directory.
  2. You could use a channel like Twilio for SMS.
  3. Direct Line clients could keep their conversations open for very long periods.

dandriscoll avatar Sep 19 '16 02:09 dandriscoll

Hi, thanks for the quick reply.

In our case, the user always initiate the conversation (creates a new conversation) so it's okay to have the conversation stay open.

From the top of my head:

  1. circumventing the bot framework seems to defeat the purpose of the bot framework?
  2. we can't use Twilio yet cause they don't support incoming texts in Denmark (checked 2 months ago)
  3. yes, that's our current approach which required us to create custom logic for this. So, when a client contacts us, we store the conversation id on our sms mediatorclient service and keep pinging the conversation to keep it open and to listen for new messages.

It seems to me you confirmed our current approach which is to ensure that the client keeps the conversation open?

rzmoz avatar Sep 19 '16 02:09 rzmoz

Yep, that's probably the best approach.

dandriscoll avatar Sep 19 '16 02:09 dandriscoll

It looks like this was taken care of, please reopen if needed. Thanks!

Andrea-Orimoto avatar Sep 30 '16 21:09 Andrea-Orimoto

I came across this implementation of a ResumptionCookie class within Bot Framework documentation. https://docs.botframework.com/en-us/csharp/builder/sdkreference/dc/d2b/class_microsoft_1_1_bot_1_1_builder_1_1_dialogs_1_1_resumption_cookie.html Will this be of any relevance here ?

Ani110591 avatar Oct 13 '16 12:10 Ani110591

Hi @Ani110591 For my scenario, the cookie seems to contain a subset of the activity (information the bot already have) but the issue lies in keeping the state of this cookie. the bot needs to persist the cookie bot-side in order to be able to resume the conversation later and the client needs to keep the conversation open from the client-side. The issue is thus the keeping the cookie state rather than the cookie itself.

I persist the whole activity object since it allows me to pull up old conversations if needed so I don't have a need for the cookie (activity subset)

Maybe it can suit your scenario?

rzmoz avatar Oct 19 '16 03:10 rzmoz

Some guy gives a good answer about how to tackle this, but never says anything about implementation and expiracy of conversations. Here

So I am in this scenario:

  • Some users use the bot via Skype. These users asks questions to the bot. When the bot is not able to answer any of those questions, a conversation between the user and a customer representative/expert starts.

  • Just for testing if this works, what I did was:

    1. Created a simple bot and have it running over ngrok.
    2. Created a simple Console App and have it running locally. This apps connects to the previous bot via DirectLine.
    3. Whenever a user sends a message via Skype, I want to broadcast it to the ConsoleApp, via DirectLine.

Is this possible?

What I did for testing was getting the ConversationID of the ConsoleApp interaction with the bot, and tried this code snippet:

var userAccount = new ChannelAccount("ID_OF_THE_CONVERSATION_BETWEEN_CSI_AND_BOT");
var botAccount = context.Activity.Recipient;
var connector = new ConnectorClient(new Uri(context.Activity.ServiceUrl));
var conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount); //botAccount now is the sender, userAccount (CS) is now the recipent.
IMessageActivity messageToSend = Activity.CreateMessageActivity();
messageToSend.From = botAccount;
messageToSend.Recipient = userAccount;
messageToSend.Conversation = new ConversationAccount(id: conversationId.Id);
messageToSend.Text = message.Text;
messageToSend.Locale = "en-Us";
await connector.Conversations.SendToConversationAsync((Activity)message);

But the DirectLine Console Application is not receiving the message. Is it possible that the ConversationId (ID_OF_THE_CONVERSATION_BETWEEN_CSI_AND_BOT) changes?

Thanks

piffarettig avatar Jan 25 '17 19:01 piffarettig