BotBuilder-Samples
BotBuilder-Samples copied to clipboard
[Question] CarouselCards issue with attachmentLayout.carousel
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)
Hi @mukeshzt ,
I believe you are using Skype, correct? Have you tested it on the Emulator?
Can you check the length of the options? How long is the HierarchyLevel2 field? And how many options are you printing on each card?
@mukeshzt If you are still having issues, please open a new issue on BotBuilder repo here: https://github.com/Microsoft/BotBuilder