2017-02-13 32 views
0

我已經實現了一個向用戶發送英雄卡作爲響應的bot。 正如我所料,以下代碼將傳送帶發送給信使。Carousel Card在Facebook Messenger的BotFramework中運行不正常

ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 

#region HeroCard 
Activity replyToConversation = activity.CreateReply("Should go to conversation, with a hero card"); 
replyToConversation.Recipient = activity.From; 
replyToConversation.Type = "message"; 
replyToConversation.Attachments = new List<Attachment>(); 
List<CardImage> cardImages = new List<CardImage>(); 
cardImages.Add(new CardImage(url: "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png")); 
cardImages.Add(new CardImage(url: "https://upload.wikimedia.org/wikipedia/en/archive/a/a9/20151112035044!Banyan_Tree_(_Shiv_Bajrang_Dham_Kishunpur).jpeg")); 
List<CardAction> cardButtons = new List<CardAction>(); 
CardAction plButton = new CardAction() 
{ 
    Value = "https://en.wikipedia.org/wiki/Pig_Latin", 
    Type = "openUrl", 
    Title = "WikiPedia Page" 
}; 
CardAction plButton2 = new CardAction() 
{ 
    Value = "https://en.wikipedia.org/wiki/Pig_Latin", 
    Type = "openUrl", 
    Title = "WikiPedia Page" 
}; 
cardButtons.Add(plButton); 
cardButtons.Add(plButton2); 
HeroCard plCard = new HeroCard() 
{ 
    Title = "I'm a hero card", 
    Subtitle = "Pig Latin Wikipedia Page", 
    Images = cardImages, 
    Buttons = cardButtons 
}; 
Attachment plAttachment = plCard.ToAttachment(); 
replyToConversation.Attachments.Add(plAttachment); 
var reply = await connector.Conversations.SendToConversationAsync(replyToConversation); 
#endregion 

但是,我得到了下面的消息,這不是一個傳送帶。 enter image description here

問題是我該如何使用botframework的本機變量(不使用手動生成的json)向Facebook Messenger發送輪播?

回答

0

的問題是解決了這些變化:

  • 首先,創建兩個卡和附件
  • 二,設置AttachmentLayout"carousel"

您可以在以下修改後的代碼:

ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 

#region HeroCard 

Activity replyToConversation = activity.CreateReply("Should go to conversation, with a hero card"); 
replyToConversation.Recipient = activity.From; 
replyToConversation.Type = "message"; 
replyToConversation.Attachments = new List<Attachment>(); 
// First Change 
// Card #One 
List<CardImage> cardImages1 = new List<CardImage>(); 
cardImages1.Add(new CardImage(url: "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png")); 

List<CardAction> cardButtons1 = new List<CardAction>(); 
CardAction plButton1 = new CardAction() 
{ 
    Value = "https://en.wikipedia.org/wiki/Pig_Latin", 
    Type = "openUrl", 
    Title = "WikiPedia Page" 
}; 
cardButtons1.Add(plButton1); 
HeroCard plCard1 = new HeroCard() 
{ 
    Title = "I'm a hero card", 
    Subtitle = "Pig Latin Wikipedia Page", 
    Images = cardImages1, 
    Buttons = cardButtons1 
}; 
Attachment plAttachment1 = plCard1.ToAttachment(); 
replyToConversation.Attachments.Add(plAttachment1); 

// Card #Two 
List<CardImage> cardImages2 = new List<CardImage>(); 
cardImages2.Add(new CardImage(url: "https://upload.wikimedia.org/wikipedia/en/archive/a/a9/20151112035044!Banyan_Tree_(_Shiv_Bajrang_Dham_Kishunpur).jpeg")); 

List<CardAction> cardButtons2 = new List<CardAction>(); 
CardAction plButton2 = new CardAction() 
{ 
    Value = "https://en.wikipedia.org/wiki/Pig_Latin", 
    Type = "openUrl", 
    Title = "WikiPedia Page" 
}; 
cardButtons2.Add(plButton2); 
HeroCard plCard2 = new HeroCard() 
{ 
    Title = "I'm a hero card", 
    Subtitle = "Pig Latin Wikipedia Page", 
    Images = cardImages2, 
    Buttons = cardButtons2 
}; 

Attachment plAttachment2 = plCard2.ToAttachment(); 
replyToConversation.Attachments.Add(plAttachment2); 

// Second Change 
replyToConversation.AttachmentLayout = "carousel"; 

var reply = await connector.Conversations.SendToConversationAsync(replyToConversation); 
#endregion 

你可以找到旋轉木馬的形象透過Facebook Messenger在下面: enter image description here