2016-12-07 15 views
1

問題消息:ADD卡連接到使用Microsoft博特框架

  • 附加卡的響應對話,下面的代碼大多是由機器人樣品取,但不顯示在響應對話卡我使用的顯示邏輯的關鍵部分。

我在執行LUIS Intent任務時遇到了問題。

目標

  • 有一個用戶問一個問題,LUIS不承認,然後用卡的幫助,一旦代碼跳進負責處理無法識別的LUIS意圖的任務作出迴應。是否還有其他一些我可以考慮的幫助窗口結構,仍然使用卡片?

代碼

那裏有我的卡應該從

[LuisIntent("None")]  
public async Task NoneHandler(IDialogContext context, LuisResult result) { 
     string worriedFace = "\U0001F61F"; 
     string smilingFace = "\U0001F642"; 

     await context.PostAsync("I'm sorry, I didn't get that " + worriedFace + '.'); 
     await context.PostAsync("Here are some things I know how to talk about!" + smilingFace); 

     var message = context.MakeMessage(); 

     var attachment = new CardDialog().ReceiptCard(); 
     message.Attachments.Add(attachment); 

     await context.PostAsync(message); 
    } 

卡I'ved創建的視圖對象的類來顯示我試圖顯示。

namespace LUISBankingBot.Views 
{ 
    using System.Collections.Generic; 
    using Microsoft.Bot.Connector; 
    using Microsoft.Bot.Builder.Dialogs; 
    using System; 
    using System.Threading.Tasks; 

    public class CardDialog : IDialog<object> 
    { 
     public Task StartAsync(IDialogContext context) 
     { 
      throw new NotImplementedException(); 
     } 

     public Attachment ReceiptCard() 
     { 
      var receiptCard = new ReceiptCard 
      { 
       Title = "John Doe", 
       Facts = new List<Fact> { new Fact("Order Number", "1234"), new Fact("Payment Method", "VISA 5555-****") }, 
       Items = new List<ReceiptItem> 
       { 
        new ReceiptItem("Data Transfer", price: "$ 38.45", quantity: "368", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png")), 
        new ReceiptItem("App Service", price: "$ 45.00", quantity: "720", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png")), 
       }, 
       Tax = "$ 7.50", 
       Total = "$ 90.95", 
       Buttons = new List<CardAction> 
       { 
        new CardAction(
         ActionTypes.OpenUrl, 
         "More information", 
         "https://account.windowsazure.com/content/6.10.1.38-.8225.160809-1618/aux-pre/images/offer-icon-freetrial.png", 
         "https://azure.microsoft.com/en-us/pricing/") 
       } 
      }; 

      return receiptCard.ToAttachment(); 
     }   
    } 
} 
+0

而......你有什麼問題? –

+0

我正面臨的問題是將卡片附加到響應對話框中,下面的代碼大部分來自bot程序樣本,但在響應對話框中不顯示卡片。 –

+0

你使用哪個頻道? –

回答

3

一些事情。首先,當您嘗試添加附件時,您可能會收到null ref異常,因爲附件數組尚未初始化。

message.Attachments = new List<Attachment>(); 

此外,您不需要創建CardDialog。下面是一個可行的例子:

[LuisIntent("None")] 
    public async Task NoneHandler(IDialogContext context, LuisResult result) 
    { 
     string worriedFace = "\U0001F61F"; 
     string smilingFace = "\U0001F642"; 

     await context.PostAsync("I'm sorry, I didn't get that " + worriedFace + '.'); 
     await context.PostAsync("Here are some things I know how to talk about!" + smilingFace); 

     var message = context.MakeMessage(); 

     var receiptCard = new ReceiptCard 
     { 
      Title = "John Doe", 
      Facts = new List<Fact> { new Fact("Order Number", "1234"), new Fact("Payment Method", "VISA 5555-****") }, 
      Items = new List<ReceiptItem> 
      { 
       new ReceiptItem("Data Transfer", price: "$ 38.45", quantity: "368", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png")), 
       new ReceiptItem("App Service", price: "$ 45.00", quantity: "720", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png")), 
      }, 
      Tax = "$ 7.50", 
      Total = "$ 90.95", 
      Buttons = new List<CardAction> 
      { 
       new CardAction(
        ActionTypes.OpenUrl, 
        "More information", 
        "https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png", 
        "https://azure.microsoft.com/en-us/pricing/") 
      } 
     }; 

     message.Attachments = new List<Attachment>(); 
     message.Attachments.Add(receiptCard.ToAttachment()); 

     await context.PostAsync(message); 
    } 
+0

感謝您的反饋,讓它像魅力一般。現在我可以繼續我的項目! –