---
title: "Get started with the web channel"
description: "Add the Moveo web channel to your website with a snippet, the API, or MCP, set the region host and CSP, and authenticate users."
---

# Get started with the web channel

> Add the Moveo web channel to your website with a snippet, the API, or MCP, set the region host and CSP, and authenticate users.

## Overview

The Moveo web channel enables you to add AI-powered conversations directly to your website. This
channel provides a customizable chat interface that you can style to match your brand and configure
to meet your specific requirements.

:::note
By default, a conversation in the web channel stays active for one hour if the user does not
close the window. The web channel does not load if the user agent (browser) is a
**bot**.
:::

The user does not have to wait for the AI agent to finish an answer. If the user sends a text
message while the AI agent is still answering, the AI agent stops that answer. Then it answers all
of the new messages together in one reply.

## Quick start

To add the web channel to your website:

1. Go to **Deploy → Connections** in your Moveo account
2. Select your environment
3. Select **Connect** on the **Webchat** integration
4. Copy the generated snippet and add it before the `</body>` tag:

```html
<script src="https://web.moveo.ai/web-client.min.js"></script>
<script>
  MoveoAI.init({
    integrationId: "YOUR-INTEGRATION-ID",
    version: "v2",
  })
    .then((instance) => console.log("connected"))
    .catch((error) => console.error(error));
</script>
```

5. Add your domain to the trusted domains list
6. Set the web channel state to **Active**

The web channel is now ready to receive messages.

### Connect the web channel through the API or the MCP server

**Console**

