botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

CarouselCards issue with attachmentLayout.carousel

Open mukeshps25 opened this issue 9 years ago • 5 comments

Below code only show the hero card listing but not the attachmentLayout.carousel.


function CreateHeroCard(session, builder, title, subtitle, text, url, buttons){
    var card = new builder.HeroCard(session)
        .title(title)
        .subtitle(subtitle)
        .text(text)     
        .images([builder.CardImage.create(session, url)])
        .buttons(buttons);      
    return card;
}

function SendHeroCard(session, builder){
     var request = require("request");
    var url = 'http://example.com/fetch/' + session.userData.profile.userToken + '/' + session.userData.profile.Level1;
    request(url, function (error, response, body)
    {
        if (!error && response.statusCode == 200) {
            var attachmentsArr = [];
            var attachmentsChoice = [];
            var jsondata = parseJson(body);
            var nextLevel = treeRoot.first(function (node) {
                return node.model.attributes.id === session.userData.profile.treeSelectdNodeId; // 1.1
            });
            for (var i = 0; i < jsondata.length; i++) {
                var secondListChild = [];
                if(nextLevel.model.children.length > 0) { 
                    for (var j = 0; j < nextLevel.model.children.length; j++) {
                        if (nextLevel.model.children[j].attributes.title != '' && nextLevel.model.children[j].attributes.title != undefined) {
                            secondListChild.push(builder.CardAction.imBack(session, nextLevel.model.children[j].attributes.id+":"+ jsondata[i].HierarchyLevel2, nextLevel.model.children[j].attributes.title));
                        }
                        attachmentsChoice.push(nextLevel.model.children[j].attributes.id+":"+ jsondata[i].HierarchyLevel2);
                    }
                    secondListChild.push(builder.CardAction.imBack(session, "previous menu", "previous menu"));
                }
                var card = CreateHeroCard(session, builder, jsondata[i].HierarchyLevel2, "RITS Builder Result", "", "http://hsplbot.headfitted.in/images/RockwellLogo3.png", 
                secondListChild);
                attachmentsArr.push(card);
                
            }
            var reply = new builder.Message(session)
                    .textFormat(builder.TextFormat.xml)
                    //.attachmentLayout(builder.AttachmentLayout.carousel)
                    .attachments(attachmentsArr);
            //session.send(reply);
            builder.Prompts.choice(session, reply, attachmentsChoice);
        } 
    });
};

If you review my code. I commented //.attachmentLayout(builder.AttachmentLayout.carousel)

If you remove the comment of this line below error received in bot node

Error: Request to 'https://smba.trafficmanager.net/v3/conversations/29%3A1z7akAj7gyQq-8N4O-hkjHHJHGKJsdsd/activities' failed: [400] Bad Request
    at Request._callback (/home/node_modules/botbuilder/lib/bots/ChatConnector.js:413:46)
    at Request.self.callback (/home/node_modules/request/request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/home/node_modules/request/request.js:1081:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (/home/node_modules/request/request.js:1001:12)
    at IncomingMessage.g (events.js:291:16)
    at emitNone (events.js:91:20)


mukeshps25 avatar Feb 14 '17 10:02 mukeshps25

One of the CarouselCards Example BotBuilder-Samples there is one note is mention.

Note: At the time of writing this sample, there is a limit on the amount of cards that can be stacked in a carousel. For Facebook, attachments carousel is mapped to the Generic Template which has a limit of 10 elements. For Skype, there's also a limit of 10 elements in the carousel.

mukeshps25 avatar Feb 14 '17 12:02 mukeshps25

@mukeshzt can we use CarouselCards in Slack??

aakashkag avatar Feb 14 '17 12:02 aakashkag

CarouselCards are displayed as list of cards in slack. You can look at channel inspector for different capabilities in different channels: https://docs.botframework.com/en-us/channel-inspector/channels/Slack/#navtitle

msft-shahins avatar Feb 14 '17 19:02 msft-shahins

Thank You so much :)

aakashkag avatar Feb 15 '17 04:02 aakashkag

Answer for my above error is " For Skype, there's also a limit of 10 elements in the carousel."

mukeshps25 avatar Feb 16 '17 07:02 mukeshps25