> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vambe.me/llms.txt
> Use this file to discover all available pages before exploring further.

# Webchat Integration Guide

> Learn how to integrate Vambe Webchat into your website. Add AI-powered customer support directly to your web pages in minutes.

## Overview

The Vambe Webchat is a powerful tool that allows customers to interact with your AI assistant directly from your website, enabling real-time communication and instant support.

## Quick Start

### Prerequisites

* Active Vambe account
* Access to your website's HTML code
* Your Vambe API credentials

### Installation Steps

<Steps>
  <Step title="Access Your Vambe Account">
    Log in to your Vambe account at [app.vambeai.com](https://app.vambeai.com)
  </Step>

  <Step title="Navigate to Channels & Accounts">
    Go to **Settings** → **Channels & Accounts**

    You can access this directly at: [app.vambeai.com/settings?q=channels](https://app.vambeai.com/settings?q=channels)
  </Step>

  <Step title="Add Webchat Channel">
    1. Click **"Add Channel"** 2. Select **"Webchat"** from the available options
    2. Give your webchat channel a descriptive name (internal use only, not
       visible to customers)
  </Step>

  <Step title="Get Your Integration Code">
    1. Click on the newly created Webchat channel
    2. Click the three dots menu (⋮)
    3. Select the code icon (`<>`)
    4. Copy the provided script code
  </Step>

  <Step title="Add Code to Your Website">
    Paste the copied code into the `<body>` section of your website's HTML, preferably just before the closing `</body>` tag.

    ```html theme={null}
    <!DOCTYPE html>
    <html>
      <head>
        <title>Your Website</title>
      </head>
      <body>
        <!-- Your website content -->

        <!-- Vambe Webchat Script (paste here) -->
        <script>
        window.embeddedWebchatConfig = {
          clientId: "YOUR_CLIENT_ID",
          channelId: "YOUR_CHANNEL_ID"
        };
        </script>
        <script src="https://vambeai.com/webchat.js"></script>
      </body>
    </html>
    ```
  </Step>

  <Step title="Test the Integration">
    Refresh your website and you should see the Vambe chat widget appear in the corner of your page.
  </Step>
</Steps>

<Check>
  **Success!** Your webchat is now live on your website. Customers can start
  chatting with your AI assistant immediately.
</Check>

## Configuration Options

After the basic installation, you can customize your webchat with various options:

### Basic Configuration

```javascript theme={null}
window.embeddedWebchatConfig = {
  // Required fields
  clientId: 'YOUR_CLIENT_ID',
  channelId: 'YOUR_CHANNEL_ID',

  // Agent customization
  agentName: 'Sofia',
  agentIconUrl: 'https://your-domain.com/agent-avatar.png',

  // Appearance
  primaryColor: '#2994FF',
  darkTheme: false,

  // Initial data collection
  askForName: true,
  askForEmail: true,
  askForPhoneNumber: false,

  // Positioning
  xPosition: 20,
  yPosition: 20,

  // Language
  language: 'es', // "es" or "en"

  // Custom text
  chatWithUsText: 'Chat with us',

  // Suggested questions
  suggestedQuestions: [
    'What services do you offer?',
    'How can I get started?',
    'What are your pricing plans?',
  ],
};
```

### Configuration Reference

<ParamField body="clientId" type="string" required>
  Your Vambe client ID (found in the integration code)
</ParamField>

<ParamField body="channelId" type="string" required>
  Your webchat channel ID (found in the integration code)
</ParamField>

<ParamField body="agentName" type="string" default="&#x22;&#x22;">
  The name of the agent displayed in the chat. Example: `"Sofia"`, `"Customer
      Support"`
</ParamField>

<ParamField body="agentIconUrl" type="string" default="&#x22;&#x22;">
  URL to the agent's avatar image. Must be a valid image URL (JPG, PNG, SVG, etc.)

  Example: `"https://your-domain.com/avatar.png"`
</ParamField>

<ParamField body="externalUserId" type="string">
  The user ID from your system. Use this if you're embedding the webchat on a page where users are already logged in.

  This allows you to:

  * Track conversations by your user IDs
  * Link chat history across sessions
  * Use with [POST /api/public/webchat/contact/add-metadata](/reference/webchat/add-webchat-contact-metadata) endpoint
</ParamField>

<ParamField body="externalUserName" type="string">
  The user's name from your system. Use when embedding on authenticated pages.
</ParamField>

<ParamField body="askForPhoneNumber" type="boolean" default={false}>
  Request user's phone number before starting the chat.
</ParamField>

<ParamField body="askForEmail" type="boolean" default={false}>
  Request user's email before starting the chat.
</ParamField>

<ParamField body="askForName" type="boolean" default={false}>
  Request user's name before starting the chat. If not provided, contact will be
  named "Webchat Contact" in Vambe.
</ParamField>

<ParamField body="darkTheme" type="boolean" default={false}>
  Enable dark theme for the webchat widget.
</ParamField>

<ParamField body="primaryColor" type="string" default="&#x22;#2994FF&#x22;">
  Primary color for the chat widget. Must be a valid hex color code.

  Examples: `"#2994FF"`, `"#FF5733"`, `"#00AA00"`
</ParamField>

<ParamField body="language" type="string" default="&#x22;es&#x22;">
  Chat interface language. Options: `"es"` (Spanish) or `"en"` (English)
</ParamField>

<ParamField body="suggestedQuestions" type="array" default={[]}>
  Up to 4 suggested questions displayed to start the conversation.

  Example:

  ```javascript theme={null}
  suggestedQuestions: [
    'What services do you offer?',
    'How can I get started?',
    'What are your pricing plans?',
    'How do I contact support?',
  ];
  ```
</ParamField>

<ParamField body="chatWithUsText" type="string" default="&#x22;&#x22;">
  Text displayed next to the chat button. Example: `"Chat with us"`, `"Need help?"`
</ParamField>

<ParamField body="xPosition" type="number" default={20}>
  Horizontal position of the chat button in pixels from the right edge.
</ParamField>

<ParamField body="yPosition" type="number" default={20}>
  Vertical position of the chat button in pixels from the bottom edge.
</ParamField>

## Advanced Examples

### Example 1: E-commerce Website

```html theme={null}
<script>
  window.embeddedWebchatConfig = {
    clientId: 'YOUR_CLIENT_ID',
    channelId: 'YOUR_CHANNEL_ID',

    // Branding
    agentName: 'Shopping Assistant',
    agentIconUrl: 'https://yourshop.com/images/assistant-avatar.png',
    primaryColor: '#FF6B6B',

    // Collect email for order updates
    askForEmail: true,
    askForName: true,

    // Custom message
    chatWithUsText: 'Need help shopping?',

    // Product-related suggestions
    suggestedQuestions: [
      "What's on sale today?",
      'Do you have free shipping?',
      'How do I track my order?',
      "What's your return policy?",
    ],

    language: 'en',
  };
</script>
<script src="https://vambeai.com/webchat.js"></script>
```

### Example 2: Logged-in User Area

```html theme={null}
<!-- For authenticated users, pass their info -->
<script>
  window.embeddedWebchatConfig = {
    clientId: 'YOUR_CLIENT_ID',
    channelId: 'YOUR_CHANNEL_ID',

    // User identification (from your system)
    externalUserId: '<%= current_user.id %>', // Your user ID
    externalUserName: '<%= current_user.name %>', // Your user name

    // Skip asking for info since user is logged in
    askForName: false,
    askForEmail: false,

    // Personalized
    agentName: 'Support Team',
    primaryColor: '#4A90E2',
    language: 'en',
  };
</script>
<script src="https://vambeai.com/webchat.js"></script>
```

### Example 3: Multilingual Support

```javascript theme={null}
// Detect user's browser language
const userLang = navigator.language.startsWith('es') ? 'es' : 'en';

window.embeddedWebchatConfig = {
  clientId: 'YOUR_CLIENT_ID',
  channelId: 'YOUR_CHANNEL_ID',

  language: userLang,

  // Language-specific suggestions
  suggestedQuestions:
    userLang === 'es'
      ? [
          '¿Qué servicios ofrecen?',
          '¿Cómo puedo empezar?',
          '¿Cuáles son sus precios?',
        ]
      : [
          'What services do you offer?',
          'How can I get started?',
          'What are your prices?',
        ],

  chatWithUsText: userLang === 'es' ? 'Habla con nosotros' : 'Chat with us',
};
```

### Example 4: Dark Theme for Dark Websites

```html theme={null}
<script>
  window.embeddedWebchatConfig = {
    clientId: 'YOUR_CLIENT_ID',
    channelId: 'YOUR_CHANNEL_ID',

    // Dark theme for dark websites
    darkTheme: true,
    primaryColor: '#BB86FC',

    agentName: 'Night Owl Support',
    chatWithUsText: "We're here 24/7",
  };
</script>
<script src="https://vambeai.com/webchat.js"></script>
```

## Customization Tips

### Choosing Colors

* **Primary Color**: Used for buttons, headers, and accents
* **Brand Alignment**: Use your brand's primary color
* **Contrast**: Ensure good contrast with white/dark backgrounds
* **Test**: Test with both light and dark themes

```javascript theme={null}
// Brand color examples
primaryColor: '#2994FF'; // Vambe blue
primaryColor: '#FF6B6B'; // E-commerce red
primaryColor: '#4CAF50'; // Success green
primaryColor: '#9C27B0'; // Tech purple
```

### Positioning the Widget

```javascript theme={null}
// Bottom right (default)
xPosition: 20,
yPosition: 20

// Bottom left
xPosition: 20,
yPosition: 20,
// + CSS: right -> left position

// Custom positioning
xPosition: 100,  // Further from edge
yPosition: 80    // Higher up
```

### Creating Effective Suggested Questions

**✅ Good Examples**:

```javascript theme={null}
suggestedQuestions: [
  'What are your business hours?', // Practical
  'How much does it cost?', // Clear
  'Can you help me track my order?', // Specific
  'Do you offer custom solutions?', // Open-ended
];
```

**❌ Avoid**:

```javascript theme={null}
suggestedQuestions: [
  'Hello', // Too vague
  'I have a question', // Not specific
  'Click here', // Not a question
  'Tell me everything', // Too broad
];
```

## Integration with User Data

### Pass User Information

If users are logged in on your website, pass their information:

```javascript theme={null}
// Example with template engine (EJS, Handlebars, etc.)
window.embeddedWebchatConfig = {
  clientId: "YOUR_CLIENT_ID",
  channelId: "YOUR_CHANNEL_ID",

  // User info from your session
  externalUserId: "<%= user.id %>",
  externalUserName: "<%= user.full_name %>",

  // Skip collection if already have data
  askForName: false,
  askForEmail: <%= user.email ? 'false' : 'true' %>
};
```

### Add Metadata After Chat Start

Use the webchat metadata endpoint to enrich contact data:

```javascript theme={null}
// After user interacts with chat
async function enrichChatContact(externalUserId, userData) {
  await fetch('https://api.vambe.me/api/public/webchat/contact/add-metadata', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': 'your_api_key_here',
    },
    body: JSON.stringify({
      externalUserId: externalUserId,
      metadata: {
        subscription_tier: userData.tier,
        account_status: userData.status,
        lifetime_value: userData.ltv.toString(),
        last_purchase: userData.lastPurchaseDate,
      },
    }),
  });
}
```

## Common Integrations

### WordPress

Add to your theme's `footer.php` before `</body>`:

```php theme={null}
<script>
window.embeddedWebchatConfig = {
  clientId: "<?php echo get_option('vambe_client_id'); ?>",
  channelId: "<?php echo get_option('vambe_channel_id'); ?>",
  agentName: "<?php bloginfo('name'); ?> Support",
  language: "<?php echo substr(get_locale(), 0, 2); ?>"
};
</script>
<script src="https://vambeai.com/webchat.js"></script>
```

### React/Next.js

```typescript theme={null}
// components/VambeChat.tsx
import { useEffect } from 'react';

export function VambeChat() {
  useEffect(() => {
    // Set configuration
    (window as any).embeddedWebchatConfig = {
      clientId: process.env.NEXT_PUBLIC_VAMBE_CLIENT_ID,
      channelId: process.env.NEXT_PUBLIC_VAMBE_CHANNEL_ID,
      agentName: "Support Team",
      primaryColor: "#2994FF",
      language: "en",
      suggestedQuestions: [
        "How can I upgrade my plan?",
        "Do you offer a free trial?",
        "How do I contact sales?"
      ]
    };

    // Load script
    const script = document.createElement('script');
    script.src = 'https://vambeai.com/webchat.js';
    script.async = true;
    document.body.appendChild(script);

    return () => {
      // Cleanup if needed
      document.body.removeChild(script);
    };
  }, []);

  return null;
}

// In your layout/page
import { VambeChat } from '@/components/VambeChat';

export default function Layout({ children }) {
  return (
    <>
      {children}
      <VambeChat />
    </>
  );
}
```

### Vue.js

```vue theme={null}
<!-- components/VambeChat.vue -->
<template>
  <div></div>
</template>

<script>
export default {
  name: 'VambeChat',
  mounted() {
    window.embeddedWebchatConfig = {
      clientId: process.env.VUE_APP_VAMBE_CLIENT_ID,
      channelId: process.env.VUE_APP_VAMBE_CHANNEL_ID,
      agentName: 'Customer Support',
      primaryColor: '#42b983',
      language: this.$i18n.locale,
    };

    const script = document.createElement('script');
    script.src = 'https://vambeai.com/webchat.js';
    document.body.appendChild(script);
  },
};
</script>
```

### Shopify

Add to **Online Store** → **Themes** → **Edit Code** → `theme.liquid` before `</body>`:

```liquid theme={null}
<script>
window.embeddedWebchatConfig = {
  clientId: "{{ settings.vambe_client_id }}",
  channelId: "{{ settings.vambe_channel_id }}",
  agentName: "{{ shop.name }} Support",
  primaryColor: "{{ settings.color_primary }}",
  askForEmail: true,
  language: "{{ request.locale.iso_code }}",
  suggestedQuestions: [
    "Do you ship internationally?",
    "What's your return policy?",
    "How can I track my order?"
  ]
};
</script>
<script src="https://vambeai.com/webchat.js"></script>
```

## Advanced Features

### Conditional Loading

Only load webchat on specific pages:

```javascript theme={null}
// Only on product and checkout pages
if (
  window.location.pathname.includes('/products') ||
  window.location.pathname.includes('/checkout')
) {
  window.embeddedWebchatConfig = {
    clientId: 'YOUR_CLIENT_ID',
    channelId: 'YOUR_CHANNEL_ID',
    chatWithUsText: 'Need help with your purchase?',
  };

  const script = document.createElement('script');
  script.src = 'https://vambeai.com/webchat.js';
  document.body.appendChild(script);
}
```

### Dynamic User Identification

```javascript theme={null}
// When user logs in, update webchat config
function initializeWebchatForUser(user) {
  window.embeddedWebchatConfig = {
    clientId: 'YOUR_CLIENT_ID',
    channelId: 'YOUR_CHANNEL_ID',
    externalUserId: user.id,
    externalUserName: user.name,
    askForName: false,
    askForEmail: false,
  };

  // Reload webchat with user context
  const script = document.createElement('script');
  script.src = 'https://vambeai.com/webchat.js';
  document.body.appendChild(script);
}
```

### Custom Styling

While the widget is pre-styled, you can adjust positioning and behavior:

```css theme={null}
/* Hide webchat on mobile */
@media (max-width: 768px) {
  #vambe-webchat {
    display: none;
  }
}

/* Custom z-index if needed */
#vambe-webchat {
  z-index: 9999 !important;
}
```

## Best Practices

### Performance

1. **Load Asynchronously**: The script loads async by default
2. **After Page Load**: Consider loading after main content
3. **Lazy Load**: Load only when user interacts

```javascript theme={null}
// Load on first user interaction
let chatLoaded = false;

document.addEventListener(
  'mousemove',
  function loadChat() {
    if (!chatLoaded) {
      chatLoaded = true;
      // Load webchat script
      const script = document.createElement('script');
      script.src = 'https://vambeai.com/webchat.js';
      document.body.appendChild(script);

      // Remove listener
      document.removeEventListener('mousemove', loadChat);
    }
  },
  { once: true },
);
```

### User Experience

1. **Collect Minimal Info**: Only ask for necessary information
2. **Clear Suggestions**: Provide helpful suggested questions
3. **Brand Consistency**: Match your website's colors and style
4. **Mobile Friendly**: Test on mobile devices
5. **Response Time**: Configure AI for quick responses

### Privacy & Compliance

```html theme={null}
<!-- Add privacy notice if collecting emails/phones -->
<script>
  window.embeddedWebchatConfig = {
    clientId: 'YOUR_CLIENT_ID',
    channelId: 'YOUR_CHANNEL_ID',
    askForEmail: true,
    // Note: Inform users about data collection in your privacy policy
  };
</script>
```

## Troubleshooting

### Widget Not Appearing

<AccordionGroup>
  <Accordion title="Check script is loaded">
    Open browser console and verify:

    ```javascript theme={null}
    console.log(window.embeddedWebchatConfig);
    ```

    Should show your configuration object.
  </Accordion>

  <Accordion title="Verify IDs are correct">
    Check that `clientId` and `channelId` match your Vambe account settings.
  </Accordion>

  <Accordion title="Check for JavaScript errors">
    Open browser DevTools (F12) → Console tab Look for errors related to the
    webchat script.
  </Accordion>

  <Accordion title="Verify script source">
    Ensure `https://vambeai.com/webchat.js` is accessible and loading.
  </Accordion>
</AccordionGroup>

### Widget Styling Issues

* **Z-index**: If widget appears behind other elements, adjust z-index
* **Mobile**: Test responsiveness on different screen sizes
* **Colors**: Verify hex color codes are valid
* **Images**: Ensure avatar URL is accessible and CORS-friendly

### Data Not Syncing

* **External User ID**: Verify externalUserId matches your system
* **Metadata Endpoint**: Use correct endpoint for webchat contacts
* **API Key**: Ensure API key has proper permissions

## Testing Your Integration

### Local Testing

1. **Open your website** in a browser
2. **Click the chat button** - should open chat interface
3. **Send a test message** - verify it appears in Vambe dashboard
4. **Check contact creation** - go to Vambe → Contacts
5. **Verify metadata** - if using externalUserId, check it's saved

### Production Checklist

* [ ] Chat button visible and positioned correctly
* [ ] Colors match your brand
* [ ] Suggested questions are relevant
* [ ] Agent name and icon display properly
* [ ] Language is correct
* [ ] Form fields (name/email/phone) work as expected
* [ ] Messages appear in Vambe dashboard
* [ ] Contacts are created with correct information
* [ ] Mobile version works properly
* [ ] No console errors

## Related Resources

* [Webchat Metadata Endpoint](/reference/webchat/add-webchat-contact-metadata) - Add metadata to webchat contacts
* [Contact Management](/reference/contact/get-info-of-an-ai-contact) - Manage webchat contacts
* [Analytics](/docs/analytics) - Track webchat performance
* [Webhooks](/docs/webhooks) - Real-time notifications for webchat events
