Chat Widget - JavaScript 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 type="module" 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 ShippedAI.ChatWidget({
    integrationId: 'your_integration_id',
    jwt: async (callback) => {
      const jwt = await getJwtFromServer()
      callback(jwt)
    },
  })
})
</script>

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

  1. To open or close the chat window programmatically use the following methods:
shippedChatWidget.toggle()
shippedChatWidget.open()
shippedChatWidget.close()
  1. Similarly, to hide or show the chat button, use:
shippedChatWidget.hide()
shippedChatWidget.show()
  1. To destroy the chat widget instance:
shippedChatWidget.destroy()