MS Teams旋转木马,没有显示缩略图卡片

时间:2018-05-15 12:15:55

标签: c# botframework

我正在尝试使用我的Bot Framework授权的机器人在MS团队中获得显示为旋转木马的卡片列表。 轮播在Web Chat和模拟器上正确显示,而不是在团队中。什么都没有显示出来。正在调用实现代码的方法,其他一切工作都很完美。

代码:

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);

AfterIDInsert电话:

private async Task AfterIDInsert(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            var carid= await result;
            await showcar(context, carid.Text);
        }

解决方案 感谢JasonSowers的回答,我能够找出问题所在。显然,MS团队需要使用比其他通道更多(所有)参数的CardAction(我检查过的bot模拟器)。

使用JasonSowers的代码并更改此行:

CardAction button = new CardAction(ActionTypes.PostBack,displayText:car.Title,title: "Show car", image: null, value: car.Id);

为我解决了这个问题。

1 个答案:

答案 0 :(得分:2)

我对您的代码进行了一些更改以尝试一些事情并使用下面的代码。似乎解决了这条线

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; }

}