Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot Framework V4 Human Handoff Middlewareset Issue #42

Open
chinnivyshnavi opened this issue Nov 19, 2018 · 3 comments
Open

Bot Framework V4 Human Handoff Middlewareset Issue #42

chinnivyshnavi opened this issue Nov 19, 2018 · 3 comments

Comments

@chinnivyshnavi
Copy link

Hello,

Please help me
I am a beginner for the Human Handover in the V4 bot framework. I am following the approach of the middleware. Also, I have the LUIS as well added as a service to my bot.
I added the middleware in my Startup.cs file as follows.

services.AddBot(options =>
{
options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);

            // Catches any errors that occur during a conversation turn and logs them to currently
            // configured ILogger.
            ILogger logger = _loggerFactory.CreateLogger<BasicLUISBot>();
            options.OnTurnError = async (context, exception) =>
            {
                logger.LogError($"Exception caught : {exception}");
                await context.SendActivityAsync($"Sorry, it looks like something went wrong. {exception}");
            };
            options.Middleware.Add(new HandoffMiddleware(Configuration));
        });

I am using the Microsoft.Bot.Builder version 4.1.5

My Middleware code is
public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken)
{
Activity activity = context.Activity;

        if (activity.Type is ActivityTypes.Message)
        {               
           
            MessageRouter.StoreConversationReferences(activity);

            AbstractMessageRouterResult messageRouterResult = null;

            // Check the activity for commands
            if (await CommandHandler.HandleCommandAsync(context) == false)
            {                   
                messageRouterResult = await MessageRouter.RouteMessageIfSenderIsConnectedAsync(activity);

                if (messageRouterResult is MessageRoutingResult
                    && (messageRouterResult as MessageRoutingResult).Type == MessageRoutingResultType.NoActionTaken)
                {
                    if (!string.IsNullOrWhiteSpace(activity.Text)
                        && (activity.Text.ToLower() == "human"))
                    {
                        messageRouterResult = MessageRouter.CreateConnectionRequest(
                            MessageRouter.CreateSenderConversationReference(activity),
                            true);
                    }
                    else
                    {
                        // No action taken - this middleware did not consume the activity so let it propagate
                        await next(cancellationToken);
                    }
                }
            }               

When I run the solution in the emulator, the create connection is assigned to "NotSetup" even i connected in two seperate instances in the emlator and during debug I get the following error
image

Please help me here

@chinnivyshnavi
Copy link
Author

@tompaana can you please help me

@hshahbaz
Copy link

@chinnivyshnavi did you find a solution for this? I have a bot on .NET core that is using LUIS and QnA Maker. The last thing I want to add is to implement bot to human handoff by opening a channel in MSTeams.

@tompaana implementation works great with the hand off I want to do but I want to integrate this in my code. I wonder if you have used his classes and could point me in the right direction.

@gauravanandwhiz
Copy link

gauravanandwhiz commented Sep 25, 2020

@chinnivyshnavi, @hshahbaz did you manage to integrate the Agent HandOff with your code?
The IntermediatorBot code works fine in isolation but, when I integrated my code(which latest version packages), the HandoffMiddleware.OnTurnAsync(...) doesn't get triggered as my code has a Controller / ApiController class as follows.

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;

namespace Yoda.Controllers
{
    // This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
    // implementation at runtime. Multiple different IBot implementations running at different endpoints can be
    // achieved by specifying a more specific type for the bot constructor argument.
    [Route("api/messages")]
    [ApiController]
    public class BotController : ControllerBase
    {
        private readonly IBotFrameworkHttpAdapter Adapter;
        private readonly IBot Bot;

        public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
        {
            Adapter = adapter;
            Bot = bot;
        }

        [HttpPost, HttpGet]
        public async Task PostAsync()
        {
            // Delegate the processing of the HTTP POST to the adapter.
            // The adapter will invoke the bot.
            await Adapter.ProcessAsync(Request, Response, Bot);
        }
    }
}

Would appreciate if you could share whether, you could manage to integrate your code with the IntermediatorBot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants