繁体   English   中英

单击使用V4 C#开发的chatbot中的自适应卡中的Submit之后,如何解决与Web聊天通道中的500错误代码相关的问题?

[英]How to fix issue related to 500 error code in web chat channel after clicking submit in Adaptive card in chatbot developed using V4 C#?

在通过V4 C#开发的聊天机器人中,单击自适应卡中的“提交”按钮后,如何解决与Web聊天频道中发生500错误有关的问题?

按照@ mdrichardson-msft的建议创建此新问题,因为该问题是特定的/其他问题,位于以下堆栈溢出问题中:

除了使用自适应卡之外,是否有办法在V4聊天机器人C#中启用日历选项作为输入?

来我的问题:

我有一个瀑布对话类,在其中我使用自适应卡选择日期时间输入,并在步骤1中使用提交按钮,然后在步骤2中单击步骤1中的提交后,将捕获并处理这些值。

当前,如上面链接中所述(问题将在下面详细解释),单击自适应卡中的“提交”按钮时,我在浏览器中面临500错误:

第1步:

我正在显示具有两个日期和时间输入的自适应卡,一个用于启动,另一个用于停止

实际结果:

自适应程序可以在模拟器和网络聊天通道中成功显示,没有任何问题

步骤2:当我在步骤1中显示的自适应卡上单击SetSchedule时,应该在步骤2中捕获值并显示在屏幕上

实际结果:

在模拟器中工作正常,但在Web Chat通道漫游器中则不能。 我在网络聊天频道BOT中遇到错误。 请找到用于访问漫游器的HTML文件,瀑布对话框类以及随附的Adaptive card json文件以供参考。 与此同时,请找到网络聊天频道中附带的错误屏幕截图,以供参考。 我也通过TestinWebChat进行了测试,它也在这里抛出错误。

我已经通过VSTS 2019发布了它,但没有附带任何错误屏幕截图,以供参考“ publishsuceed_thruvisualStudio2019.jpg”。

您是否可以像引导问题中一样指导我解决此问题? 请求您的即时帮助,这阻止了我的工作。

语言:C#SDK:V4发布于:Visual Studio 2019

HTML:

 <!DOCTYPE html> <html lang="en-US"> <head> <title>Web Chat: Custom style options</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js". When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js", or lock down on a specific version with the following format: "/4.1.0/webchat.js". --> <script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script> <style> html, body { height: 100% } body { margin: 0 } #webchat { height: 100%; width: 100%; } </style> </head> <body> <div id="webchat" role="main"> </div> <script> (async function () { // In this demo, we are using Direct Line token from MockBot. // To talk to your bot, you should use the token exchanged using your Direct Line secret. // You should never put the Direct Line secret in the browser or client app. // https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication // Token is found by going to Azure Portal > Your Web App Bot > Channels > Web Chat - Edit > Secret Keys - Show // It looks something like this: pD*********xI.8ZbgTHof3GL_nM5***********aggt5qLOBrigZ8 const token = '<<Your Direct Line Secret Key>>'; // You can modify the style set by providing a limited set of style options const styleOptions = { botAvatarImage: 'https://docs.microsoft.com/en-us/azure/bot-service/v4sdk/media/logo_bot.svg?view=azure-bot-service-4.0', botAvatarInitials: 'BF', userAvatarImage: 'https://avatars1.githubusercontent.com/u/45868722?s=96&v=4', userAvatarInitials: 'WC', bubbleBackground: 'rgba(0, 0, 255, .1)', bubbleFromUserBackground: 'rgba(0, 255, 0, .1)' }; // We are using a customized store to add hooks to connect event const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => { if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') { // When we receive DIRECT_LINE/CONNECT_FULFILLED action, we will send an event activity using WEB_CHAT/SEND_EVENT dispatch({ type: 'WEB_CHAT/SEND_EVENT', payload: { name: 'webchat/join', value: { language: window.navigator.language } } }); } return next(action); }); window.WebChat.renderWebChat({ directLine: window.WebChat.createDirectLine({ token }), styleOptions,store }, document.getElementById('webchat')); document.querySelector('#webchat > *').focus(); })().catch(err => console.error(err)); </script> </body> </html> 

