Selva Feliz
Selva Feliz

Reputation: 91

How do I prevent messages from arriving out of order in BotFramework Nodejs?

I am using azure bot framework. I want to send a second message only after the first has been sent.

Here is the code.

session.send("Hi")
   response=store.getRating();
   cards.Herocard(session,builder,response,function(msg){
      sendCard(msg,session);         
  }); 

Here once "Hi" is sent then only i wanted to send the hero card.
But sometimes i am facing issues like card is being sent out first and then followed by "Hi" I try setting timer(settimeout). But that doesn't make sense. It also fails sometime.

Is there any way to identify that or something like a callback/promise. I am not sure how to implement the same for this scenario?

Upvotes: 1

Views: 249

Answers (1)

Mark B
Mark B

Reputation: 581

Try sending your HeroCard by creating it as an attachment to a second message after you've send the first one. It should look something like this:

session.send('Hi');
var followup = new builder.Message(session);
followup.attachments([
        new builder.HeroCard(session)
        .title("Hi")
        .subtitle("I'm a herocard")
        .text("i do stuff "+ session.message.text)
]);
session.send(followup);

You can also build the HeroCard separately (before this code block or in a call to some other builder function) and just add it in as an attachment when you're sending the followup message. Sending it this way should prevent the messages from arriving out of order.

Upvotes: 1

Related Questions