Javascript API: Listeners/Events
These events are triggered when the Tiledesk Widget fires a specific event. Register an event handler with:
window.Tiledesk(event_name, handler)Register an event handler to an event type. The handler signature is function(event_data), where event_data is a JavaScript CustomEvent. More info about CustomEvent: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
Arguments
event_name (String, required): Event name to bind to
handler (Function, required): Function with the signature function(event_data)
Available events
onLoadParams — Fired when the parameters are loaded*. Use this event to change at runtime your Tiledesk settings.
onInit — Fired when the widget is initialized
onAuthStateChanged — Generated when the user logs in or logs out
onOpen — Fired when the widget is open
onClose — Fired when the widget is closed
onBeforeMessageSend — Fired before the message is sent. Use to add user information or custom attributes to the chat message.
onAfterMessageSend — Generated after the message has been sent.
onOpenEyeCatcher — Fired when the callout box is opened
onClosedEyeCatcher — Fired when the callout box is closed
onCloseMessagePreview — Fired when the user clicks the close button in message preview while a new message is received and the widget is closed
onNewConversationComponentInit — Fired just after a new conversation is initialized
onBeforeDepartmentsFormRender — Fired just before rendering Departments in the Departments view (useful to filter the default Departments list)
onMessageCreated — Fired when the widget receives a message
onNewConversation — Fired when the widget starts a new conversation
onConversationUpdated — Fired when the widget receives a conversation update
*This event (onLoadParams) will be fired before the tiledesk parameters are loaded. Use this event to change at runtime your Tiledesk settings.
Initial events lifecycle
Important payload of event_data
Examples
Logging widget events
Widget with visitor fullname and email from localStorage
Widget with welcome message containing current date
Event details and examples by event
onBeforeMessageSend
Description: Fired before a message is sent. Use to add user information or custom attributes to the chat message.
Important payload:
detail.message (Object): the message that is being sent
Example — programmatically setting custom user metadata:
Example — add a custom attribute (page title) to the message:
onAfterMessageSend
Description: Generated after the message has been sent.
Important payload:
detail.message (Object): the message that was sent
Example:
onAuthStateChanged
Description: Generated when the authentication state changes (e.g., user sign-in, sign-out).
Important payload: detail (Object) — the auth event.
Auth Event description (expandable)
Example:
onBeforeDepartmentsFormRender
Description: Generated before rendering the Departments selection view. Use to filter the default Departments list based on conditions.
Important payload:
detail.departments (Array): the array of the default Departments (modify this array by reference)
Example — filter departments based on widget language (uses department.description to store language in this example):
onNewConversationComponentInit
Description: Generated as soon as a new conversation view is rendered. Use to execute actions on conversation start.
Important payload:
detail.newConvId (Object): the id of the conversation that fired the event
Example — send a hidden message when a conversation starts (useful to fire a bot welcome message):
onMessageCreated
Description: Generated when the widget receives a message.
Important payload:
detail (Object): the message that was received
Example:
onConversationUpdated
Description: Generated when the widget receives a conversation update.
Important payload:
detail (Object): the conversation that was received
Example:
Related
Previous: Javascript API: Attributes — https://developer.tiledesk.com/widget/attributes
Next: Widget Authentication — https://developer.tiledesk.com/widget/auth
Last updated 2 years ago