Skip to main content

Events

Events can be observed in two ways, either by assigning a function to a property or by listening to custom events fired from the component element.

onMessage

Triggered when a message is sent from the user and recieved from the target service.
message encompasses all of the message contents.
isHistory is used to determine whether if the message is from the prepopulated history property.

Example

Latest events:
>
chatElementRef.onMessage = (message) => { console.log(message); };

onClearMessages

  • Function: () => void
  • Event: clear-messages

Triggered when the clearMessages method has been executed. The core purpose of this is to help track messages state.

Example

Latest events:
>
chatElementRef.onClearMessages = () => { console.log("Messages cleared"); };

onComponentRender

  • Function: (chatElementRef: DeepChat) => void
  • Event: render

Triggered when the component has finished rendering on the browser's window.

Example

Latest events:
> "Finished rendering"
chatElementRef.onComponentRender = () => { console.log("Finished rendering"); };
note

Setting a property's value on the DeepChat element when this event is triggered can cause infinite recursion as the component will re-render every time a property value is set. Use a flag variable to prevent this - example.

onError

  • Function: (error: string) => void
  • Event: error

Triggered when an error message appears in the chat.

Example

Latest events:
>
chatElementRef.onError = (error) => { console.log(error); };