Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.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# botFramework:在bot框架下禁用web聊天中的卡按钮_C#_Bots_Botframework_Web Chat - Fatal编程技术网

C# botFramework:在bot框架下禁用web聊天中的卡按钮

C# botFramework:在bot框架下禁用web聊天中的卡按钮,c#,bots,botframework,web-chat,C#,Bots,Botframework,Web Chat,我想在bot框架下禁用web聊天中的卡按钮。例如,在一张卡中,我有多个按钮,我想根据一些数据值禁用一些按钮。我怎样才能做到这一点呢?今后,我建议缩小您的请求范围,使其不那么宽泛,并包括与您试图实现的目标相关的细节。尽管如此,我还是填补了一些空白,并做了一些我希望会有所帮助的事情 我有一个可以执行以下操作的程序: 为每个响应显示英雄卡 如果用户说“嗨”或“你好”,卡上将显示两个按钮 如果用户没有向机器人打招呼,则只会显示一个按钮 告诉用户他们是否向机器人打招呼(SendGreeting,true

我想在bot框架下禁用web聊天中的卡按钮。例如,在一张卡中,我有多个按钮,我想根据一些数据值禁用一些按钮。我怎样才能做到这一点呢?

今后,我建议缩小您的请求范围,使其不那么宽泛,并包括与您试图实现的目标相关的细节。尽管如此,我还是填补了一些空白,并做了一些我希望会有所帮助的事情

我有一个可以执行以下操作的程序:

  • 为每个响应显示英雄卡
  • 如果用户说“嗨”或“你好”,卡上将显示两个按钮
  • 如果用户没有向机器人打招呼,则只会显示一个按钮
  • 告诉用户他们是否向机器人打招呼(SendGreeting,true或false)
我在UserData中保存了一个布尔值SendGreeting,以通知bot是否显示第二个按钮。在控制器中,我有以下代码:

  • 实例化用户数据
  • 确定SentGreeting应为true还是false
  • 然后将该布尔值保存到UserData.SentGreeting

             // create connector service
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
            // get state client object
            StateClient stateClient = activity.GetStateClient();
            // retrieve user data
            BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);
    
            bool SentGreeting;
            if (activity.Text == "hello" || activity.Text == "hi")
            {
                SentGreeting = true;
            } else
            {
                SentGreeting = false;
            }
            userData.SetProperty<bool>("SentGreeting", SentGreeting);
    
            // save state
            await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
    
            // initiate CardDialog
            await Conversation.SendAsync(activity, () => new CardDialog());
    
    //创建连接器服务
    ConnectorClient连接器=新的ConnectorClient(新Uri(activity.ServiceUrl));
    //获取状态客户端对象
    StateClient StateClient=activity.GetStateClient();
    //检索用户数据
    BotData userData=await stateClient.BotState.GetUserDataAsync(activity.ChannelId,activity.From.Id);
    布尔森特问候;
    if(activity.Text==“你好”| | activity.Text==“你好”)
    {
    sent=正确;
    }否则
    {
    sent=假;
    }
    SetProperty(“SentGreeting”,SentGreeting);
    //拯救国家
    等待stateClient.BotState.SetUserDataAsync(activity.ChannelId、activity.From.Id、userData);
    //启动CardDialog
    等待对话。SendAsync(活动,()=>new CardDialog());
    
在对话框中,有以下代码:

  • 从UserData检索SentGreeting
  • 创建英雄卡
  • 创建“秘密”按钮,并仅在“秘密”为true时将其添加到按钮列表中

            // create sentGreeting
        bool sentGreeting;
        // assign value from UserData.SentGreeting
        context.UserData.TryGetValue<bool>("SentGreeting", out sentGreeting);
    
        // create standard button list (for those who do not greet the bot)
        var GenericButtonList = new List<CardAction>
        {
            new CardAction(ActionTypes.OpenUrl, "Bot Framework", value: "https://docs.botframework.com/en-us/"),
        };
    
        // create the hero card
        var Card = new HeroCard()
        {
            Title = "Select an Action",
            Subtitle = "Choose from available actions",
            Text = "If you were polite and said \'hi\' or \'hello\' to this bot, you will see two buttons below.",
            Images = new List<CardImage> { new CardImage("https://cloud.githubusercontent.com/assets/14900841/23733811/c618e402-042f-11e7-9b8e-6262d9f2d898.JPG") },
            Buttons = GenericButtonList
        };
        // create secret button that only users who said hi can see
        CardAction secretButton = new CardAction();
        secretButton.Title = "Very Polite";
        secretButton.Type = "openUrl";
        secretButton.Value = "https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers/ContosoFlowers.Services";
    
        if (sentGreeting)
        {
            Card.Buttons.Add(secretButton);
        }
    
    //创建新的问候语
    布尔森特问候;
    //从UserData.SentGreeting分配值
    context.UserData.TryGetValue(“SentGreeting”,out-SentGreeting);
    //创建标准按钮列表(适用于那些不欢迎机器人的人)
    var GenericButtonList=新列表
    {
    新的CardAction(ActionTypes.OpenUrl,“Bot框架”,值:https://docs.botframework.com/en-us/"),
    };
    //创建英雄卡
    var卡=新卡()
    {
    Title=“选择操作”,
    Subtitle=“从可用操作中选择”,
    Text=“如果您礼貌地对这个机器人说‘嗨’或‘你好’,您将看到下面的两个按钮。”,
    图像=新列表{新图像(“https://cloud.githubusercontent.com/assets/14900841/23733811/c618e402-042f-11e7-9b8e-6262d9f2d898.JPG") },
    按钮=通用按钮列表
    };
    //创建只有说“嗨”的用户才能看到的秘密按钮
    CardAction secretButton=新的CardAction();
    secretButton.Title=“非常礼貌”;
    secretButton.Type=“openUrl”;
    secretButton.Value=”https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers/ContosoFlowers.Services";
    如果(问候语)
    {
    卡片.按钮.添加(secretButton);
    }
    

链接到此bot的

您不能使用现成的WebChat启用/禁用。不过,您可能可以构建自定义WebChat并添加该功能

所有的魔法都发生在档案上。有一个函数,例如,在渲染时调用。该函数创建一个按钮并应用CSS类。您可以根据按钮的某些值动态更改类


顺便说一句,如果你能做到这一点,IMO,这可能是对WebChat组件的一个很好的贡献。

你想从哪些数据中得到提示?到目前为止你试过什么?您可以显示一些示例代码吗?我不想根据数据输入切换按钮的可见性(显示/隐藏)。我想根据输入数据启用/禁用按钮。按钮应始终存在,应根据数据值启用或禁用。