0

This issue only exists with the Converse API, when using the Webchat it works fine.

When checking the database the timestamp in ‘createdOn’ is the exact same for messages that are sent sequentially, which is the reason why the order is mixed up, e.g.:

  • The user is asked for an input
  • The Message that should be display after User Input is render
  • And only afterwards the user input is rendered

The strange thing is, when looking at the database, the createdOn property in the event column has a different timestamp than in the createdOn column, which is actually used to sort the events :

Event Column

//Dropdown Component that asks user for input
{""type"":""custom"",""channel"":""api"",""direction"":""outgoing"",""createdOn"":""2021-04-13T12:45:54.924Z""}
//Answer that is supposed to be displayed after user input
{""type"":""text"",""channel"":""api"",""direction"":""outgoing"",""createdOn"":""2021-04-13T12:46:02.645Z““}
//User Input
{""type"":""text"",""channel"":""api"",""direction"":""incoming"",""createdOn"":""2021-04-13T12:46:02.420Z""}

CreatedOn Column

//Dropdown Component
2021-04-13 12:45:55.243118+00 
//Message that should be displayed after User Input
2021-04-13 12:46:03.253342+00
//User Input
2021-04-13 12:46:03.253342+00

Is there any way to prevent this?

Nico
  • 157
  • 1
  • 15

1 Answers1

0

I don't think it's possible to prevent this in Botpress. From the events-table schema. The CreatedOn is created but Knex. But the event column is a JSON value. I didn't find the reference where the event column is inserted in the database or was correspondent to the event.createdOn value.

I was curious and I try with the Channel-web module. The timestamp difference also appends with the channel-web module.

Frontend Post request

Initial payload

curl 'http://localhost:3001/api/v1/bots/weather/mod/channel-web/messages?__ts=1625757442879' 
-H 'Accept: application/json, text/plain, */*' 
-H 'Authorization: Bearer {{BEARER_TOKEN}}' 
--data-raw '{"webSessionId":"/guest#S9UoXB2NuDfySWqgAAAK","conversationId":7,"payload":{"type":"text","text":"hello"}}'

Database table events

sqlite> sqlite> select event,createdOn from events where botId = 'weather';

I transform the event column to a readable format with JQ

jq .createdOn,.payload
"2021-07-08T15:17:22.888Z"
{
  "type": "text",
  "text": "hello"
}

The createdOn Column (not in the event column)

2021-07-08T15:17:23.456Z

Trigger on insert

You can create a trigger on inserted value. This post explain how to do it with a JSON column value (like to event column).