Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从LUIS|C中的自适应卡提交操作中获取值#_C#_Submit_Botframework_Azure Language Understanding_Adaptive Cards - Fatal编程技术网

C# 如何从LUIS|C中的自适应卡提交操作中获取值#

C# 如何从LUIS|C中的自适应卡提交操作中获取值#,c#,submit,botframework,azure-language-understanding,adaptive-cards,C#,Submit,Botframework,Azure Language Understanding,Adaptive Cards,我目前正在开发一个在VST中创建项目的LUIS bot。 现在,您只需将名称写入bot,如“Create Projekt abcd”,它就会为您创建项目。 我想通过为输入添加自适应卡来使它看起来更好,但当我按下提交按钮时,它只是告诉Bot代码有一个错误。 我做了一些研究,问题似乎是LUIS机器人不知道如何处理作为消息返回的对象 自适应卡:` using Microsoft.Bot.Builder.Dialogs; using Microsoft.Bot.Connector; using Syst

我目前正在开发一个在VST中创建项目的LUIS bot。 现在,您只需将名称写入bot,如“Create Projekt abcd”,它就会为您创建项目。 我想通过为输入添加自适应卡来使它看起来更好,但当我按下提交按钮时,它只是告诉Bot代码有一个错误。 我做了一些研究,问题似乎是LUIS机器人不知道如何处理作为消息返回的对象

自适应卡:`

using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AdaptiveCards;
using AdaptiveCards.Rendering;
using AdaptiveCards.Rendering.Html;
using Microsoft.Bot.Builder.FormFlow;

namespace LuisBot.Dialogs
{
public class ProjektInputCard
{


    public static Attachment GetCard(String pName)
    {
        String projektname = pName;
        if (projektname.Equals("(Name not found)"))
        {
            projektname = "";
        }

        AdaptiveCard Card = new AdaptiveCard() 
        {
            Body = new List<AdaptiveElement>()
            {
                new AdaptiveContainer()
                {
                    Items = new List<AdaptiveElement>()
                    {
                        new AdaptiveTextBlock()
                        {
                            Text = "Projekterstellung",
                            Weight = AdaptiveTextWeight.Bolder,
                            Size = AdaptiveTextSize.Large
                        },
                        new AdaptiveTextBlock()
                        {
                            Text = "Projektname:",
                            Weight = AdaptiveTextWeight.Bolder,
                            Size = AdaptiveTextSize.Default
                        },
                        new AdaptiveTextInput()
                        {
                            Type = "Input.Text",
                            Id = "ID_projekt",
                            Value = projektname
                        },
                        new AdaptiveTextBlock()
                        {
                            Text = "Beschreibung:",
                            Weight = AdaptiveTextWeight.Bolder,
                            Size = AdaptiveTextSize.Default
                        },

                        new AdaptiveTextInput()
                        {
                            Type = "Input.Text",
                            Id = "ID_description",
                            Value = "",
                            IsMultiline = true
                        }
                    }


                }



            }


        };

        Card.Actions = new List<AdaptiveAction>()
        {
            new AdaptiveSubmitAction()
            {
                Type = "Action.Submit",
                Title = "Erstellen"
            }
        };

        Attachment Attach = new Attachment() 
        {
            ContentType = AdaptiveCard.ContentType,
            Content = Card
        };

        return Attach;
    }
}
}`
MessageReceived方法是:

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        var message = await result;
        InputValues data;
        if (message.Value != null)
        {
            // Got an Action Submit
            dynamic value = message.Value;
            string submitType = value.Type.ToString();
            if (value != null)
            {
                data = Newtonsoft.Json.JsonConvert.DeserializeObject<InputValues>(submitType);
                _projectname = data.Name;
                _description = data.Description;
                await this.ShowLuisResult(context);

            }

        }
    }
