Skip to main content

getMessages(options);

Call this method to get messages from the chat room.

JavaScript

const messages = await sdk.getMessages(skip);

getMessages(options)

Parameter NameDescriptionTypeRequired
skip18 messages are returned when you call this method in descending order. Set the skip to the number of messages you want to skip in the callIntegerNo

Example

The code snippet below prints the latest 18 messages from the chat.

const messages = await sdk.getMessages();
console.log("Messages", messages);

Properties

PropertiesDescriptionType
messagesArray of messages in the chat roomArray of Message
eventIdInternal fieldstring

Message

PropertiesDescriptionType
_idid of the messageString
likesnumber of likes of the messageArray
createdtimestamp when the message was sentDate
messagethe message itselfString
useruser object that contains details about the userObject
_iduserIdString
usernameusername of the userString
customercustomerIDString

User

PropertiesDescriptionType
_idid of the userString
usernameusername of the userString
JSON Sample Response
{
"eventId": "f97f775e-8ce2-432a-b309-c7660b609207",
"messages": [
{
"_id": "63237f8ef0357f1c64879194",
"likes": [],
"created": "2022-09-15T19:39:58.157Z",
"chatRoom": "631794a83671700c713b1ce6",
"message": "ghfhf",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "bobob"
},
"customer": "631794a83671700c713b1ce5",
"__v": 0
},
{
"_id": "63237f54f0357f1c64879193",
"likes": [],
"created": "2022-09-15T19:39:00.413Z",
"chatRoom": "631794a83671700c713b1ce6",
"message": "sdfsd",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "bobob"
},
"customer": "631794a83671700c713b1ce5",
"__v": 0
},
{
"_id": "63237f53f0357f1c64879192",
"likes": [],
"created": "2022-09-15T19:38:59.703Z",
"chatRoom": "631794a83671700c713b1ce6",
"message": "fsdf",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "bobob"
},
"customer": "631794a83671700c713b1ce5",
"__v": 0
},
{
"_id": "63237f52f0357f1c64879191",
"likes": [],
"created": "2022-09-15T19:38:58.919Z",
"chatRoom": "631794a83671700c713b1ce6",
"message": "dfsfsd",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "bobob"
},
"customer": "631794a83671700c713b1ce5",
"__v": 0
},
{
"_id": "6323301cc3aa3508a4c8fc35",
"likes": [],
"created": "2022-09-15T14:01:00.801Z",
"chatRoom": "631794a83671700c713b1ce6",
"message": "Hello world0.9368298953351251",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "bobob"
},
"customer": "631794a83671700c713b1ce5",
"__v": 0
}
]
}