簡體   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