Skip to content

Async Loader

The async loader is a lightweight script that lets you configure the chat widget before it finishes loading. Commands are queued and applied once the full widget is ready.

Usage

html
<!-- 1. Include the loader -->
<script type="module" src="https://sdk.saytv.net/@saytv/chat-sdk@latest/dist/loader.mjs"></script>

<!-- 2. Queue commands (runs even before the widget loads) -->
<script>
  SayTVChat('init', {
    appId: 'your-app-id',
    authToken: 'user-jwt-token',
    theme: 'dark',
    height: 700,
    width: '100%',
  });
</script>

How It Works

  1. The loader registers a global window.SayTVChat() function
  2. Commands are queued until the full widget finishes loading
  3. Once ready, all queued configuration is applied to the <saytv-chat> element

SayTVChat Function

ts
SayTVChat(action: string, config?: Record<string, unknown>): void

Actions

ActionDescription
'init'Initialize the inline widget with the given config
'bubble'Initialize a floating chat bubble with the given config

Config Options

The init action accepts a config object. Keys are camelCase and are automatically converted to kebab-case attributes:

KeyAttributeTypeDescription
appIdapp-idstringApp identifier
envenvstringEnvironment ('production' or 'staging')
apiUrlapiurlstringDirect API URL
authTokenauth-tokenstringJWT access token
builtInAuthbuilt-in-authbooleanShow login UI
fanzonefanzonebooleanEnable fanzone
heightheightnumberHeight in pixels
widthwidthstringCSS width value
themethemestring'light' or 'dark'
modemodestring'page-chat' for page chat mode
pageIdpage-idstringUnique identifier for page chat
pageNamepage-namestringDisplay name for page chat
customTabUrlcustom-tab-urlstringURL loaded in a custom tab iframe
customTabLabelcustom-tab-labelstringLabel shown on the custom tab
customTabIconcustom-tab-iconstringIcon name for the custom tab

Bubble Config Options

The bubble action accepts all the same config keys as init, plus bubble-specific options:

KeyAttributeTypeDescription
positionpositionstring'bottom-right' or 'bottom-left'
bubbleSizebubble-sizenumberLauncher diameter in pixels
bubbleColorbubble-colorstringLauncher background color
bubbleIconbubble-iconstringCustom launcher icon URL
offsetXoffset-xnumberHorizontal offset from viewport edge
offsetYoffset-ynumberVertical offset from viewport edge
chatWidthchat-widthnumberChat panel width
chatHeightchat-heightnumberChat panel height
greetinggreetingstringGreeting tooltip text
greetingDelaygreeting-delaynumberSeconds before greeting appears
hideOnMobilehide-on-mobilebooleanHide bubble on mobile viewports
customLaunchercustom-launcherstringCSS selector for external launcher

See the Bubble Chat guide for full details.

Auto-Creation

If no <saytv-chat> element exists on the page when init is called, the loader automatically creates one and appends it to document.body.

To control placement, add the element yourself:

html
<div id="chat-container">
  <saytv-chat></saytv-chat>
</div>

<script type="module" src="loader.mjs"></script>
<script>
  SayTVChat('init', { appId: 'your-app-id', theme: 'dark' });
</script>

When to Use

Use the async loader when:

  • You want to minimize initial page load impact
  • The chat widget is not immediately visible (e.g., in a tab or modal)
  • You need to configure the widget from server-rendered data before it loads
  • You're embedding via a third-party script tag

For most cases where the widget is immediately visible, importing @saytv/chat-sdk/widget directly is simpler.

SayTV Chat SDK Documentation