request-messages
type RequestMessagesCallback = (event: { id: string }) => void;
Detect That Some Chat is Missing Messages, and They Need to Be Loaded
chat.on("request-messages", ({ id }) =>
console.log("data was requested for chat", id);
);
When and Why to Use: This event should be used when there is a need to detect if a chat is missing messages. A typical scenario involves fetching historical messages that are not currently loaded in the chat interface. By listening to this event, developers can initiate loading of missing messages when a request for such data is detected.
How to Block Message Requests in a Chat Widget
chat.intercept("request-messages", ({ id }) => {
console.log("message request blocked for chat", id);
return false;
});
When and Why to Use: This event interception should be used when there is a need to prevent the fetching of historical messages for a given chat. This can be useful in scenarios where loading of old messages needs to be restricted due to user permissions or other business logic. Blocking the request ensures that no additional data is fetched and the chat interface will not attempt to load missing messages.