Javascript Chat Widget SDK

In order to integrate the Shipped AI Chat Widget into your website, please follow these instructions:

  1. Add the JS SDK right before the closing </head> tag
<script defer src="https://js.shippedsuite.com/api/chat-widget.js"></script>

📘

Staging JS SDK

For staging environment, use https://js-staging.shippedsuite.com/api/chat-widget.js

  1. Add a new <script></script> and instantiate the JS SDK:
<script>
window.addEventListener('shipped:chat-script-loaded', () => {
  const shippedChatWidget = new ShippedChatWidget.ChatWidget({
    iframeSrc: 'https://shipped.ai/ai/conversations',
    jwt: async callback => {
      const jwt = await getJwtFromServer()
      callback(jwt)
    },
  })
})
</script>

Through iframeSrc you will specify the source URL of the iframe that loads the chat window.

You can authenticate the current user by creating getJwtFromServer() function which should return a promise that resolves with the JWT token.

  1. authenticate('JWT_TOKEN')

As an alternative to providing JWT token upon initializing ChatWidget instance, you can authenticate the current user through the authenticate() function, like this:

shippedChatWidget.authenticate('USER_JWT_TOKEN')
  1. To open or close the chat window programmatically use the following methods:
shippedChatWidget.openChatWindow()
shippedChatWidget.closeChatWindow()
  1. Similarly, to hide or show the chat button, use:
shippedChatWidget.hideChatButton()
shippedChatWidget.showChatButton()
  1. To logout the current user, use:
shippedChatWidget.logout()
  1. To destroy the chat widget instance:
shippedChatWidget.destroy()