Gorgias logo
Gorgias logo

All articles

Subscribe to Chat eventsUpdated 8 months ago

This suggestion isn't an official feature of our Chat widget, so our support for it is limited - we recommend that it be implemented by someone with a technical background.


Sometimes it's useful to do something specific when the Chat widget is open or closed - you can use the example below to do that.

1<script>
2var initGorgiasChatPromise = (window.GorgiasChat) ? window.GorgiasChat.init() : new Promise(function (resolve) { window.addEventListener('gorgias-widget-loaded', function () { resolve();})});
3
4initGorgiasChatPromise.then(function() {
5 GorgiasChat.on('EVENT_NAME', function(data) {
6 // your code should go here
7 })
8})
9</script>


Gorgias Chat supports the following events:

  • A ready event is triggered when the Chat is rendered.
  • A destroy event is triggered when the Chat is unmounted.
  • A message:received event is triggered when a message is received. The data parameter will contain the message attributes.
  • A message:sent event is triggered when a message is received. The data parameter will contain the message attributes.
  • A message event is triggered when a message is sent or received. The data parameter will contain the message attributes.
  • An unreadCount event is triggered when the unread message count changes. The data parameter will contain the new number of unread messages.
  • A widget:opened event is triggered when the Chat window is opened.
  • A widget:closed event is triggered when the Chat window is closed.
  • A connected event is triggered when a connection to the Chat server is established.
  • A disconnected event is triggered when a connection to the Chat server is lost.
  • A typing:start event is triggered when an agent begins typing their message.
  • A typing:stop event is triggered when an agent stops typing their message.

It is also possible to deregister an event listener using the GorgiasChat.off('EVENT_NAME', listener) - the listener argument must be the function that was previously registered to subscribe to the event.

Was this article helpful?
Yes
No