将按钮添加到机器人框架应用程序

问题描述:

我试图使用来自Microsoft的bot框架来实现bot。我跟着文档,但它似乎并没有正确添加按钮。在Skype上,它显示了一种缩略图,可以打开到Skype的下载页面。在Facebook Messenger上,它没有显示任何内容。将按钮添加到机器人框架应用程序

有什么建议吗? 谢谢!

+0

你使用formflow或对话框? – blueprintChris

是的,你可以实现添加一个自定义按钮,它将在bot框架的每个通道上工作。

有两种方法可以实现: 1)使用Bot的Cards功能来获取按钮。 (快速且简单) 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

直达线路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 = "[email protected]"; 
     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> 

不要让我知道的情况下,你需要任何帮助