-3

I have bot made using framework v4 using c#. I have integrated luis in it for exit feature, in my bot when ever user type exit it will take you out from the conversation and the entire bot will start from beinging. I my case bot is able to exit but not able to start from beinging. I thought i can use CancelallDialogAsync method but i am not able make it accessible in onturnasync method where i have written code for exit feature.

public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        var activity = turnContext.Activity;
       // var activity = turnContext.Activity;
        var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);

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

        var attachments = new List<Attachment>();
        var reply = MessageFactory.Attachment(attachments);
        reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;


        // First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.

        if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
        {
            activity.Text = JsonConvert.SerializeObject(activity.Value);
        }
        if (turnContext.Activity.Text == "Yes")
        {

            await turnContext.SendActivityAsync($"Good bye. I will be here if you need me. ", cancellationToken: cancellationToken);
            await turnContext.SendActivityAsync($"Say Hi to wake me up.", cancellationToken: cancellationToken);
        }
        else  if (topIntent.intent == "OrderStatusintent")
            {
                reply.Attachments.Add(Cards.GetHeroCard6().ToAttachment());
                await turnContext.SendActivityAsync(reply, cancellationToken);
            }
        else if (topIntent.intent == "Exitintent")
        {
            await turnContext.SendActivityAsync($"Good bye. Say Hi if you need more help.", cancellationToken: cancellationToken);

        }

        else if (activity.ChannelId != "webchat")
        {
            await base.OnTurnAsync(turnContext, cancellationToken);
        }
        await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
        await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
    }
  • I've not done this, but sounds like you could use proactive messaging and a timer-based function to achieve this. Someone may have a template they have used for this, but you will have more luck with getting a response if you can try out a solution and then let us know what difficulties you are having in implementing it. – billoverton Jan 27 '20 at 12:47

1 Answers1

0

I'm having a bit of a hard time following your bot function, but I believe you need a dialog context. My bot structure is different than yours, but I have an onMessage function which calls my intent dispatcher and passes the turnContext. I am using DialogSet (from botbuilder-dialogs) to create the dialog context via (nodejs)

this.dialogs = new DialogSet(this.dialogState) // in constructor

const dc = await this.dialogs.createContext(turnContext) // in function called from onMessage

await dc.cancelAllDialogs(); // from wherever I want to cancel

I don't see anywhere where you have created a dialog context, so that may be why you are unable to call this method from your onTurn handler. It may be possible, but everywhere I call cancelAllDialogs() it's either from this dialog context, or from within a waterfall dialog I'm using the step context and cancelling at the parent level via stepContext.parent.cancelAllDialogs().

billoverton
  • 2,705
  • 2
  • 9
  • 32