c# - 未显示缩略图卡的 MS Teams 轮播
问题描述
我正在尝试使用我的 Bot Framework 授权机器人在 MS Teams 上以轮播形式显示卡片列表。轮播在 Web Chat 和模拟器上正确显示,但在 Teams 上却没有。什么都没有显示。正在调用实现代码的方法,其他一切都很完美。
代码:
var reply = context.MakeMessage();
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
List<Attachment> attachments = new List<Attachment>();
foreach (Models.Cars car in cars)
{
Attachment att = new Attachment();
List<CardAction> buttons = new List<CardAction>();
CardAction button = new CardAction(ActionTypes.PostBack, "Show car", value : car.id);
buttons.Add(button);
var heroCard = new ThumbnailCard
{
Title = car.Title ?? "",
Subtitle = car.Model ?? "2",
Text = $"{car.Description}" ?? $"Text is not available for this car.",
Images = null,
Buttons = buttons
};
att = heroCard.ToAttachment();
attachments.Add(att);
}
reply.Attachments = attachments;
await context.Wait(AfterIDInsert);
IDInsert 调用后:
private async Task AfterIDInsert(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var carid= await result;
await showcar(context, carid.Text);
}
解决方案 感谢 JasonSowers 的回答,我能够找出问题所在。显然 MS Teams 需要在 CardAction 中填写比其他通道(我检查过的机器人模拟器)更多的(所有)参数。
使用 JasonSowers 的代码并更改此行:
CardAction button = new CardAction(ActionTypes.PostBack,displayText:car.Title,title: "Show car", image: null, value: car.Id);
为我解决了这个问题。
解决方案
我对您的代码进行了一些更改以尝试一些事情并使其与下面的代码一起使用。似乎解决它的是这条线
CardAction button = new CardAction(ActionTypes.PostBack, "Show car",image : null, value: car.Id);
我认为这些属性在团队或类似的情况下被乱序读取,因此明确设置value: car.Id
似乎可以解决问题
var activity = await result as Activity;
var reply = activity.CreateReply();
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
List<Attachment> attachments = new List<Attachment>();
List<Cars> cars = new List<Cars> {
new Cars("This is a cool car", "car1"," title1", "1"),
new Cars("This is an awesome car", "car2", " title2", "2"),
new Cars("This is the best car", "car3", " title3", "3"),
new Cars("This is the worst car", "car4", " title4", "4"),
new Cars("This is amazing", "car5"," title5", "5")
};
foreach (Cars car in cars)
{
List<CardAction> buttons = new List<CardAction>();
CardAction button = new CardAction(ActionTypes.PostBack, "Show car", value: car.Id);
buttons.Add(button);
var heroCard = new ThumbnailCard
{
Title = car.Title ?? "",
Subtitle = car.Model ?? "2",
Text = $"{car.Description}" ?? $"Text is not available for this car.",
Buttons = buttons
};
;
attachments.Add(heroCard.ToAttachment());
}
reply.Attachments = attachments;
try
{
await context.PostAsync(reply);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
还有这门课
public class Cars
{
public Cars( string description, string model, string title, string id)
{
Id = id;
Description = description;
Model = model;
Title = title;
}
public string Id { get; set; }
public string Title { get; set; }
public string Model { get; set; }
public string Description { get; set; }
}
推荐阅读
- qt - 错误:“QModelIndex 类”没有名为“siblingAtColumn”的成员
- kotlin - RxJava: Issue with withLatestFrom operator when using in combination with .subScribeOn
- swift - How to deal with NaN in large arrays using swift
- jmeter - 仪表板报告 - 事务/秒
- c - 为什么要为同名的函数定义宏?
- pandas - 将第二个条目保留在数据框中
- vector - 如何将两个 Rust 向量交织成一个新向量?
- http - 单页应用程序的简单命令行 http 服务器
- javascript - How to create a different random number for every single div with React on onclick event?
- javascript - 绝对定位一个 div 并隐藏页面的其余部分