Skip to main content

add-message

chat.on("add-message", ({ id: TID, message: Message }) => 
console.log("new message", message.content, "added to chat", id)
);

Detecting New Messages Sent by User

chat.on("add-message", ({ id: TID, message: Message }) => 
console.log("new message", message.content, "added to chat", id)
);

Use the "add-message" event to detect when a new message is sent by the user. This can be useful for updating the user interface, logging user interactions, or triggering additional actions based on user input.

Blocking Adding a New Message by the User

chat.intercept("add-message", ({ id: TID, message: Message }) => {
console.log("attempt to add message", message.content, "to chat", TID);
return false;
});

Intercept the "add-message" event to block the addition of new messages sent by the user. This can be useful for implementing moderation features, controlling flow, or validating message content before it is added to the chat.