码:

using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace EchoBot.Dialogs
{
    public class Adaptivecarddialog : WaterfallDialog
    {
        public const string cards = @"./AdaptiveCard.json";

        public Adaptivecarddialog(string dialogId, IEnumerable<WaterfallStep> steps = null)
            : base(dialogId, steps)
        {
            AddStep(async (stepContext, cancellationToken) =>
            {
                var cardAttachment = CreateAdaptiveCardAttachment(cards);

                var reply = stepContext.Context.Activity.CreateReply();
                reply.Attachments = new List<Attachment>() { cardAttachment };

                await stepContext.Context.SendActivityAsync(reply, cancellationToken);
                var opts = new PromptOptions
                {
                    Prompt = new Activity
                    {
                        Type = ActivityTypes.Message,
                        // You can comment this out if you don't want to display any text. Still works.
                    }
                };

                // Display a Text Prompt and wait for input
                return await stepContext.PromptAsync(nameof(TextPrompt), opts);
            });

            AddStep(async (stepContext, cancellationToken) =>
            {
                var res = stepContext.Result.ToString();
                dynamic jobject = JsonConvert.DeserializeObject(res);
                string NewStartDateTime = jobject.Startdate + " " + jobject.Starttime;
                string NewStopDateTime = jobject.Stopdate + " " + jobject.Stoptime;
                await stepContext.Context.SendActivityAsync($"StartDateTime:{NewStartDateTime}", cancellationToken: cancellationToken);
                await stepContext.Context.SendActivityAsync($"StopDateTime:{NewStopDateTime}", cancellationToken: cancellationToken);

                return await stepContext.EndDialogAsync();
            });

        }

        public static new string Id => "Adaptivecarddialog";

        public static Adaptivecarddialog Instance { get; } = new Adaptivecarddialog(Id);

        public static Attachment CreateAdaptiveCardAttachment(string filePath)
        {
            var adaptiveCardJson = File.ReadAllText(filePath);
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content = JsonConvert.DeserializeObject(adaptiveCardJson),
            };
            return adaptiveCardAttachment;
        }
    }
}

自适应卡:

