When Bot is hosted on Azure, I'm unable to ret

2019-08-31 05:00发布

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.

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));
            }
        }

Kindly help me in resolving the issue.

1条回答
\"骚年 ilove
2楼-- · 2019-08-31 05:31

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.

Regarding your LUIS issue, go to:

  1. Azure Portal
  2. Your Resource Group
  3. Your App Service that Your Bot Uses

enter image description here

  1. Go to Configuration

enter image description here

  1. Ensure that all of your config values match the ones in your appsettings.json file.

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

查看更多
登录 后发表回答