Skip to main content

intercept

widget.intercept(event: string, handler: (obj: any) => boolean): void

The intercept method allows the interception of specific widget events, enabling custom handling or prevention of the default behavior for those events.

Parameters

  • event: The name of the event to intercept (e.g., "add-message", "delete-chat").
  • handler: A function that takes an obj parameter and returns a boolean. If the handler returns false, the default behavior for the event is prevented.

Use-Cases

Preventing Default Reaction to "add-message" Event

To prevent the default reaction when a new message is sent by a user:

widget.intercept("add-message", obj => {
return false;
});

Custom Handling of "add-chat" Event

To intercept the creation of a new chat and perform custom actions:

widget.intercept("add-chat", obj => {
// Custom logic here
console.log("New chat created", obj);
return false; // Optionally prevent default behavior
});

Modifying Data on "provide-messages" Event

To modify or log the data before it is processed when new messages are provided for a chat:

widget.intercept("provide-messages", obj => {
// Custom logic to modify obj
console.log("Messages provided", obj);
return true; // Proceed with default behavior after modification
});

Preventing Chat Deletion with "delete-chat" Event

To prevent a user from deleting a chat:

widget.intercept("delete-chat", obj => {
alert("Chat deletion is not allowed.");
return false; // Prevent the deletion
});