Get Messages

Description

Returns the message history of a given room, in a defined number and counted from a certain message within that room.

Params

The argument of the getMessages() function is an object with the following keys:

  • roomId: It's a mandatory key with a value of type “string”, that corresponds to the ID of the room from which messages will be fetched. The ID of the current room is a key inside the room object of widgetService, and can be accessed as follows: widgetService.room.id

  • limit: It's an optional key with a value of type “number”, that corresponds to the number of messages to be fetched. If not set, the “getMessages” function will take the default value of 20, and therefore it will bring 20 messages.

  • id: It's an optional key with a value of type “string” or “number”, that corresponds to the message ID from which a number of messages determined by the "limit" parameter will be fetched. If not set, the “getMessages” function will take the default value of null, and therefore it will bring the last sent messages, according to the established “limit”.

Example of use

/**
* @param {GetMessages} [params]
* @returns {Promise<Message[]>}
**/

widgetInstance.getMessages ({
    roomId: "<someStringValue>",
    id?: "<someStringOrNumberValue>",
    limit?: <someNumberValue>,
  }
);

Last updated