2016-08-01 79 views
2

我試圖使用來自Microsoft的bot框架來實現bot。我跟着文檔,但它似乎並沒有正確添加按鈕。在Skype上,它顯示了一種縮略圖,可以打開到Skype的下載頁面。在Facebook Messenger上,它沒有顯示任何內容。將按鈕添加到機器人框架應用程序

有什麼建議嗎? 謝謝!

+0

你使用formflow或對話框? – blueprintChris

回答

0

是的,你可以實現添加一個自定義按鈕,它將在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> 

不要讓我知道的情況下,你需要任何幫助

相關問題