-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): messaging api #4340
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this! Let's wait for @allardy to test with your telegram port then we're good !
Conversation and message ids are now uuids instead of auto increment integers. I did some benchmarks to test if there was a difference in performance and to my surprise it wasn't noticeable at all. In fact it comes within the margin of error compared to integers. Here are some benchmarks I did using the sdk directly (100 000 users, 2 000 000 messages) Create 100 000 users, create a converation for each and add 20 messages in each conversations
For every user, get the most recent conversation
For 1/10 of the users, get the most recent conversation. Then loop back and get the most recent conversations again 20 times (to test caching)
For every user, get the most recent conversation and all of its messages
I didn't see much of a difference on sqlite either. From what I've researched it's possible it doesn't scale as well with very large amounts of data. For example sqlite implements the field as a char(36). I think many other database handle uuids like that, however postgres actually has a builtin type for uuids. They are handled as 128 bit integers so the concerns for performance are probably not really justified. It's still worth considering options like in this article exist but I don't think it's really needed. The only drawback to uuids in node is that they are represented in strings instead of 128 bit integers. So you get way more memory usage when stored in the cache. I also thought having a string as an id migth mislead sdk users to think they can put in anything as an id, so I created a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're good to go !
The messaging API is meant to make it easier to send messages by abstracting some stuff from the events system. It also records a list of messages and conversations in its own tables. The goal is to move the behavior from the web channel to a more generic one in the core. This will allow, for example, to remove de dependency that the new hitl module has on the channel-web module.
Usage
Basic message sending
{userId, botId}
being a user endpointThe api remembers the last channel used by a user, so if you want to programmatically send a message you don't need to know the channel (as shown above).
However you will need to specify the channel in the args if you are programming a channel module. So for example the web channel does something like this :
Sending a message and specifying the channel of origin
It uses the optionnal
args
parameter to provide additionnal parameters to the event constructor. In this casechannel
will be used for the event and registered as the last channel used by the user.Getting 100 most recent messages
Getting 100 most recent conversations from a user
This produces an array of conversations that each contain a
lastMessage
propertyStoring conversations without using the event engine