# Web Chat Widget SDK

Developer guide for embedding and customizing the web chat widget

Integrate the Qwetty web chat widget into your website for real-time customer communication.

## Installation

Add the widget script to your website. Provide **`data-organization-id`** or **`data-channel-id`** (at least one is required):

```html
<script src="https://app.qwetty.com/webchat/embed.js"
  data-organization-id="YOUR_ORGANIZATION_ID"
  data-channel-id="YOUR_CHANNEL_ID">
</script>
```

## Configuration options

Pass configuration via `data-` attributes on the script tag:

| Attribute | Description | Default |
|-----------|-------------|---------|
| `data-organization-id` | Your organization ID (this or `data-channel-id` required) | — |
| `data-channel-id` | Your web chat channel ID (this or `data-organization-id` required) | — |
| `data-position` | Widget position: `bottom-right` or `bottom-left` | `bottom-right` |
| `data-primary-color` | Primary color (hex) | `#10b981` |
| `data-widget-title` | Chat window title | `"Chat with us"` |
| `data-widget-subtitle` | Subtitle below the title | `"We're here to help!"` |
| `data-require-form-before-chat` | Require a pre-chat form (`"true"`/`"false"`) | `false` |
| `data-popup-message` | Proactive popup message | — |
| `data-popup-delay` | Delay before the popup (seconds) | `5` |
| `data-language` | Widget language: `en` or `id`. Takes precedence over the channel's language | Channel language, else `en` |
| `data-api-url` | Override the API base URL | — |

With `data-channel-id`, the widget loads the design saved on the channel in Qwetty, and those settings (position, color, title, subtitle, pre-chat form, popup message and delay) take precedence over the matching `data-` attributes. With only `data-organization-id`, the widget connects to one of the organization's web chat channels and uses the attributes and defaults above; use `data-channel-id` when you have more than one web chat channel.

## How it works

1. The widget loads and displays a chat button on your page
2. When a visitor clicks, a chat window opens
3. If "require form before chat" is enabled, the visitor fills in their details first
4. A chat session starts for the visitor
5. Messages are exchanged in real-time via WebSocket
6. Your team sees the conversation in the Qwetty inbox

## Guest sessions

Web chat visitors don't need to log in. Each visitor gets a guest session tied to the channel. If the visitor provides their name, email, or phone number (via the pre-chat form), a contact is created in your directory.

## Framework examples

### React

```jsx
import { useEffect } from 'react';

function QwettyChat({ channelId }) {
  useEffect(() => {
    const script = document.createElement('script');
    script.src = 'https://app.qwetty.com/webchat/embed.js';
    script.dataset.channelId = channelId;
    document.body.appendChild(script);
    return () => document.body.removeChild(script);
  }, [channelId]);

  return null;
}
```

### Next.js

```jsx
import Script from 'next/script';

export default function Layout({ children }) {
  return (
    <>
      {children}
      <Script
        src="https://app.qwetty.com/webchat/embed.js"
        data-channel-id="YOUR_CHANNEL_ID"
        strategy="lazyOnload"
      />
    </>
  );
}
```

## Next steps

- [Web Chat Widget](/en/channels/web-chat-widget) — Channel setup and design configuration
- [Channel Configuration](/en/channel-management/configuration) — Advanced widget settings
