如何防止消息在 BotFramework Nodejs 中乱序到达?

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

我正在使用 azure 机器人框架。我想在第一条消息发送后才发送第二条消息。

这是代码。

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

这里发一次"Hi"然后我只想发英雄卡
但有时我遇到的问题是先寄出卡片,然后再寄出 "Hi" 我尝试设置定时器(settimeout)。但这没有意义。它有时也会失败。

有什么方法可以识别那个或类似 callback/promise 的东西吗?我不确定如何为这种情况实施相同的操作?

尝试发送您的 HeroCard,方法是在您发送第一封邮件后将其创建为第二封邮件的附件。它应该看起来像这样:

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);

您也可以单独构建 HeroCard(在此代码块之前或调用其他构建器函数时),然后在发送后续消息时将其作为附件添加。以这种方式发送应该可以防止消息乱序到达。