Chat

Chat — Integration Guidelink

The New Instance Chat product is an embeddable live-chat + AI chatbot widget. Add it to your site with the embed script or the JavaScript API.


Configure your chat widgetlink

  1. Log in to the merchant dashboard
  2. Navigate to Dashboard → Org → Chat (/dashboard/org/[orgId]/chat)
  3. Configure your widget: appearance, AI chatbot, routing rules, agent availability
  4. Copy your Widget API Key — this is the key ID only (e.g. sk_live_abc123), not the keyId:secret form. The widget runs in a browser; the secret must never appear in client-side code.

Embed the widget via script tag (auto-init)link

Add this to your HTML <head> or just before </body>:

<script
  src="https://widget.newinstance.cloud/embed.js"
  data-api-key="sk_live_abc123"
  data-theme="dark"
  data-position="bottom-right"
></script>

data attributes

AttributeTypeDefaultDescription
data-api-keystring (required)Widget key ID (NOT the full secret)
data-themedarklightsystem
data-positionbottom-rightbottom-leftbottom-right

Embed via JavaScript API (full control)link

<script src="https://widget.newinstance.cloud/embed.js"></script>
<script>
const widget = NInstanceChat.init({
  apiKey: 'sk_live_abc123',  // key ID only — never the secret
  theme: 'dark',
  position: 'bottom-right',
  customerName: 'John',
  customerEmail: 'john@example.com',
  customerId: 'usr_123',
  autoOpen: false,
  callbacks: {
    onAuth: (info) => console.log('Chat auth:', info.valid, info.status),
    onOpen: () => console.log('Chat opened'),
    onClose: () => console.log('Chat closed'),
  },
});

// Programmatic control
widget.open();
widget.close();
widget.toggle();
widget.destroy();

// File attachments (before opening composer)
widget.attachFile(file);
widget.openComposer();
</script>

NInstanceChat.init(config) options

OptionTypeDescription
apiKeystring (required)Widget key ID
themedarklight
transportssews
customerNamestringPre-fill customer name
customerEmailstringPre-fill customer email
customerIdstringYour internal customer ID
positionbottom-rightbottom-left
autoOpenbooleanOpen the chat on load
buttonSizenumberLauncher button size in px
panelWidthnumberChat panel width in px
panelHeightnumberChat panel height in px
zIndexnumberCSS z-index for the widget
callbacksobjectonReady, onAuth, onOpen, onClose, onDestroy

How the iframe bridge workslink

The widget loads in a sandboxed <iframe>. All communication between the host page and the widget uses postMessage with source-tag and origin validation:

  • Host → widget messages are tagged with ninstance-chat-host
  • Widget → host messages are tagged with ninstance-chat

The widget fires onAuth after API key validation. The button stays hidden until onAuth confirms valid: true.


Permission scopes for Chat API keyslink

Scope codeDescription
full-accessAll chat permissions (recommended)
ai-chatbot-accessInteract with AI chatbot
live-chat-operationsManage live chat sessions
chat-configurationConfigure widget settings