Strapi logo

Strapi Integration

Embed the Maison concierge chat widget in the website that shows your Strapi 5 content to guests. Strapi official site ↗

The widget goes on your website, not in Strapi. Strapi is a headless CMS: it stores your content and serves it over an API, and a separate frontend renders the pages guests see. The chat widget is added to that frontend. Nothing is installed in the Strapi admin panel, and there is no Maison plugin for Strapi.

Prerequisites

  • The source code of the frontend that renders your Strapi content
  • Your Client UUID — find it in the Business Console under Settings
  • For the optional settings section: a Strapi 5 project you can run in development

Follow the guide for your frontend

Add the widget exactly as the guide for your frontend framework describes. The worked example below uses Next.js.

Example: a Next.js website on Strapi

  1. Create a MaisonChat client component

    The same component as the Next.js guide. The 'use client' directive must be the first line.

    tsx
    // components/MaisonChat.tsx
    'use client';
    
    import { useEffect } from 'react';
    
    export function MaisonChat({ clientId }: { clientId: string }) {
      useEffect(() => {
        const script = document.createElement('script');
        script.src = 'https://maison-labs.com/agent-inject.bundle.js';
        script.setAttribute('data-cfasync', 'false');
        script.setAttribute('data-no-minify', '1');
        script.setAttribute('data-no-optimize', '1');
        script.setAttribute('data-no-defer', '1');
        script.setAttribute('data-noptimize', '1');
        script.onload = () => {
          const sessionId = new URLSearchParams(window.location.search).get('mcbsid');
          const mcbs = (window as any).initMcbs({
            clientId,
            sessionId,
            // locale: 'en-US',                     // Override browser locale
            // iconPosition: { top: 0, bottom: 20, left: 0, right: 20 },  // Chat icon position (px)
            // loadChatWindow: 'load',   // When the chat window loads: 'load' (default), 'interaction', 'lazy' or 'eager'
            // onSessionUpdate: (id) => console.log('Session:', id),
            // onLocaleUpdate: (locale) => console.log('Locale:', locale),
          });
          mcbs.showIcon();
        };
        document.head.appendChild(script);
    
        return() => {
          document.head.removeChild(script);
        };
      }, [clientId]);
    
      return null;
    }
  2. Add MaisonChat to your root layout

    Render it once in app/layout.tsx, so every page of the website gets the widget.

    tsx
    // app/layout.tsx
    import { MaisonChat } from '@/components/MaisonChat';
    
    export default function RootLayout({
      children,
    }: {
      children: React.ReactNode;
    }) {
      return(
        <html lang="en">
          <body>
            {children}
            <MaisonChat clientId="YOUR_CLIENT_UUID" />
          </body>
        </html>
      );
    }
  3. Verify in DevTools

    Open a page of your website and the launcher appears in the corner. In DevTools, the Elements tab shows #maison-chat-icon in the DOM. No chat icon? Check that the Maison script loaded and that the client UUID is the one for your hotel. An opening (welcome) message is not required: a hotel without one still shows the launcher, and its chat opens empty.

Optional: manage the widget from Strapi

A single type gives editors one entry in the Strapi admin to switch the chat off or change the Client UUID without a frontend deploy. The website reads it over Strapi's REST API. This is ordinary Strapi content you define yourself; Maison adds nothing to Strapi.

  1. Create a Maison settings single type

    The Content-type Builder only works in development, so run Strapi locally. Open Content-type Builder, choose Create new single type and name it Maison settings (API ID maison-setting). Leave Draft & publish off in the Advanced settings tab. Add a Boolean field named enabled with the default value true, and a Text (short text) field named clientId, then save. Strapi writes the type to src/api/maison-setting/content-types/maison-setting/schema.json with its routes, controller and service; deploy them like any other code change.

    json
    {
      "kind": "singleType",
      "collectionName": "maison_settings",
      "info": {
        "singularName": "maison-setting",
        "pluralName": "maison-settings",
        "displayName": "Maison settings"
      },
      "options": {
        "draftAndPublish": false
      },
      "attributes": {
        "enabled": {
          "type": "boolean",
          "default": true
        },
        "clientId": {
          "type": "string"
        }
      }
    }
  2. Let the website read it

    Content types are private by default. Go to Settings › Users & Permissions plugin › Roles, open the Public role, find Maison settings in the Permissions tab, tick find only, and save. Do this on every Strapi environment your website reads from.

  3. Fill it in

    In the Content Manager, open Maison settings under Single types, paste your Client UUID and save. If you turned Draft & publish on, also click Publish: the REST API returns only published content.

  4. Read it from the frontend

    A single type has one endpoint, named after its singular API ID. Strapi 5 returns the fields directly on data.

    http
    GET {STRAPI_URL}/api/maison-setting
    json
    {
      "data": {
        "id": 1,
        "documentId": "…",
        "enabled": true,
        "clientId": "YOUR_CLIENT_UUID",
        "createdAt": "…",
        "updatedAt": "…"
      },
      "meta": {}
    }

    In the Next.js example, read it in the root layout (on the server, cached for a minute) and render the widget only when it is switched on. Set STRAPI_URL to your Strapi address. Another frontend makes the same request and passes data.clientId to the initMcbs call from its guide.

    tsx
    // app/layout.tsx
    import { MaisonChat } from '@/components/MaisonChat';
    
    /** The Maison settings single type, as Strapi 5's REST API returns it (flat, no `attributes`). */
    interface MaisonSetting {
      enabled: boolean | null;
      clientId: string | null;
    }
    
    async function getMaisonSetting(): Promise<MaisonSetting | null> {
      const res = await fetch(`${process.env.STRAPI_URL}/api/maison-setting`, {
        next: { revalidate: 60 },
      });
      // 404 until an editor has saved the entry (and published it, with Draft & Publish on);
      // 403 until the Public role may read it. Either way: no widget, no broken page.
      if(!res.ok) return null;
      const { data } = (await res.json()) as { data: MaisonSetting | null };
      return data;
    }
    
    export default async function RootLayout({ children }: { children: React.ReactNode }) {
      const maison = await getMaisonSetting();
    
      return(
        <html lang="en">
          <body>
            {children}
            {maison?.enabled && maison.clientId ? <MaisonChat clientId={maison.clientId} /> : null}
          </body>
        </html>
      );
    }

For the full list of configuration options, control methods, and callbacks, see the Widget SDK Reference.

Common mistakes
Adding the widget to the Strapi admin panel. Guests never see the admin panel. The widget belongs in the frontend that renders your website.
403 Forbidden from /api/maison-setting. The Public role cannot read the type yet. Tick find for it under Users & Permissions › Roles › Public.
404 Not Found from /api/maison-setting. The entry has not been saved yet, or Draft & publish is on and it is not published.
Reading data.attributes. That is the Strapi 4 response shape. Strapi 5 returns the fields directly on data, as in data.clientId.

Not sure if it's set up correctly? Use the Site Diagnostic tool.