Skip to main content

add_chat


name: intercept-add-chat description: conditional chat creation prevention ---# add-chat

type IChat = {
convert: boolean;
chat: Chat;
};
chat.on("add-chat", ({ chat: IChat }) => {
console.log("new chat was created", chat.id, chat.theme);
});

This event is triggered when a user creates a new chat. It can be used to perform actions when a new chat is initiated, such as logging or updating the UI to reflect the new chat instance.

display new chat details

chat.on("add-chat", ({ chat: IChat }) => {
console.log("new chat was created", chat.id, chat.theme);
});

Use this snippet to log the details of the newly created chat, such as its unique ID and theme. This can be important for debugging, analytics, or keeping track of user interactions.

intercept-add-chat

type IChat = {
convert: boolean;
chat: Chat;
};
chat.intercept("add-chat", ({ chat: IChat }) => {
console.log("attempt to create new chat was blocked", chat.id, chat.theme);
return false; // block the creation of a new chat
});

This event intercepts the creation of a new chat, allowing you to block the chat creation if necessary. It can be used for enforcing business rules or preventing certain actions based on custom conditions.

conditional chat creation prevention

chat.intercept("add-chat", ({ chat: IChat }) => {
console.log("attempt to create new chat was blocked", chat.id, chat.theme);
return false; // block the creation of a new chat
});

Use this snippet to block the creation of a new chat and log the attempt. This is useful in scenarios where chat creation needs to be restricted based on certain conditions such as user permissions or system state.