Web SDK API events

ujet.on(eventName, callback)

ujet.off(eventName, callback)

created

When Web SDK widget is created. Usually this happens when you click the launcher.

You can use this event to send authentication token:

const ujet = new UJET({
  // ...
  // authenticate: getAuthToken
})

// when you didn't use `authenticate` option, you need to call
// `.authenticate` method manually

ujet.on('created, () => {
  fetch('/token').then(resp => {
    return resp.json()
  }).then(data => {
    ujet.authenticate({ token: data.token })
  })
})

authorized

This event happens when .authenticate method is called and responded with a token to Web SDK.

ready

Web SDK has fetched company information, it is ready to use now.

unread

Emit unread chat message count:

ujet.on('unread', function(num) {
  console.log('has ' + num + ' unread messages')
})

close

When Web SDK has been closed. This event happens when you click "close" button in the SDK, or click the launcher to close SDK.