Follow the [quick start](#quick-start) steps above. The console shows the snippet with your
`integrationId`. For accounts in the United States and Brazil, the snippet also sets `host`.

**API**

Send `POST /v1/desks/{desk_id}/integrations` with a `manage` API key. See
[Add integration](/api/rest/add-integration).

```json
{
  "type": "web",
  "name": "Website chat",
  "active": true,
  "config": {
    "domains": ["https://example.com"]
  }
}
```

The `integration_id` of the response is the `integrationId` of the snippet. It is not the ID of the
environment (`desk_id`).

**MCP**

`moveo_create_integration` with `environment_id`, `name`, `type: "web"`, and an optional `config`
such as `{"domains": ["https://example.com"]}`. Read `moveo://schemas/integration-config/web` for
the config fields.

### Region hosts

The snippet loads the same script in every region. The `host` option tells the web channel which
region to connect to. Without `host`, it connects to Europe.

| Region        | `host` value                             |
| ------------- | ---------------------------------------- |
| Europe        | `https://channels-ws.moveo.ai` (default) |
| United States | `https://channels-ws.us-central.moveo.ai` |
| Brazil        | `https://channels-ws.sa-east.moveo.ai`   |

```js
MoveoAI.init({
  integrationId: "YOUR-INTEGRATION-ID",
  host: "https://channels-ws.us-central.moveo.ai",
});
```

## Installation options

### Standard installation

The standard installation loads the web channel on every page:

```html
<script src="https://web.moveo.ai/web-client.min.js"></script>
<script>
  MoveoAI.init({
    integrationId: "YOUR-INTEGRATION-ID",
    version: "v2",
  })
    .then((instance) => console.log("connected"))
    .catch((error) => console.error(error));
</script>
```

### Embed mode

Render the chat within your page content instead of as a floating widget:

```html
<div id="chat-container"></div>
<script src="https://web.moveo.ai/web-client.min.js"></script>
<script>
  MoveoAI.init({
    integrationId: "YOUR-INTEGRATION-ID",
    element: document.getElementById("chat-container"),
    version: "v2",
  })
    .then((instance) => console.log("embedded chat connected"))
    .catch((error) => console.error(error));
</script>
```

### Delayed initialization

Wait for page load or user interaction before initializing:

```html
<script src="https://web.moveo.ai/web-client.min.js"></script>
<script>
  window.addEventListener("DOMContentLoaded", function () {
    MoveoAI.init({
      integrationId: "YOUR-INTEGRATION-ID",
      version: "v2",
    })
      .then((instance) => console.log("connected"))
      .catch((error) => console.error(error));
  });
</script>
```

## User authentication

Secure your web channel and authenticate users to ensure messages come from verified customers only.

### Why authenticate?

Authentication provides:

- **Security**: Verify that messages come from your actual customers
- **Personalization**: Pass user data securely to provide tailored responses
- **Privacy**: Encrypt sensitive information end-to-end

### Basic authentication setup

1. **Generate RSA keys**:

```bash
# Private key (keep secure on your server)
openssl genrsa -out private.pem 2048
# Public key (add to Moveo)
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
```

2. **Add public key to Moveo**:

   - Go to **Deploy → Connections** → **Webchat** → **Advanced settings**
   - Enable **Activate end-to-end encryption**
   - Paste your public key

3. **Generate JWT on your server**:

**Node.js**

    ```js
    const jwt = require('jsonwebtoken');

    function generateToken(userId) {
      const payload = {
        sub: userId, // Required: unique user ID
        iss: 'yourdomain.com', // Required: issuer
      };

      return jwt.sign(payload, process.env.PRIVATE_RSA_KEY, {
        algorithm: 'RS256',
        expiresIn: '5m', // Must expire within 24 hours
      });
    }
    ```

**Go**

    ```go
    import (
      "crypto/x509"
      "encoding/pem"
      "github.com/golang-jwt/jwt"
      "time"
    )

    func generateToken(userId string) (string, error) {
      token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
        "sub": userId,           // Required
        "iss": "yourdomain.com", // Required
        "exp": time.Now().Add(5 * time.Minute).Unix(),
      })

      // Sign with private key
      privateKey := loadPrivateKey()
      return token.SignedString(privateKey)
    }
    ```

4. **Initialize with authentication**:

```html
<script>
  MoveoAI.init({
    integrationId: "YOUR-INTEGRATION-ID",
    identityToken: "JWT_FROM_YOUR_SERVER",
    version: "v2",
  })
    .then((instance) => console.log("authenticated"))
    .catch((error) => console.error(error));
</script>
```

### Keep the token fresh

`identityToken` accepts a string or a function that returns a token or a promise with a token:
`string | (() => string | Promise<string>)`.

The web channel sends the token when it starts a session and each time it reconnects to that
session. A reconnect follows a network drop, a page reload, or a second tab. An open connection
does not need a new token.

With a string, the web channel sends the same token every time. When Moveo
[requires the token](#require-an-identity-token), it refuses a reconnect with a token after its
`exp`. Then the string token must stay valid for the whole conversation. Moveo accepts an `exp` at
most 24 hours ahead. After the `exp`, the web channel starts a new session with the same expired
token, and Moveo refuses it too. The visitor sees an error screen until the page reloads with a new
token, because **Restart** sends the same token again (see
[Authentication failures](https://docs.moveo.ai/docs/integrations/web/web-troubleshooting.md#issue-authentication-failures)). With a function,
the web channel calls it before each session start and each reconnect, and keeps no token between
calls. Use a function when your tokens expire in less than one conversation. A function also makes a
logout or an account switch take effect at the next reconnect, on a single-page app that does not
reload.

```html
<script>
  MoveoAI.init({
    integrationId: "YOUR-INTEGRATION-ID",
    version: "v2",
    identityToken: async () => {
      const response = await fetch("/moveo-token", { credentials: "include" });
      if (response.status === 401) {
        return ""; // No user is logged in.
      }
      if (!response.ok) {
        throw new Error(`Token endpoint: ${response.status}`);
      }
      const { token } = await response.json();
      return token;
    },
  });
</script>
```

Your `/moveo-token` endpoint signs a token for the logged-in user, as `generateToken` does in
[step 3](#basic-authentication-setup), and returns it as `{ "token": "<JWT>" }`. Sign a new token on
each call. With a function, an `exp` of five minutes is enough.

The function follows these rules:

- If your page has no logged-in user, the function returns an empty string. The web channel then sends no
  token. If the token is optional, the visitor starts or rejoins the session without a verified
  identity. If Moveo [requires the token](#require-an-identity-token), Moveo refuses the session,
  and the visitor sees an error screen with a **Restart** button.
- A call fails if the function throws an error, returns no string, or does not answer in 10
  seconds. Then the web channel calls it again after 1 second and after 2 more seconds. If every
  call fails, the result
  is the same as an empty string. If the token is optional, an outage of your token endpoint gives
  sessions without a verified identity. If every call times out, the chat waits about 33 seconds
  before it continues.
- If your page loads a fixed version of the web channel script, update it before you pass a
  function.

### Log out

When the user logs out, call [`destroy()`](https://docs.moveo.ai/docs/integrations/web/web-developer-guide.md#destroy). For a full login and
logout example, see [User authentication flow](https://docs.moveo.ai/docs/integrations/web/web-developer-guide.md#user-authentication-flow).

### Require an identity token

By default, the identity token is optional, and a session ID is enough to reconnect to a session.
You can make the token required for your integration. Then Moveo applies these rules:

- The web channel cannot start a session without a valid token.
- A reconnect to a session needs a valid token for the same user (`sub`) that started the session.
  Otherwise, the web channel starts a new session. That session also needs a valid token, so a
  missing or expired token gives an error screen.
- A connection can send messages and read the history only for the session that it started or
  reconnected to.

To make the token required, set `require_identity_token` to `true` in the integration `config`
with the update integration API. Your integration needs a public key in **Activate end-to-end
encryption**. To turn it off, set it to `false`.

:::warning

Complete the checks below before you turn the setting on. A page that does not pass the token
cannot start a chat. A page that loads an old web channel script loses the conversation on each
reload. Moveo recommends that you ask Moveo support to turn the setting on with you.

:::

Before you turn the setting on, complete these checks:

1. Make sure that every page that loads the web channel passes `identityToken`, including the page
   of a mobile WebView.
2. Make sure that every page loads the current web channel script.
3. If your tokens expire in less than one conversation, pass a [function](#keep-the-token-fresh).

A visitor without a valid token sees an error screen with a **Restart** button. For the small
window, see [Keep the chat when visitors leave](https://docs.moveo.ai/docs/integrations/web/web-configuration.md#keep-the-chat-when-visitors-leave).

### Passing encrypted user data

To securely pass sensitive user information (for example, account details, VIP status):

1. **Get Moveo's public key** from your web integration settings
2. **Encrypt context with AES-256**
3. **Encrypt AES key with RSA**
4. **Include in JWT**:

:::warning Match the encryption scheme exactly
Moveo decrypts `encryption_key` and `init_vector` with **RSA-OAEP (SHA-256)**, and the
`context` with **AES-256-CBC**. Libraries that default to a different padding or hash
produce tokens Moveo cannot decrypt. In particular, `node-rsa` defaults to OAEP with
SHA-1, so always set the OAEP hash to SHA-256, as the example shows.
:::

**Node.js**

```js
const crypto = require("crypto");
const jwt = require("jsonwebtoken");

function generateSecureToken(userId, userContext) {
  // Generate AES key and IV
  const aesKey = crypto.randomBytes(32);
  const iv = crypto.randomBytes(16);

  // Encrypt context with AES-256-CBC
  const cipher = crypto.createCipheriv("aes-256-cbc", aesKey, iv);
  let encrypted = cipher.update(JSON.stringify(userContext), "utf8", "base64");
  encrypted += cipher.final("base64");

  // Encrypt the AES key and IV with Moveo's RSA public key.
  // Moveo decrypts with RSA-OAEP / SHA-256, so the padding and hash must
  // match exactly or decryption fails server-side.
  const oaep = {
    key: process.env.MOVEO_PUBLIC_KEY,
    padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
    oaepHash: "sha256",
  };
  const encryptedKey = crypto.publicEncrypt(oaep, aesKey).toString("base64");
  const encryptedIV = crypto.publicEncrypt(oaep, iv).toString("base64");

  // Create JWT with encrypted data
  const payload = {
    sub: userId,
    iss: "yourdomain.com",
    context: encrypted, // AES encrypted context
    encryption_key: encryptedKey, // RSA encrypted AES key
    init_vector: encryptedIV, // RSA encrypted IV
  };

  return jwt.sign(payload, process.env.PRIVATE_RSA_KEY, {
    algorithm: "RS256",
    expiresIn: "5m",
  });
}

// Usage
const userContext = {
  user: {
    email: "user@example.com",
    is_vip: true,
    account_tier: "premium",
  },
  contract_id: "12345",
  credit_limit: 10000,
};

const token = generateSecureToken("user-123", userContext);
```

The AI agent can use the encrypted context for personalization. Moveo never sends it back to the
client, so sensitive data stays secure.

### Authentication flow

```mermaid
sequenceDiagram
    participant S as Your Server
    participant W as Web Client
    participant M as Moveo

    W->>S: Call the function (a string skips this step)
    S->>W: JWT signed with your private key
    W->>M: Start a session with the JWT
    M->>M: Verify the signature and exp

    alt Token valid
        M->>W: Session created
    else Token refused
        M->>W: Session refused
        W->>W: Error screen with Restart
    end

    Note over W,M: The connection drops, or the page reloads
    W->>S: Call the function again (a string reuses the same JWT)
    S->>W: Fresh JWT
    W->>M: Reconnect with the JWT
    M->>M: Verify the signature, exp, and sub

    alt Token valid
        M->>W: Session reconnected, history kept
    else Token refused (token required)
        M->>W: Session expired
        W->>M: Start a new session with the next JWT
        alt Token valid
            M->>W: Session created, new conversation
        else No token, or an expired string
            M->>W: Session refused
            W->>W: Error screen with Restart
        end
    end
```

## Content Security Policy

If your site sends a `Content-Security-Policy` header, allow these hosts. Replace the
`channels-ws` host with the host of your [region](#region-hosts).

| Directive     | Value                                                         | Why                                                       |
| ------------- | ------------------------------------------------------------- | --------------------------------------------------------- |
| `script-src`  | `https://web.moveo.ai`                                         | The script `web-client.min.js`.                            |
| `frame-src`   | `https://web.moveo.ai`                                         | The web channel window loads in an iframe from this host. |
| `connect-src` | `https://channels-ws.moveo.ai` and `wss://channels-ws.moveo.ai` | The configuration request and the WebSocket connection.    |
| `img-src`     | `https://res.cloudinary.com`                                   | The default avatar of the AI agent.                       |

The snippet also has an inline `<script>` that calls `MoveoAI.init`. A policy that allows only
hosts blocks this script, so the web channel does not start. To allow it, add a nonce: a random
value that your server creates for each page response. Put the same value in `script-src`
and in the `nonce` attribute of the inline script.

For example, for an account in Europe:

```text
Content-Security-Policy: script-src 'self' https://web.moveo.ai 'nonce-RANDOM-VALUE';
  frame-src https://web.moveo.ai;
  connect-src 'self' https://channels-ws.moveo.ai wss://channels-ws.moveo.ai;
  img-src 'self' https://res.cloudinary.com
```

```html
<script src="https://web.moveo.ai/web-client.min.js"></script>
<script nonce="RANDOM-VALUE">
  MoveoAI.init({
    integrationId: "YOUR-INTEGRATION-ID",
    version: "v2",
  });
</script>
```

If you cannot add a nonce, move the `MoveoAI.init` call to a script file on your own domain.
`'self'` in `script-src` allows that file.

If you set your own avatar or show files that users upload, also allow the hosts of these files
in `img-src` and `connect-src`.

## Security best practices

1. **Keep private keys secure** - Never expose them in client-side code
2. **Use short expiration times** - Pass a [function](#keep-the-token-fresh) and set `exp` to five
   minutes. Moveo rejects JWT tokens that expire more than 24 hours ahead.
3. **Validate on server** - Always generate tokens server-side
4. **Encrypt sensitive data** - Use AES encryption for context data
5. **Trusted domains** - Only allow your domains in settings
6. **HTTPS only** - Always use secure connections

## Mobile app integration

To use the web channel in a mobile application:

1. Host the web channel on a webpage accessible by URL
2. Embed the webpage using a WebView or iframe:

```html
<!-- Host this page on your server -->
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body>
    <script src="https://web.moveo.ai/web-client.min.js"></script>
    <script>
      MoveoAI.init({
        integrationId: "YOUR-INTEGRATION-ID",
        // Pass authentication from mobile app if needed
        identityToken: window.AUTH_TOKEN,
        version: "v2",
      })
        .then((instance) => {
          // Expose instance to mobile app if needed
          window.moveoInstance = instance;
        })
        .catch((error) => console.error(error));
    </script>
  </body>
</html>
```

Then embed this page in your mobile app's WebView component.

If the WebView stays open longer than the token's `exp`, pass a [function](#keep-the-token-fresh)
that asks the app for a new token.

## Next steps

- [Configure appearance and behavior](https://docs.moveo.ai/docs/integrations/web/web-configuration.md)
- [Use methods and events](https://docs.moveo.ai/docs/integrations/web/web-developer-guide.md)
- [Troubleshoot common issues](https://docs.moveo.ai/docs/integrations/web/web-troubleshooting.md)
