Chat Widget - JavaScript SDK
In order to integrate the Shipped AI Chat Widget into your website, please follow these instructions:
- 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
- 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.
- To open or close the chat window programmatically use the following methods:
shippedChatWidget.toggle()
shippedChatWidget.open()
shippedChatWidget.close()
- Similarly, to hide or show the chat button, use:
shippedChatWidget.hide()
shippedChatWidget.show()
- To destroy the chat widget instance:
shippedChatWidget.destroy()
Updated 8 months ago