本文介绍了当Bot托管在Azure上时,我无法在验证器方法内的瀑布对话框中从自适应卡中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Bot中使用的是自适应卡版本1.2 ,而 Bot Builder对话框版本是4.5.1 .目前,我正在使用TextPrompt在瀑布对话框中调用自适应卡.我已经编写了一个验证器方法来验证从卡返回的值.在Bot Emulator中可以正常工作.但是,当我将其托管在Azure上时,出现错误.

I'm using Adaptive card version 1.2 and Bot Builder dialog version is 4.5.1 in my Bot. Currently I'm calling adaptive card inside waterfall dialog using TextPrompt. I have written a validator method to validate values returned from the card. This works fine in Bot Emulator. But when I host it on Azure I'm Getting error.

在验证器方法中,在promptContext.Recognized.Value中捕获自适应卡的值.但是当托管在Azure上时,它会返回null,这会导致对象引用未设置为对象的实例异常.

In the validator method, Adaptive card values are captured in promptContext.Recognized.Value. But it returns null when hosted on Azure which results in Object reference not set to an instance of an object exception.

//DialogClass
 AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
 {
      AdaptiveCardAsync,            
  }));
  AddDialog(new TextPrompt("AdaptiveCard", CardValidator));


private async Task<DialogTurnResult> SelectedOptionAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
                    // Get Adaptive Card
                    JObject card = AdaptiveCard();

                    return await stepContext.PromptAsync("AdaptiveCard",
                    new PromptOptions
                    {
                        Prompt = (Activity)MessageFactory.Attachment(new Attachment
                        {
                            ContentType = AdaptiveCard.ContentType,
                            Content = card,
                        }),
                    }, cancellationToken);
}


//Calling adaptive card. 
 public JObject AdaptiveCard()
 {
      string fileName = "GetValues.json";
      // combine path for cross platform support
      string[] paths = { ".", "AdaptiveCards", fileName };
      string fullPath = Path.Combine(paths);
      var adaptiveCard = File.ReadAllText(fullPath);
      JObject card = JObject.Parse(adaptiveCard);
}   

// To validate values received from adaptive card.
 private async Task<bool> CardValidator(PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)
{

var result =  JObject.Parse(promptContext.Recognized.Value);

}  


//Calling Dialog - DialogExtension.cs
 public static class DialogExtension
    {
        public static async Task Run(this Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor<DialogState> accessor, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var dialogSet = new DialogSet(accessor);
                dialogSet.Add(dialog);

                var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);
                // Ensure that message is a postBack (like a submission from Adaptive Cards)
                if (dialogContext.Context.Activity.GetType().GetProperty("ChannelData") != null)
                {
                    var channelData = JObject.Parse(dialogContext.Context.Activity.ChannelData.ToString());
                    if (channelData.ContainsKey("postBack") || channelData.ContainsKey("postback"))
                    {
                        var postbackActivity = dialogContext.Context.Activity;
                        // Convert the user's Adaptive Card input into the input of a Text Prompt
                        // Must be sent as a string
                        postbackActivity.Text = postbackActivity.Value.ToString();
                        //await dialogContext.Context.SendActivityAsync(postbackActivity);
                    }
                }
                var results = await dialogContext.ContinueDialogAsync(cancellationToken);
                if (results.Status == DialogTurnStatus.Empty)
                {
                    await dialogContext.BeginDialogAsync(dialog.Id, null, cancellationToken);
                }
            }
            catch(Exception ex)
            {
               await turnContext.SendActivityAsync(MessageFactory.Text(ex.Message));
            }
        }

请帮助我解决问题.

推荐答案

问题是"Web聊天中的测试"和Web聊天iFrame <embed>代码仍然使用WebChat V3,它不能很好地支持自适应卡. .在接下来的几周内,WebChat V4应该会同时推广到这两个平台.

The issue is that both "Test in Web Chat" and the Web Chat iFrame <embed> code still uses WebChat V3, which doesn't support Adaptive Cards well. WebChat V4 should be rolling out to both of those in the next couple of weeks.

关于您的LUIS问题,请访问:

Regarding your LUIS issue, go to:

  1. Azure门户网站
  2. 您的资源组
  3. 您的机器人使用的应用服务
  1. 转到配置
  1. 确保所有配置值均与appsettings.json文件中的值匹配.
  1. Ensure that all of your config values match the ones in your appsettings.json file.

这不会影响您的其他V4机器人,因为每个机器人应该使用其自己的应用程序服务.

This will not affect your other V4 bots since each bot should use its own App Service.

这篇关于当Bot托管在Azure上时,我无法在验证器方法内的瀑布对话框中从自适应卡中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:06