Extend behavior with JavaScript
Use the full SDK from your website, or save a small isolated extension in widget settings.
Website extensions
Your application can combine its own data and DOM with the public SDK. Keep component subscriptions scoped and unsubscribe on unmount.
document.querySelector('#support-button').addEventListener('click', async () => {
await TruComWidget.identify({ name: currentUser.name });
await TruComWidget.setAttributes({ last_order_id: selectedOrder.id });
await TruComWidget.startConversation({ draft: 'I need help with this order.' });
});Saved extensions
Open Settings → Chat widget → JavaScript, enable the extension and save your code. The code runs on installed widgets inside a sandbox. Settings appearance previews do not execute saved scripts.
The sandbox has open, close, showLauncher, hideLauncher, configure, setCustomCss, setLauncherCss and on. configure is limited to appearance and greeting options. It cannot read your page, call network services, access session credentials, identify customers, send messages or change backend capabilities.
TruComWidget.on('open', function () {
TruComWidget.configure({ headerTitle: 'Our support team' });
});Sandbox events
Saved extensions receive event names and timestamps. The ready, open, close, navigation.changed and availability.changed events include presentation context. Other events omit customer and conversation data. Errors are reported to the host SDK error event.
Use your website’s JavaScript for account data, analytics integrations, DOM changes and the full method set. Keep all privileged credentials on the server. Disable an extension or clear its code to remove it on the next configuration refresh.