Embed the Maison concierge chat widget in the website of a Payload 3 project — the Next.js pages that show your Payload content to guests. Payload official site ↗
(frontend) route group. Nothing is installed in the Payload admin panel, and there is no Maison plugin for Payload. If your website is a separate app that reads Payload over its API, follow the guide for that app instead: Next.js, React, Vue, Angular or plain HTML.Prerequisites
- A Payload 3 project with its website in the same Next.js app (the official
websiteandblanktemplates are set up this way) - Your Client UUID — find it in the Business Console under Settings
Steps
Create a MaisonChat client component
This is the same component as the Next.js guide. The
'use client'directive must be the first line, because the component usesuseEffectandwindow.tsx// src/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; }Render it in the frontend root layout
Open
src/app/(frontend)/layout.tsx(in an existing Next.js app, the root layout of whichever route group holds your website) and renderMaisonChatas the last child of<body>. Keep everything else in your layout as it is — the website template's providers, header and footer stay where they are.tsx// src/app/(frontend)/layout.tsx import React from 'react' import { MaisonChat } from '@/components/MaisonChat' import './styles.css' export default async function RootLayout(props: { children: React.ReactNode }) { const { children } = props return( <html lang="en"> <body> <main>{children}</main> <MaisonChat clientId="YOUR_CLIENT_UUID" /> </body> </html> ) }Verify in DevTools
Open a page of your website (not
/admin) and the launcher appears in the corner. In DevTools, the Elements tab shows#maison-chat-iconin the DOM. The admin panel shows no chat icon. 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.
src/app/(payload)/layout.tsx renders the Payload admin panel. It is generated by Payload and not meant to be edited, and the widget there would show to your editors, not your guests.Optional: let editors manage the widget in Payload
A Payload Global gives editors one settings screen in the admin panel to switch the chat off or change the Client UUID, without a code change. The layout reads it on the server with Payload's Local API, which skips access control by default, so the Global needs no public read access and stays editable only by signed-in admin users.
Add a Maison Global
typescript// src/globals/Maison.ts import type { GlobalConfig } from 'payload' import { revalidatePath } from 'next/cache' export const Maison: GlobalConfig = { slug: 'maison', label: 'Maison chat', fields: [ { name: 'enabled', type: 'checkbox', label: 'Show the Maison chat on the website', defaultValue: true, }, { name: 'clientId', type: 'text', label: 'Maison Client UUID', }, ], hooks: { // Re-render cached pages so a saved change shows without a redeploy. afterChange: [ ({ doc, req: { context } }) => { if(!context.disableRevalidate) revalidatePath('/', 'layout') return doc }, ], }, }Register it in your Payload config
typescript// src/payload.config.ts import { Maison } from './globals/Maison' export default buildConfig({ // ...the rest of your config globals: [Maison], // the website template: [Header, Footer, Maison] })Regenerate your Payload types
The official templates ship this script (it runs
payload generate:types), which adds themaisonGlobal topayload-types.tsso the layout below is typed.bashpnpm generate:typesRead the Global in the frontend layout
Replace the fixed Client UUID from step 2. The widget renders only when the box is ticked and a Client UUID is filled in.
tsx// src/app/(frontend)/layout.tsx import React from 'react' import config from '@payload-config' import { getPayload } from 'payload' import { MaisonChat } from '@/components/MaisonChat' import './styles.css' export default async function RootLayout(props: { children: React.ReactNode }) { const { children } = props const payload = await getPayload({ config }) const maison = await payload.findGlobal({ slug: 'maison' }) return( <html lang="en"> <body> <main>{children}</main> {maison.enabled && maison.clientId ? <MaisonChat clientId={maison.clientId} /> : null} </body> </html> ) }Fill it in
In the admin panel, open Maison chat under Globals, paste your Client UUID and save. Reload a page of your website: the launcher appears. Untick the box and save to hide it.
next.config headers or a middleware), add maison-labs.com to its script-src allowlist. When the browser still blocks a request, its console names the directive that blocked it.For the full list of configuration options, control methods, and callbacks, see the Widget SDK Reference.
Common mistakes
(frontend) root layout.useEffect. The MaisonChat file must start with 'use client'.afterChange hook in the Global revalidates them; without it, the change appears only after the cache expires or the next deploy.Not sure if it's set up correctly? Use the Site Diagnostic tool.