{
  "type": "AdaptiveCard",
  "body": [
    {
      "type": "TextBlock",
      "id": "Start date text",
      "separator": true,
      "text": "Schedule Start DateTime:"
    },
    {
      "type": "TextBlock",
      "id": "DateTimeFormat",
      "horizontalAlignment": "Center",
      "separator": true,
      "weight": "Bolder",
      "color": "Warning",
      "text": "(In UTC Time Zone)"
    },
    {
      "type": "Input.Date",
      "id": "Startdate",
      "separator": true,
      "value": "2019-05-24"
    },
    {
      "type": "Input.Time",
      "id": "Starttime",
      "separator": true,
      "value": "08:00"
    },
    {
      "type": "TextBlock",
      "id": "Stop date text",
      "separator": true,
      "text": "Schedule Stop DateTime:"
    },
    {
      "type": "TextBlock",
      "id": "DateTimeFormat",
      "horizontalAlignment": "Center",
      "separator": true,
      "weight": "Bolder",
      "color": "Warning",
      "text": "(In UTC Time Zone)"
    },
    {
      "type": "Input.Date",
      "id": "Stopdate",
      "separator": true,
      "value": "2019-05-25"
    },
    {
      "type": "Input.Time",
      "id": "Stoptime",
      "separator": true,
      "value": "08:00"
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "id": "SubmitBtn",
      "title": "SetSchedule"
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.0"
}

屏幕截图:

发布到Azure期间没有错误

单击自适应卡中的按钮时,Web通道聊天机器人出现500错误

感谢和问候

-ChaitanyaNG


日期:2019年6月6日

在Matt的指导下,KUDU的日志详细信息可供参考:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>IIS Detailed Error - 500.0 - Internal Server Error</title> 
<style type="text/css"> 
<!-- 
body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;} 
code{margin:0;color:#006600;font-size:1.1em;font-weight:bold;} 
.config_source code{font-size:.8em;color:#000000;} 
pre{margin:0;font-size:1.4em;word-wrap:break-word;} 
ul,ol{margin:10px 0 10px 5px;} 
ul.first,ol.first{margin-top:5px;} 
fieldset{padding:0 15px 10px 15px;word-break:break-all;} 
.summary-container fieldset{padding-bottom:5px;margin-top:4px;} 
legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;} 
legend{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px; 
font-weight:bold;font-size:1em;} 
a:link,a:visited{color:#007EFF;font-weight:bold;} 
a:hover{text-decoration:none;} 
h1{font-size:2.4em;margin:0;color:#FFF;} 
h2{font-size:1.7em;margin:0;color:#CC0000;} 
h3{font-size:1.4em;margin:10px 0 0 0;color:#CC0000;} 
h4{font-size:1.2em;margin:10px 0 5px 0; 
}#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS",Verdana,sans-serif; 
color:#FFF;background-color:#5C87B2; 
}#content{margin:0 0 0 2%;position:relative;} 
.summary-container,.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} 
.content-container p{margin:0 0 10px 0; 
}#details-left{width:35%;float:left;margin-right:2%; 
}#details-right{width:63%;float:left;overflow:hidden; 
}#server_version{width:96%;_height:1px;min-height:1px;margin:0 0 5px 0;padding:11px 2% 8px 2%;color:#FFFFFF; 
background-color:#5A7FA5;border-bottom:1px solid #C1CFDD;border-top:1px solid #4A6C8E;font-weight:normal; 
font-size:1em;color:#FFF;text-align:right; 
}#server_version p{margin:5px 0;} 
table{margin:4px 0 4px 0;width:100%;border:none;} 
td,th{vertical-align:top;padding:3px 0;text-align:left;font-weight:normal;border:none;} 
th{width:30%;text-align:right;padding-right:2%;font-weight:bold;} 
thead th{background-color:#ebebeb;width:25%; 
}#details-right th{width:20%;} 
table tr.alt td,table tr.alt th{} 
.highlight-code{color:#CC0000;font-weight:bold;font-style:italic;} 
.clear{clear:both;} 
.preferred{padding:0 5px 2px 5px;font-weight:normal;background:#006633;color:#FFF;font-size:.8em;} 
--> 
</style> 

</head> 
<body> 
<div id="content"> 
<div class="content-container"> 
<h3>HTTP Error 500.0 - Internal Server Error</h3> 
<h4>The page cannot be displayed because an internal server error has occurred.</h4> 
</div> 
<div class="content-container"> 
<fieldset><h4>Most likely causes:</h4> 
<ul>    <li>IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.</li>    <li>IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.</li>    <li>IIS was not able to process configuration for the Web site or application.</li>     <li>The authenticated user does not have permission to use this DLL.</li>   <li>The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.</li> </ul> 
</fieldset> 
</div> 
<div class="content-container"> 
<fieldset><h4>Things you can try:</h4> 
<ul>    <li>Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.</li>     <li>Check the event logs to see if any additional information was logged.</li>  <li>Verify the permissions for the DLL.</li>    <li>Install the .NET Extensibility feature if the request is mapped to a managed handler.</li>  <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul> 
</fieldset> 
</div> 

<div class="content-container"> 
<fieldset><h4>Detailed Error Information:</h4> 
<div id="details-left"> 
<table border="0" cellpadding="0" cellspacing="0"> 
<tr class="alt"><th>Module</th><td>&nbsp;&nbsp;&nbsp;AspNetCoreModule</td></tr> 
<tr><th>Notification</th><td>&nbsp;&nbsp;&nbsp;ExecuteRequestHandler</td></tr> 
<tr class="alt"><th>Handler</th><td>&nbsp;&nbsp;&nbsp;aspNetCore</td></tr> 
<tr><th>Error Code</th><td>&nbsp;&nbsp;&nbsp;0x00000000</td></tr> 

</table> 
</div> 
<div id="details-right"> 
<table border="0" cellpadding="0" cellspacing="0"> 
<tr class="alt"><th>Requested URL</th><td>&nbsp;&nbsp;&nbsp;https://testbotforoauthprompt:80/api/messages</td></tr> 
<tr><th>Physical Path</th><td>&nbsp;&nbsp;&nbsp;D:\home\site\wwwroot\api\messages</td></tr> 
<tr class="alt"><th>Logon Method</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr> 
<tr><th>Logon User</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr> 

</table> 
<div class="clear"></div> 
</div> 
</fieldset> 
</div> 

<div class="content-container"> 
<fieldset><h4>More Information:</h4> 
This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error. 
<p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&amp;IIS70Error=500,0,0x00000000,14393">View more information &raquo;</a></p> 
<p>Microsoft Knowledge Base Articles:</p> 


</fieldset> 
</div> 
</div> 
</body> 
</html> 
2019-06-06 05:04:50 TESTBOTFOROAUTHPROMPT POST /api/messages X-ARR-LOG-ID=b3f7a170-d306-477e-b318-fbd82ec285f6 443 - 52.172.202.195 BF-DirectLine+(Microsoft-BotFramework/3.2++https://botframework.com/ua) ARRAffinity=232908322fb7729ed3fe519abf975a28a9506866f45a7a57c7acd29d79e24c2f - testbotforoauthprompt.azurewebsites.net 500 0 0 294 2493 3475

请帮助我解决此问题,由于我对代码和所有其他技术方面的知识还很陌生,因此我要求以逐步的详细方式进行指导。

如果可能,我们可以进行双方同意的Skype /团队呼叫会议,以便我们可以在需要时逐步详细地进行操作。


日期:2019年6月16日,通过其他调试点更新POST。

嗨,马特,

我已经使用NGROK调试了远程通道,例如在webchat中进行了测试,并且还通过仿真器进行了调试,以查看传入的数据不同:

使用仿真器:使用仿真器时,当我按下Adaptive卡内的按钮时,有来自仿真器的通道数据,在解析后我将POSTBACK视为true,因此我可以转到瀑布对话框的下一步,由于附加代码用来处理自适应卡中数据的模块已执行

请参阅名称为“ ChannelDataComing_fromemulator.jpg”的屏幕截图作为参考。

使用Azure的TestInWebChat:在这里,Channel数据以NULL的形式出现,由于代码无法解析,导致代码出错,因为没有解析它会给出作为对象引用错误的错误。 没有通道数据,没有POSTback,因此不会进入瀑布的下一步来处理数据。

请参阅名称为“ ChannelDataComingnull_fromTestinWeBChat.jpg”的屏幕截图作为参考。

查询

  1. 在模拟器中进行测试时,为什么通道数据没有出现?
  2. 在这种情况下,如何获取要传递的通道数据,以使POST返回为真,然后执行瀑布的下一步?
  3. 如果这不起作用,还有其他方法可以完成,以便进入下一步,我可以按照我认为合适的方式处理数据吗?

值得注意的是,在发送第一个HI消息时,通道数据确实存在,因为该代码位于Activity == Message条件内,并且该通道没有回发代码,因此代码不会完全执行,但是在命中之后显示自适应卡中的提交按钮后,通道数据不确定,为什么?

当我被困在这里时,请帮助我解决此问题,我真的希望它能够正常工作吗? 来自仿真器的通道数据

来自testinWebchat的频道数据为空

以下是导致问题解决的对OP的评论的摘要。

调试技巧

  • 确保机器人在本地运行。
  • 在您的App Service的“开发工具”>“高级工具”下,通过Kudu检查日志流或日志文件。 您还可以在您的App Service的“监视”>“ App Service 日志”下打开“ 应用程序日志” ,然后在另一个选项卡/窗口中的Web聊天中测试bot时,通过App Service的“日志流”部分查看日志流。
  • 检查“ 应用程序设置”条目是否存在且正确(密码,应用程序ID等)。
  • 按照@Kyle Delaney, 使用您的本地代码调试远程通道 这里有更多说明,基本上,这需要进行以下操作:
  • 确保已安装ngrok。
  • 以下说明大致基于此处的指南:
  • 在Visual Studio中打开解决方案。
  • 在Visual Studio中开始调试。
  • 记下打开的网页的本地主机地址中的端口(应为3978)。
  • 导航到您提取ngrok的目录。
  • 在地址栏中输入cmd,然后按Enter键以打开一个新的命令提示符窗口。
  • 创建一个公共可访问的URL,该URL将指定端口上的所有http通信隧道传输到您的计算机:
  • ngrok http 3978 --host-header = localhost
  • 复制https转发URL。
  • 该格式应为https://.ngrok.io。
  • 使ngrok运行的命令提示符窗口保持打开状态,因为一旦关闭,URL将不再可访问。
  • 停止调试。
  • 在Azure门户中,打开Web App Bot资源。
  • 转到Bot管理>设置>配置,然后将URL https://.azurewebsites.net的第一部分替换为ngrok URL。
  • 最终网址应采用https:/// api / messages的形式。
  • 单击“保存”(您已在文本框外单击以启用“保存”按钮)。
  • 转到“应用程序服务”>“设置”>“配置”,并记下MicrosoftAppId和MicrosoftAppPassword的值。
  • .bot文件中的值是加密值,我们需要模拟器的解密值。
  • 在Visual Studio中,将appId和appPassword键值对从.bot文件中的Production端点复制到Development端点。
  • 确保将Development终结点的终结点值设置为localhost URL( http:// localhost:3978 / api / messages )。
  • 将更改保存在Visual Studio中。
  • 在Visual Studio中开始调试。
  • 在Azure中的Web聊天中打开测试。
  • 测试机器人功能。
  • 应该达到在代码中设置的所有断点。

  • 清理步骤-重要!!!

  • 将Azure中Web App Bot的消息传递终结点URL恢复为其原始值,然后保存更改。
  • 撤消/还原对.bot文件的任何更改。
  • 关闭运行ngrok的命令提示符窗口。
  • 关闭Bot Framework模拟器

空参考错误

多个作者对此进行了无数次讨论,但总而言之……您要访问的一个对象或其中一个对象的属性为null 遇到断点时,请在调试器中逐行浏览代码,直到找到断行。 找到断行后,可以鼠标悬停在变量及其属性上,以检查变量及其属性。


WebChat频道中未通过ChannelData

我自己遇到了这个问题,找不到关于这种情况的任何文档,但是我设法通过OnTurnAsync方法中的以下代码解决了这个问题:

if (dc.Context.Activity.Type == ActivityTypes.Message)
{
    //PropertyInfo channelDataProperty = dc.Context.Activity.GetType().GetProperty("ChannelData");
    Activity activity = dc.Context.Activity;
    object rawChannelData = activity.ChannelData;

    // For the Bot Framework Emulator
    if (rawChannelData != null)
    {
        JObject channelData = JObject.Parse(rawChannelData.ToString());

        if (channelData.Children().Any(c => ((JProperty)c).Name == "postBack") && activity.Value != null)
        {
            dc.Context.Activity.Text = "your-value-here";
        }
    }
    // For the WebChat channel since it doesn't provide ChannelData
    else if (activity.ChannelId == Channels.Webchat && activity.Value != null)
    {
        dc.Context.Activity.Text = "your-value-here";
    }
}

(如果您愿意)可以进一步简化为:

if (dc.Context.Activity.Type == ActivityTypes.Message)
{
    // For the Bot Framework Emulator AND the WebChat channel
    if (dc.Context.Activity.Value != null && dc.Context.Activity.Text == null)
    {
        dc.Context.Activity.Text = "your-value-here";
    }
}

上面的代码的简化版本应该起作用的原因是,因为您知道Adaptive Card是唯一应填充Activity.Value属性的时间,其余时间是回发数据位于.Text属性中并且将由WaterfallDialog中的代码自动拾取。 我建议您在决定使用简化代码之前先进行测试,因为您可能会遇到在自适应卡之外不填充.Value情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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