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

Creating a function which returns an array of ThumbnailCards

Open KwstasBol opened this issue 9 years ago • 1 comments

  • SDK Platform: Node.js

Issue Description

I am using foursquare-venues and i want to make 5 different cards with each one being a different Thumbnail Card, having their own image and button. However, all i achieved was only one card with the last venue i got.

Code Example

function createMultipleButtons(session,places){
    var builderas=new builder.ThumbnailCard(session);
    var card=[];
    for(var i=0;i<5;i++){
     builderas
    .buttons([ builder.CardAction.postBack(session,places[i].name,places[i].name)])
    .images([builder.CardImage.create(session,places[i])])
    card.push(builderas);
    }
    return card; /

}
//Invoking the function
 var msg=new builder.Message(session);
            msg.attachmentLayout(builder.AttachmentLayout.carousel);
            msg.attachments([
               createMultipleButtons(session,places)
            ]); 
            builder.Prompts.text(session,msg);
            });

Expected Behavior

Like this one but with the places found from using Foursquare Api ( places) image

Actual Results

image

KwstasBol avatar Oct 30 '17 00:10 KwstasBol

You're only declaring var builderas=new builder.ThumbnailCard(session); once, outside of your loop, so in each loop iteration, you're just modifying the reference to the same original card. You need to instantiate a new card inside each iteration, then you'll see the expected result.

sphanley avatar Oct 30 '17 02:10 sphanley