To integrate this widget into your portal:
<script src="/dist/chatbot-widget.js"></script>
<chatbot-widget
api-url="https://chatbot-api-sit.volanedev.com"
user-id="<%= user.id %>">
</chatbot-widget>
// After your portal login completes
const widget = document.querySelector('chatbot-widget');
const authToken = sessionStorage.getItem('authToken');
widget.setAuthToken(authToken);
// Listen for auth expiry events
window.addEventListener('chatbot-auth-expired', (event) => {
console.log('Chatbot auth expired for user:', event.detail.userId);
// Refresh token and update widget
const newToken = await refreshAuthToken();
widget.setAuthToken(newToken);
});
Three small examples showing common Vue 3 patterns: CDN/script tag, ESM import (recommended for modern builds), and a Vue SFC example you can copy into your app.
<!-- public/index.html -->
<script src="https://chatbot-sit.volanedev.com/dist/chatbot-widget.js"></script>
Then in any Vue template you can directly use the custom element and set the token from onMounted:
<template>
<chatbot-widget ref="chatbot" api-url="https://chatbot-api-sit.volanedev.com" :user-id="userId" />
</template>
<script setup>
import { ref, onMounted } from 'vue'
const chatbot = ref(null)
const userId = 'user123'
onMounted(() => {
const token = sessionStorage.getItem('authToken')
if (chatbot.value && token) chatbot.value.setAuthToken(token)
})
Import the ESM bundle in your app entry so the element is registered before components mount:
// main.js
import 'chatbot-widget/dist/chatbot-widget.esm.js'
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
<template>
<div>
<chatbot-widget ref="chatbot" api-url="https://chatbot-api-sit.volanedev.com" :user-id="userId" />
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
const chatbot = ref(null)
const userId = 'user123'
onMounted(() => {
// Ensure widget is available (if using ESM import this is usually immediate)
const token = sessionStorage.getItem('authToken')
if (chatbot.value && token) chatbot.value.setAuthToken(token)
})
setAuthToken(token) and emits chatbot-auth-expired for token refresh flows.if (typeof window !== 'undefined')).