公共虚拟异步任务消息ReceivedAsync(IDialogContext上下文,IAwaitable结果) { var消息=等待结果; 输入值数据; if(message.Value!=null) { //收到一个提交的动作 动态值=message.value; 字符串submitType=value.Type.ToString(); if(值!=null) { data=Newtonsoft.Json.JsonConvert.DeserializeObject(submitType); _projectname=data.Name; _描述=数据。描述; 等待此消息。ShowLuisResult(上下文); } } } Ceepert, 不要试图在同一个类中完成这一切(我想这就是我在代码中看到的),您要做的是将自适应卡部件和luis部件分离到单独的对话框中。您的初始对话框将是一个常规的IDialog实现

从输入中收集数据,使用自适应卡中的数据作为消息的文本属性创建新消息,并执行调用上下文。转发以将新消息发送到您的luis对话框。 从您的代码中不清楚Luis将使用AdaptiveCard的哪个输入来确定用户的意图,因此我假设我的示例为“\u projectname”

如果文本之外还有其他数据,可以将其作为参数传递给Luis对话框构造函数

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
    var message = await result;

    if (message.Value != null)
    {
        //reroute the user back to your card with an additional message to 
        //put response in the provided fields.
        return;
    }

    InputValues data;
    if (message.Value != null)
    {
        // Got an Action Submit
        dynamic value = message.Value;
        string submitType = value.Type.ToString();
        if (value != null)
        {
            data = Newtonsoft.Json.JsonConvert.DeserializeObject<InputValues>(submitType);
            _projectname = data.Name;
            _description = data.Description;

            IMessageActivity msg = Activity.CreateMessageActivity();
            msg.TextFormat = "text";
            msg.Text = _projectname;

            await context.Forward(new MyLuisDialog(), ResumeAfterLuisDialog, msg, CancellationToken.None);

        }

    }
}
公共虚拟异步任务消息ReceivedAsync(IDialogContext上下文,IAwaitable结果) { var消息=等待结果; if(message.Value!=null) { //将用户重新路由回您的卡,并向 //将响应放在提供的字段中。 返回; } 输入值数据; if(message.Value!=null) { //收到一个提交的动作 动态值=message.value; 字符串submitType=value.Type.ToString(); if(值!=null) { data=Newtonsoft.Json.JsonConvert.DeserializeObject(submitType); _projectname=data.Name; _描述=数据。描述; IMessageActivity msg=Activity.CreateMessageActivity(); msg.TextFormat=“text”; msg.Text=\u projectname; wait context.Forward(新建MyLuisDialog(),ResumeAfterLuisDialog,msg,CancellationToken.None); } } }
感谢您的回复,我将测试您编写的内容,但我不希望LUIS使用AdaptiveCard中的数据。用户写入项目名称和描述,并据此创建VST。我面临的问题是a)对话框没有等待卡片被填充,并且按下了“提交”按钮,因此当卡片显示时,您可以向bot写入其他内容;b)我不知道如何从中获取值。(但这可能由您编写的内容修复,需要先测试该内容)哦和“message.CreateMessage();”不存在,我已经见过几次了,但不知道“message”var来自哪里,我所能做的就是“context.MakeMessage();”几件事。首先,我更正了我的代码示例。抱歉搞混了!。其次,好的,当您“提交”自适应卡时,数据通过message.Value输入,当用户只是向bot写入其他内容时,数据通过message.Text输入。当他们这样做的时候,你不会从卡片上得到任何东西。这是您应该执行的常见错误检查。我通常要做的是在方法的开头检查message.text,然后用一个额外的文本块重新显示卡片,上面写着“请在提供的字段中键入您的响应”
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
    var message = await result;

    if (message.Value != null)
    {
        //reroute the user back to your card with an additional message to 
        //put response in the provided fields.
        return;
    }

    InputValues data;
    if (message.Value != null)
    {
        // Got an Action Submit
        dynamic value = message.Value;
        string submitType = value.Type.ToString();
        if (value != null)
        {
            data = Newtonsoft.Json.JsonConvert.DeserializeObject<InputValues>(submitType);
            _projectname = data.Name;
            _description = data.Description;

            IMessageActivity msg = Activity.CreateMessageActivity();
            msg.TextFormat = "text";
            msg.Text = _projectname;

            await context.Forward(new MyLuisDialog(), ResumeAfterLuisDialog, msg, CancellationToken.None);

        }

    }
}