Botframework - C# - 自适应卡 - 提交操作 - 例外

时间:2017-05-31 05:29:28

标签: botframework adaptive-cards

自适应卡中的SubmitAction操作(botframework,c#,emulator,localhost)我得到了这个例外

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()"

3 个答案:

答案 0 :(得分:2)

尝试填写DataJson属性而不是Data属性。

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

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

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

除了完整的例外,问题出在LUIS周围,而不是自适应卡。具体来说,问题出现在BuildUri类的LuisService方法中(由LuisDialog调用)。例外情况还告诉我们,在调用EscapeDataString方法时会出现问题。

如果仔细查看BuildUri方法,您会看到有10次调用EscapeDataString方法。其中一些调用是针对服务本身的值,我认为你不会修改它们;但是其他值超过LuisModel的值,例如SubscriptionKeyModelId,并且Query上还有一个值要发送到LUIS

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

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

答案 1 :(得分:0)

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

答案 2 :(得分: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
};