![](/img/trans.png)
[英]Get variable from Adaptive card `Action.Submit` in Botframework
[英]Botframework - C# - Adaptive Card - Submit Action - Exception
在自適應卡片(botframework、c#、模擬器、本地主機)中的 SubmitAction 操作上,我收到此異常
Exception: Value cannot be null. Parameter name: stringToEscape
[File of type 'text/plain']
你能幫我指出我做錯了什么嗎?
card.Actions.Add(
new SubmitAction()
{
Title = "Submit"
Data = Newtonsoft.Json.Linq.JObject.FromObject(new { button = "Submit", ServerUrl = "idServerURL" })
}
);
從 RootDialog - LUIS Intent 被調用
[LuisIntent("ServerAuth")]
public async Task ServerAuthIntentActionResultHandlerAsync(IDialogContext
context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
var message = await activity;
await context.PostAsync($"Am working on it...'{message.Text}' ");
var serverAuthAction = new ServerAuthAction();
// Action to execute if no form is required - Based on LUIS result, call fulfillment methods From/To ERP Data and proceed to next stage of dialog
await serverAuthAction.ResumeActionServerAuthFormDialog(context, result);
//context.Wait(this.MessageReceived);
}
public async Task ResumeActionServerAuthFormDialog(IDialogContext context, LuisResult result)
{
try
{
//Based on the LUIS Result, fetch data from AppServer
//var searchQuery = result;
//Data - Assign value to this Model from AppServer fetched data
ServerAuthModel serverAuthData = new ServerAuthModel();
serverAuthData = default(ServerAuthModel);
//For testing populate values by hardcoding - /May/2017
ServerAuthAdaptiveCardView serverAuthView = new ServerAuthAdaptiveCardView();
//Pass Data to Channel Adaptive Card View
var resultData = serverAuthView.GetServerAuthAdaptiveCard();
var resultMessage = context.MakeMessage();
resultMessage.Attachments.Add(resultData);
await context.PostAsync(resultMessage);
}
catch (Exception ex)
{
...
}
finally
{
....
}
}
GetServerAuthAdaptiveCard() 具有提交操作代碼。
public Attachment GetServerAuthAdaptiveCard()
{
AdaptiveCard card = new AdaptiveCard();
card.FallbackText = "App Server Authentication";
card.Body.Add(
new TextInput()
{
Id = "idServerURL",
IsRequired = true,
Placeholder = "App Server URL",
MaxLength = 100,
IsMultiline = false,
Style = TextInputStyle.Url,
Speak = "App Server URL",
});
card.Body.Add(
new ChoiceSet()
{
Id = "idAuthCompany",
IsRequired = true,
IsMultiSelect = false,
Style = ChoiceInputStyle.Compact,
Speak = "Company to Authenticate for",
Value = "DocM5",
Choices = new List<Choice>() {
new Choice()
{
Title = "P2PDemo",
Value = "P2PDemo",
IsSelected = true,
Speak = "P2PDemo"
},
new Choice()
{
Title = "SalesDemo",
Value = "SalesDemo",
IsSelected = false,
Speak = "SalesDemo"
}
}
});
card.Body.Add(
new TextInput()
{
Id = "idBranchName",
IsRequired = true,
Placeholder = "App Branch",
MaxLength = 100,
IsMultiline = false,
Style = TextInputStyle.Text,
// Value = ""
});
var submitActionData = JObject.Parse("{ \"Type\": \"idServerURL\" }");
card.Actions.Add(
/* new SubmitAction()
{
Title = "Submit",
// Speak = "Submit",
Data = Newtonsoft.Json.Linq.JObject.FromObject(new { button = "Submit", ServerUrl = "idServerURL" })
}
*/
new SubmitAction()
{
DataJson = submitActionData.ToString()
});
var attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = card };
return attachment;
}
模擬器異常:
"contentType": "text/plain",
"content": " at System.Uri.EscapeDataString(String stringToEscape)
at Microsoft.Bot.Builder.Luis.LuisRequest.BuildUri(ILuisModel model)
at Microsoft.Bot.Builder.Luis.LuisService.Microsoft.Bot.Builder.Luis.ILuisService.BuildUri(LuisRequest luisRequest)
at Microsoft.Bot.Builder.Luis.Extensions.<QueryAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.LuisDialog`1.<MessageReceived>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult()
at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog`1.<ResumeAsync>d__3.MoveNext()
-- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown --
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.ScoringEventLoop`1.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.EventLoopDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.SetAmbientThreadCulture.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.SerializeByConversation.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__5.MoveNext()"
嘗試填充DataJson
屬性而不是Data
屬性。
var submitActionData = JObject.Parse("{ \"Type\": \"HotelSelection\" }");
var action = new SubmitAction()
{
DataJson = submitActionData.ToString()
}
根據完整的例外情況,問題出在 LUIS 上,而不是 Adaptive 卡上。 具體來說,問題出在LuisService類(由LuisDialog
)的BuildUri方法中。 異常還告訴我們問題是在調用EscapeDataString方法時發生的。
如果您仔細查看BuildUri
方法,您將看到有 10 次調用EscapeDataString
方法。 其中一些調用與服務本身的值相反,我認為您沒有修改這些值; 然而,其他的超過了LuisModel
值,比如SubscriptionKey
和ModelId
,並且還有一個超過了要發送到LUIS
的Query
。
話雖如此,我的建議是查看您在裝飾基於LuisDialog
的類的LuisModel
屬性中設置的值。
如果您不確定 LUIS + Bot Framework 的工作原理,我建議您查看智能 LUIS示例。
您收到此錯誤是因為當您單擊 Adaptive 卡上的提交按鈕時,它會調用您的 BOT 框架的 POST 方法。 此時Activity.Text
字段為NULL
。 如果Activity.Text
字段為NULL
,您應該檢查 POST 方法; 如果是,則不應調用 LUIS 進行意圖檢查。
我就是這樣做的,以使其適用於 Microsoft 團隊。 否則對於模擬器,您只需在 Data 中傳遞一個字符串。
dynamic dataObject = new JObject();
dataObject.msteams = new JObject();
dataObject.msteams.type = "imBack";
dataObject.msteams.value = intent.Value;
var actionSubmit = new AdaptiveSubmitAction(){
Title = intent.Value,
Data = turnContext.Activity.ChannelId != "emulator" ? dataObject : intent.Value
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.