简体   繁体   中英

Bot Framework 4.0 Equivalent

I am building a bot, but I am having issues with Bot Framework 4.0. What is the equivalent code to the snippet below in Bot Framework 4.0?

I am having trouble finding applicable code snippets for my problem. I am trying to call a dialog from my bot class, but I can only find applicable code from Bot Framework 3.0. The code snippet is below:

if (entry)
            {
                JToken commandToken = JToken.Parse(turnContext.Activity.Value.ToString());
                string temp = turnContext.Activity.Value.ToString();
                Logger.LogInformation(temp);
                string command = commandToken["action"].Value<string>();

                if (command.ToLowerInvariant() == "purchaseorder")
                {
                    //call PurchaseOrderDialog
                }
                else if (command.ToLowerInvariant() == "sku")
                {
                    //call SKUNumberDialog
                }

            }

I am basically looking for a way to call a specific dialog using Bot Framework 4.0 once determining what parameter the user is requesting. I have looked through Microsoft's documentation for Bot Builder 4.0 and have not been able to find anything applicable. I am very new to this environment, so I may have passed over the problem. I found a way to do it, by calling:

await Conversation.SendAsync(activity, () => new RootDialog());

But this was the syntax for Bot Framework 3.0. If anyone has any suggestions it would be very much appreciated.

What you're looking for is

await <TYPE>Context.BeginDialogAsync(nameof(<YOURDIALOGNAME>), <OPTIONAL_PARAMETERS>, cancellation token

The <TYPE> above means you could be using waterfalls, in which case it would be stepContext or a simple dialog, which would be dialogContext .

so for your bot above, you'd create the PurchaseOrderDialog.cs and SKUNumberDialog.cs , then utilize them as follows:

if (entry)
            {
                JToken commandToken = JToken.Parse(turnContext.Activity.Value.ToString());
                string temp = turnContext.Activity.Value.ToString();
                Logger.LogInformation(temp);
                string command = commandToken["action"].Value<string>();

                if (command.ToLowerInvariant() == "purchaseorder")
                {
                   return await context.BeginDialogAysnc(nameof(PurchaseOrderDialog), cancellationToken)
                }
                else if (command.ToLowerInvariant() == "sku")
                {
                    return await context.BeginDialogAysnc(nameof(SKUNumberDialog), cancellationToken)
                }

            }

The CoreBot in the Bot Framework's Samples Github Repo here is a good example of how complex dialogs are worked, and there's an official how-to doc here on working with component and waterfall dialogs, which are unique to v4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM