3

在 Adaptive Cards (botframework, c#, emulator, localhost) 中的 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()"
4

3 回答 3

2

尝试填充DataJson属性而不是属性Data

var submitActionData = JObject.Parse("{ \"Type\": \"HotelSelection\" }");

var action = new SubmitAction()
{
    DataJson = submitActionData.ToString()
}

根据添加到问题的新详细信息进行更新。

根据完整的例外情况,问题在于 LUIS 而不是自适应卡。具体来说,问题出在LuisService类的BuildUri方法中(由 调用)。该异常还告诉我们在调用EscapeDataString方法时发生了问题。LuisDialog

如果您仔细查看该BuildUri方法,您会看到该方法有 10 次调用EscapeDataString。其中一些调用违反了服务本身的值,我认为您没有修改它们;然而,其他的超过了LuisModel, like SubscriptionKeyand的值,ModelId并且还有一个超过 的Query要发送到LUIS

话虽如此,我的建议是查看您在装饰基础类的LuisModel属性中设置的值。LuisDialog

如果您不确定 LUIS + Bot Framework 的工作原理,我建议您查看Intelligence-LUIS示例。

于 2017-05-31T09:31:38.960 回答
0

您收到此错误是因为当您单击自适应卡上的提交按钮时,它会调用您的 BOT 框架的 POST 方法。此时Activity.Text字段为NULL。如果Activity.Text字段为NULL;您应该检查 POST 方法 如果是,则不应调用 LUIS 进行意图检查。

于 2017-06-09T09:24:32.157 回答
0

我就是这样做的,以使其适用于 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
};
于 2020-04-27T18:44:39.910 回答