用于团队渲染英雄卡轮播的微软机器人

microsoft bot for teams to render a carousel of hero cards

我有下面的代码来渲染多张英雄卡

 const hcard = CardFactory.heroCard(
            'Neeti Sharma',
            'CEO, Moblize.it LLC',
            null,
            [
                {
                    type: ActionTypes.MessageBack,
                    title: 'Call',
                    value: null,
                    text: 'UpdateCardAction'
                },
                {
                    type: ActionTypes.MessageBack,
                    title: 'Email',
                    value: null,
                    text: 'email'
                }
            ]);
        await context.sendActivity({ attachments: [hcard, hcard] });

这会渲染一张又一张卡片。我如何将其转换为轮播?

您需要获取所有附件,将它们附加到您要发送的回复中,并将附件布局设置为Carousel。以下是实现此目标的方法:

var reply=activity.CreateReply();

reply.attachment=GetAttachments();

reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

只是为了别人的利益,我现在就是这样做的

 const hcard = CardFactory.heroCard(
                card._firstName + ' ' + card._lastName,
                card._jobTitle + ', ' + card._dept,
                null,
                [
                    {
                        type: ActionTypes.MessageBack,
                        title: 'Call',
                        value: null,
                        text: 'UpdateCardAction'
                    },
                    {
                        type: ActionTypes.MessageBack,
                        title: 'Email',
                        value: null,
                        text: 'email'
                    }
                ]);

                cardArr.push(hcard)
         }

         console.log("all the cards are::::" + JSON.stringify(rspVal))
         const reply = {
             "attachments" : cardArr,
             "attachmentLayout" : AttachmentLayoutTypes.Carousel
         }

        await context.sendActivity(reply);