【问题标题】:Adding buttons to bot framework application向机器人框架应用程序添加按钮
【发布时间】:2016-12-06 11:13:56
【问题描述】:

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

有什么建议吗? 谢谢!

【问题讨论】:

  • 您使用的是表单流还是对话框?

标签: c# botframework


【解决方案1】:

是的,您可以添加一个自定义按钮,该按钮适用于机器人框架的每个通道。

有两种方法可以实现: 1)使用Bot的卡片功能获取按钮。 (快捷方便) 2)使用直接线路通道并添加您的自定义按钮。 (复杂)

让我们从方法 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());
        }

让我们从方法 2 开始

Direct Line API 是一个简单的 REST API,用于直接连接到单个机器人。此 API 适用于编写自己的客户端应用程序、网络聊天控件或与机器人对话的移动应用程序的开发人员。 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>

如果您需要任何帮助,请告诉我

【讨论】:

    猜你喜欢
    • 2012-03-14
    • 2013-06-10
    • 1970-01-01
    • 2017-08-04
    • 2018-07-01
    • 2017-04-11
    • 2014-01-03
    • 1970-01-01
    • 2015-10-14
    相关资源
    最近更新 更多