External chatbot - How to force messages order?

Hi guys, I’m developing an external chatbot and everything works fine.
I just noted that sometimes my messages do not arrive in the same order I sent them from my chatbot application.

Just to clarify, I used this tutorial to create my chatbot application:

I send messages like this:

let msg1 = {
text: ‘First message’
}
let msg2 = {
text: ‘Oldest message, is reordered’
}
}
tdclient.sendMessage(msg1);
tdclient.sendMessage(msg2);

What I experience is that sometimes I receive messages in opposite order, mesg2 before message 1.

There is a way to “force” the the same sending order?

Hi Alex.

You can use the parameter attributes.clienttimestamp to force the message timestamp to your server-side timestamp.
Example:

 let msg1 = {
    text: 'First message',
    attributes: {
      'clienttimestamp': Date.now()
    }
  }
  let msg2 = {
    text: 'Oldest message, is reordered',
    attributes: {
      'clienttimestamp': Date.now()
    }
  }
  tdclient.sendMessage(msg1);
  tdclient.sendMessage(msg2);

In this way, the Web Widget and all the other native Tiledesk Clients will reorder the messages based on the clienttimestamp attributes of the single messages.

You can find here a Replit example on how to manually reorder the messages to demonstrate the clienttimestamp property: