[英]Hero Card not showing in Bot framework's emulator
我是Bot Framework的新手,我使用C#編寫了一個簡單的漫游器,該漫游器應返回示例英雄卡作為回復。 問題在於,Hot卡未在Bot Framework通道仿真器中顯示。 這是代碼:
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> arg)
{
var referenceMessage = await arg as IMessageActivity;
var msg = (Activity)context.MakeMessage();
Activity replyToConversation = msg.CreateReply($"Buscando resultados para {referenceMessage.Text}");
replyToConversation.Recipient = msg.From;
replyToConversation.Type = "message";
replyToConversation.ReplyToId = referenceMessage.Id;
replyToConversation.AttachmentLayout = "carousel";
replyToConversation.Attachments = new List<Attachment>();
List<CardImage> CardImages = new List<CardImage>();
CardImages.Add(new CardImage()
{
Url = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/be/BMW-Z4_diagonal_front_at_IAA_2005.jpg/243px-BMW-Z4_diagonal_front_at_IAA_2005.jpg"
});
CardAction btnWebsite = new CardAction()
{
Type = "openUrl",
Title = "Open",
Value = "http://bmw.com"
};
HeroCard plCard = new HeroCard()
{
Title = $"{referenceMessage.Text}",
Subtitle = $"Resultados de busqueda para {referenceMessage.Text}",
Images = CardImages,
Tap = btnWebsite
};
var attachment = plCard.ToAttachment();
replyToConversation.Attachments.Add(attachment);
await context.PostAsync(replyToConversation);
//var connector = new ConnectorClient(new Uri(msg.ServiceUrl));
//var reply = connector.Conversations.SendToConversationAsync(replyToConversation);
}
如您所見,我一直在嘗試使用上下文和連接器,但卡未顯示。我已經調試了應用程序,並且可以看到輸入信息已被正確捕獲
有什么想法嗎?
我將發布您可能的解決方案。
*如果您的函數在某些IDialog類中,並且如果您期望某些結果應如下所示:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
*第二個解決方案(如果我是您,我會用它)是從當前上下文創建一條消息。 所以你的代碼應該是:
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> arg)
{
var replyToConversation= context.MakeMessage();
replyToConversation.AttachmentLayout = "carousel";
replyToConversation.Attachments = new List<Attachment>();
List<CardImage> CardImages = new List<CardImage>();
CardImages.Add(new CardImage()
{
Url = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/be/BMW-Z4_diagonal_front_at_IAA_2005.jpg/243px-BMW-Z4_diagonal_front_at_IAA_2005.jpg"
});
CardAction btnWebsite = new CardAction()
{
Type = "openUrl",
Title = "Open",
Value = "http://bmw.com"
};
HeroCard plCard = new HeroCard()
{
Title = $"{referenceMessage.Text}",
Subtitle = $"Resultados de busqueda para {referenceMessage.Text}",
Images = CardImages,
Tap = btnWebsite
};
var attachment = plCard.ToAttachment();
replyToConversation.Attachments.Add(attachment);
await context.PostAsync(replyToConversation);
}
注意 :
代替
replyToConversation.AttachmentLayout = "carousel",
采用
replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
希望能幫助到你 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.