0
votes

I would like to know how can I redirect a user's message to a person, instead of having that message be processed by the bot. Here's how I would like to have everything working, assuming a situation where a customer is talking with a bot that belongs to a company:

The user starts a conversation with the bot.

  • The bot gives the user the option to speak with a representative.

  • From now on the messages from the user are redirected to the representative (behind another software).

  • Representative responds the messages, they are forwared to the user.

I have given some thought on how I could be able to achieve this, and so far I haven't made much progress. The part where I redirect the user messages to another place seems rather easy, since after the user says he wants to talk to a person I put a flag on it's UserData that I use to redirect his messages somewhere else.

Example:

Inside the dialog, here's the LUIS Intent where I set the flag on the UserData:

[LuisIntent("SpeakWithEmployee")]
public async Task IntentSpeakWithEployee(IDialogContext context, LuisResult result)
{
    await context.PostAsync("This conversation will be redirected to a employee.");
    context.UserData.SetValue<bool>("RedirectToEmployee", true);
}

Now on the MessagesController here's how I'm doing to redirect the user's message:

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
    if (activity.Type == ActivityTypes.Message)
    {
        StateClient state = activity.GetStateClient();
        BotData botData = state.BotState.GetUserData(activity.ChannelId, activity.From.Id);
        bool redirectToEmployee = botData.GetProperty<bool>("RedirectToEmployee");

        if (redirectToEmployee)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
            Activity reply = activity.CreateReply();
            reply.Text = $"Echoe: {activity.Text}";
            await connector.Conversations.ReplyToActivityAsync(reply);
        }
        else
        {
            await Conversation.SendAsync(activity, () => new RootDialog());
        }
    }
    else
    {
        HandleSystemMessage(activity);
    }
    var response = Request.CreateResponse(HttpStatusCode.OK);
    return response;
}

That seems like the easy part. My problem is to figure out the part where the employee replies to the user. I have no idea on how to implement this next part.

I will need to use the DirectLine API in order to allow the Employee to reply to the user, right? On the software the employee is runnig I think I'll have to send a POST message to the bot's endpoint, is that right?

I also need to store the user Id, activity Id and information like that in order to allow message from the employee to go to the right user. However when the software used by the employee sents a POST to the bot's endpoint the POST will have to contain an activity?

Anyway, any idea on how this could be done?

1

1 Answers

0
votes

Yes, BotFramework can.

Basically, you must have two channels or chats to test it. One is where the representative register him as it role and keep open waiting someone to chat. In the other channel, you have your customer that will be attempted by the bot until the bot reach its limit of usability or the customer ask to speak with a human. In this last moment, you connect the two people and the bot. The customer send a message, the bot receives it and send it to the representative. The representative send back the response and the bot send it to the customer. There is not really big deal in this.

You can evolve this idea taking care about the representative status (free to chat or in a conversation).

The technical key point of this, is store the representative and customer data (channel data, user data, conversation data) to be able to send the responses.