Botframework-sdk: [Welcome Message] How to send Hero card without access to session object on conversationUpdate event?

Created on 17 Jan 2018  路  2Comments  路  Source: microsoft/botframework-sdk

Bot Info

  • SDK Platform: Node.js
  • Active Channels: FB, Skype, Directline
  • Deployment Environment: Azure Bot Service

Issue Description

I am looking to send a new Hero card to the user on conversation update as a welcome.

I could compose one without session using the attached code.

My issue is that Bot.send is not able to send the hero card. only session.send can. and on conversation update, there is no session.

Code Example

//send Hi to user
Bot.on('conversationUpdate', function (message) {
    if (message.membersAdded && message.membersAdded.length > 0) {
        // Say hello
        var isGroup = message.address.conversation.isGroup;
        var txt = isGroup ? "Hello everyone!" : "Hello...";
//        var reply = new Builder.Message()
   //             .address(message.address)
      //          .text(txt);

        Bot.beginDialog('sayHi'); // ends up in invalide address
         var msg = card(null);
         Bot.send(msg);// throws conversation id not availble error
          session,send(msg); //works but dont have a session here
    } 
});

//Hi dialog test
Bot.dialog('sayHi', [
    function (session) {
        console.log("hi dialog");
       sendWelcome(session);
    },
    function (session, results) {
        session.endDialogWithResult(results);
    }
]);


function card(session){
    var demoCard = createHeroCard();
    var msg = new Builder.Message(null).addAttachment(demoCard);
    session.send(msg); // i dont have session when i call from conversation update
}

//creates a card
function createHeroCard() {
    return new Builder.HeroCard()
        .title('some title')
        // .subtitle('')
        .text('some welcome message.')
        .images([
            Builder.CardImage.create(null, 'some image url')
        ])
        .buttons([
            Builder.CardAction.imBack(null, 'some return text', 'some button text')
        ]);

}

Reproduction Steps

  1. Use the above code.

Expected Behavior

Send hero card using bot.send() or able to start call beginDialog() from conversation update.

Actual Results

All errors I get is kept as a comment in the code itself.

Is there any other way to do this? I could do the same in C# and it worked.
Thanks in Advance

Most helpful comment

Hi

I'm able to send a hero card on conversationUpdate like this:

      Bot.send(new builder.Message()
                    .address(message.address)
                    .addAttachment(new builder.HeroCard()
                        .text('Hero card text')
                        .buttons([
                            builder.CardAction.imBack(null, 'some return text', 'some button text')
                        ])));

I'd like to know if there's a better way to handle the address in the CardAction than setting it to null.

Thanks

All 2 comments

Hi

I'm able to send a hero card on conversationUpdate like this:

      Bot.send(new builder.Message()
                    .address(message.address)
                    .addAttachment(new builder.HeroCard()
                        .text('Hero card text')
                        .buttons([
                            builder.CardAction.imBack(null, 'some return text', 'some button text')
                        ])));

I'd like to know if there's a better way to handle the address in the CardAction than setting it to null.

Thanks

@maryjanem That Worked! :D thank you...

Bit more improvised code with an image.

  Bot.send(new Builder.Message()
            .address(message.address)
            .addAttachment(new Builder.HeroCard()
                .title('Title text')
                .text('some text')
                .images([
                    Builder.CardImage.create(null, 'image url')
                ])
                .buttons([
                    Builder.CardAction.imBack(null, 'action text', 'button text')
                ])));
Was this page helpful?
0 / 5 - 0 ratings