2

`namespace Microsoft.BotBuilderSamples { public class DispatchBot : ActivityHandler { private ILogger _logger; private IBotServices _botServices;

    public DispatchBot(IBotServices botServices, ILogger<DispatchBot> logger)
    {
        _logger = logger;
        _botServices = botServices;
    }

    protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        // First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
        var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);

        // Top intent tell us which cognitive service to use.
        var topIntent = recognizerResult.GetTopScoringIntent();

        // Next, we call the dispatcher with the top intent.
        await DispatchToTopIntentAsync(turnContext, topIntent.intent, recognizerResult, cancellationToken);
    }

    protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
    {
        const string WelcomeText = "I am here to make your bot experience much more easier";

        foreach (var member in membersAdded)
        {
            if (member.Id != turnContext.Activity.Recipient.Id)
            {
                await turnContext.SendActivityAsync(MessageFactory.Text($"Hi {member.Name}, I am your IT assistant at your service . {WelcomeText}"), cancellationToken);
            }
        }
    }

    private async Task DispatchToTopIntentAsync(ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
    {
        switch (intent)
        {
            case "l_us_bot":
                await ProcessHomeAutomationAsync(turnContext, recognizerResult.Properties["luisResult"] as LuisResult, cancellationToken);
                break;

            case "t_abs-bot":
                await ProcessSampleQnAAsync(turnContext, cancellationToken);
                break;
            default:
                _logger.LogInformation($"Dispatch unrecognized intent: {intent}.");
                await turnContext.SendActivityAsync(MessageFactory.Text($"Dispatch unrecognized intent: {intent}."), cancellationToken);
                break;
        }
    }
    private Activity CreateResponse(IActivity activity, Attachment attachment)
    {
        var response = ((Activity)activity).CreateReply();
        response.Attachments = new List<Attachment>() { attachment };
        return response;
    }

    private async Task ProcessHomeAutomationAsync(ITurnContext<IMessageActivity> turnContext, LuisResult luisResult, CancellationToken cancellationToken)
    {
        _logger.LogInformation("ProcessHomeAutomationAsync");

        // Retrieve LUIS result for Process Automation.
        var result = luisResult.ConnectedServiceResult;

        var topIntent = result.TopScoringIntent.Intent;
        var entity = result.Entities;


        if (topIntent == "welcome")
        {
            await turnContext.SendActivityAsync(MessageFactory.Text("Hi,This is your IT assistant"), cancellationToken);
        }
        if (topIntent == "None")
        {
            await turnContext.SendActivityAsync(MessageFactory.Text("Sorry I didnt get you!"), cancellationToken);
        }

        if (topIntent == "DateTenure")
        {
          // Here i want to call my dialog class
            }

        }



    }



    private async Task ProcessSampleQnAAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        _logger.LogInformation("ProcessSampleQnAAsync");

        var results = await _botServices.SampleQnA.GetAnswersAsync(turnContext);
        if (results.Any())
        {
            await turnContext.SendActivityAsync(MessageFactory.Text(results.First().Answer), cancellationToken);
        }
        else
        {
            await turnContext.SendActivityAsync(MessageFactory.Text("Sorry, could not find an answer in the Q and A system."), cancellationToken);
        }
    }


}

`I have a scenario as described: When user says hi, the bot shows the adaptive cards (with Action.Submit on each card). ----Suppose the cards are as: 1. Book tickets 2. Need Help
3. Cancel whenever user click any of the option ,i get the same user clicked value. Like

  1. If the user selects "Need help". I get the same value..

  2. then i am getting input from user like any question(query).

  3. Then this query will go to the specific intent from dispatcher but its not going to intent from dispatcher and showing error (object reference not set to an instance of an object)

so what should i do?

for reference i already gone through this link "How to retrieve user entered input in adaptive card to the c# code and how to call next intent on submit button click"

it should take value from the dispatcher bot after user input.

rahul jha
  • 21
  • 2
  • You should add some code showing what you have already done so we can help. Just from your description is very hard to get what you are asking for. – guzmonne Aug 08 '19 at 12:58
  • I have uploaded my sample code on github (https://github.com/rahuljha819/jharahul/blob/master/FinalBot.zip) Whenever user selects : Need Help Bot provides a prompt for user to type its question, upon getting that question it should get passed to the dispatcher and get result from there. Similarly if user selects "Book Flight", bot gives a prompt to get the details of flight which goes to dispactcher from where the BookingDialog gets called (This I have no idea how to implement) And for Cancel: it will ask yes or no on Yes it should pass to cancelandhelpdialog) – rahul jha Aug 09 '19 at 04:25
  • yeah, no one is gonna unzip a file, even if it's on Github. Please update your questions to INCLUDE the relevant code. Please refer to this: https://stackoverflow.com/help/how-to-ask – JJ_Wailes Aug 09 '19 at 16:25
  • 1
    i have edited my question also added code please go through it and help me in getting the intent from the dispatcher. – rahul jha Aug 12 '19 at 08:58
  • Card are handled differently in each channel. What channel are you trying to use? – JJ_Wailes Aug 20 '19 at 19:55
  • I am using direct line channel. – rahul jha Aug 29 '19 at 12:43

0 Answers0