JavaScript API

Control the widget programmatically — methods, callbacks, and the messenger SDK.

Loader instance

new SupportWireWidget({ … }) returns an instance with these methods:

Method Signature Description
open() () => void Open the widget.
close() () => void Close the widget.
toggle() () => void Toggle open/closed.
showTrigger() () => void Show the launcher button.
hideTrigger() () => void Hide the launcher button.
updateConfig(config) (config: Partial<Config>) => void Update options at runtime.
sendMessage(message, options?) (message: string, options?: { openWidget?: boolean }) => void Pre-fill/send a message. Opens the widget unless openWidget: false.
destroy() () => void Remove the widget, clear its local state, and detach listeners.
SupportWireWidget.getInstances(slug?) (slug?: string) => SupportWireWidget[] All instances, optionally filtered by slug.
const widget = new SupportWireWidget({ widgetSlug: 'YOUR_WIDGET_SLUG' });
 
document.querySelector('#help').addEventListener('click', () => widget.open());

Callbacks

Pass these in the config:

Callback Fires when
onOpen The widget opens.
onClose The widget closes.
onError An error occurs during init or operation.

Messenger SDK

The npm SDK (@supportwire/messenger-js-sdk) exposes an Intercom-compatible API.

Method Description
boot(settings) Initialize with full settings.
update(settings) Update settings on a running instance.
show() / hide() Open / close the messenger.
showNewMessage(content?) Open with an optional pre-filled message.
shutdown() Tear down and clear local state.
onShow(cb) Subscribe to open events. Returns an unsubscribe function.
onHide(cb) Subscribe to close events. Returns an unsubscribe function.
onUnreadCountChange(cb) Subscribe to unread-count changes (delivers current count immediately).
onUserEmailSupplied(cb) Fires when an email is supplied via boot/update.
trackEvent(name, metadata?) Track a custom event.
import SupportWire, { onUnreadCountChange, show } from '@supportwire/messenger-js-sdk';
 
SupportWire({ app_id: 'YOUR_WIDGET_SLUG' });
 
onUnreadCountChange((count) => {
  document.title = count > 0 ? `(${count}) Support` : 'Support';
});

Pre-boot queue

If you load the SDK asynchronously, queue calls on window.SupportWireMessenger before it loads — they drain once it's ready:

window.SupportWireMessenger = window.SupportWireMessenger || function (...a) {
  (window.SupportWireMessenger.q = window.SupportWireMessenger.q || []).push(a);
};
 
window.SupportWireMessenger('boot', { app_id: 'YOUR_WIDGET_SLUG' });
window.SupportWireMessenger('show');

Note — Some Intercom methods are not yet implemented and are safe no-ops: startTour, showArticle, showNews, startSurvey, startChecklist, showTicket, showConversation, showSpace, showMessages, hideNotifications.