Web SDK API 事件

ujet.on(eventName, callback)

ujet.off(eventName, callback)

已创建

创建 Web SDK 小部件时。通常,当您点击启动器时,会发生这种情况。

您可以使用此事件发送身份验证令牌:

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 })
  })
})

已授权

当调用 .authenticate 方法并使用 token 响应 Web SDK 时,会发生此事件。

准备就绪

Web SDK 已提取 company 信息,现在准备就绪 ,可以使用了。

unread

发出 unread 聊天消息计数:

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

关闭

Web SDK 已关闭。当您点击 SDK 中的“关闭”按钮或点击启动器以关闭 SDK 时,会发生此事件。