C# 向bot框架应用程序添加按钮

C# 向bot框架应用程序添加按钮,c#,botframework,C#,Botframework,我正在尝试使用微软的bot框架实现一个bot。我遵循了文档,但似乎没有正确添加按钮。在skype上,它显示一种打开skype下载页面的缩略图。在facebook messenger上,它没有显示任何内容 有什么建议吗? 谢谢大家! 是的,您可以添加一个自定义按钮,该按钮将在bot框架的每个通道上工作 实现这一目标有两种方法: 1) 使用Bot的卡片功能获取按钮。(快速简便) 2) 使用direct Line频道并添加自定义按钮。(复杂) 让我们从方法1开始 您需要创建一张英雄卡,并在对话框中调用

我正在尝试使用微软的bot框架实现一个bot。我遵循了文档,但似乎没有正确添加按钮。在skype上,它显示一种打开skype下载页面的缩略图。在facebook messenger上,它没有显示任何内容

有什么建议吗?
谢谢大家!

是的,您可以添加一个自定义按钮,该按钮将在bot框架的每个通道上工作

实现这一目标有两种方法: 1) 使用Bot的卡片功能获取按钮。(快速简便) 2) 使用direct Line频道并添加自定义按钮。(复杂)

让我们从方法1开始

您需要创建一张英雄卡,并在对话框中调用它。英雄卡包含来自机器人和缩略图url的文本响应。(如果不需要,可以删除缩略图)。下面是您的帮助的运行代码

public async Task StartAsync(IDialogContext context)
        {
            context.Wait(ImgCardResponse);
        }

        private async Task ImgCardResponse(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            var message = await argument;

            //responseMsgOnly is used to pass bot reply message
            //responseImage is used to pass thumbnail image
            var attachment = BotButtonCard(responseMsgOnly, responseImage);
            cardMsg.Attachments.Add(attachment);
            await context.PostAsync(cardMsg);



        }
        private static Attachment BotButtonCard(string responseMsgOnly, string responseImage)
        {
            var heroCard = new HeroCard
            {
                Title = "Here we go with the response",
                Subtitle = "Subtitle goes here",
                Text = responseMsgOnly,
                Images = new List<CardImage>
                {
                    new CardImage(responseImage)
                }
                Buttons = new List<CardAction>
                {
                    new CardAction(ActionTypes.OpenUrl, "Your Button Label", value: "https://www.google.com")
                }
            };

            return heroCard.ToAttachment();
        }
        private async Task ResumeAfterAction(IDialogContext context, IAwaitable<object> result)
        {
            context.Done(new object());
        }
公共异步任务StartAsync(IDialogContext上下文)
{
Wait(ImgCardResponse);
}
专用异步任务ImgCardResponse(IDialogContext上下文,IAwaitable参数)
{
var message=等待参数;
//responseMsgOnly用于传递bot回复消息
//responseImage用于传递缩略图图像
var附件=BotButtonCard(responseMsgOnly,responseImage);
cardMsg.Attachments.Add(附件);
wait context.PostAsync(cardMsg);
}
专用静态附件BotButtonCard(仅字符串响应mssgonly、字符串响应图像)
{
var heroCard=新heroCard
{
Title=“我们开始回复”,
Subtitle=“Subtitle在此显示”,
Text=仅响应msg,
图像=新列表
{
新CardImage(responseImage)
}
按钮=新列表
{
新的CardAction(ActionTypes.OpenUrl,“您的按钮标签”,值:https://www.google.com")
}
};
返回heroCard.ToAttachment();
}
专用异步任务ResumeAfterAction(IDialogContext上下文,IAwaitable结果)
{
context.Done(新对象());
}
让我们从方法2开始

Direct Line API是一个简单的REST API,用于直接连接到单个机器人。此API适用于编写自己的客户端应用程序、web聊天控件或移动应用程序的开发人员,这些应用程序将与他们的机器人进行对话。Direct Line v3.0 Nuget包简化了对底层REST API的访问

您需要创建一个html页面并输入以下代码

头部部分

<link href="../botchat.css" rel="stylesheet"/>
    <script src="../js/botchat.js"></script>
<div id="bot"></div>
<script>

    var FirstName;
    var emailaddress; 
    var Environment;
    try{

        FirstName =  _spPageContextInfo.userDisplayName;
        emailaddress = "manoj.resources@resources.in";
        Environment= _spPageContextInfo.webAbsoluteUrl ;
    }
    catch(ex)
    {
        spCOntext = 'You';
        Environment = 'Local System';

    }

    BotChat.App({

        directLine: { secret: 'Your direct line secret' },

        user: { id: FirstName,Name: Environment},
        name: spCOntext,
        value: FirstName,
        From: '',
        bot: { id: 'Bot ID' },
        resize: 'detect'
    }, document.getElementById("bot"));

</script>

身体部位

<link href="../botchat.css" rel="stylesheet"/>
    <script src="../js/botchat.js"></script>
<div id="bot"></div>
<script>

    var FirstName;
    var emailaddress; 
    var Environment;
    try{

        FirstName =  _spPageContextInfo.userDisplayName;
        emailaddress = "manoj.resources@resources.in";
        Environment= _spPageContextInfo.webAbsoluteUrl ;
    }
    catch(ex)
    {
        spCOntext = 'You';
        Environment = 'Local System';

    }

    BotChat.App({

        directLine: { secret: 'Your direct line secret' },

        user: { id: FirstName,Name: Environment},
        name: spCOntext,
        value: FirstName,
        From: '',
        bot: { id: 'Bot ID' },
        resize: 'detect'
    }, document.getElementById("bot"));

</script>

var名字;
var电子邮件地址;
var环境;
试一试{
FirstName=\u spPageContextInfo.userDisplayName;
emailaddress=“manoj。resources@resources.in";
环境=_spPageContextInfo.webAbsoluteUrl;
}
捕获(ex)
{
spCOntext='You';
环境=‘本地系统’;
}
BotChat.App({
directLine:{secret:'您的直连密码'},
用户:{id:FirstName,Name:Environment},
名称:spCOntext,
值:FirstName,
从:“”,
机器人:{id:'bot id'},
调整大小:“检测”
},document.getElementById(“bot”);

如果您需要帮助,请务必告诉我

您使用的是formflow还是dialogs?