ドキュメント

Widget reference

Configuration options, callbacks, context providers and custom actions for the chat widget.

All options are passed to the MochiiWidget constructor. Only apiKey is required.

const widget = new MochiiWidget({
  apiKey: "YOUR_API_KEY",
  // ...options
});

Appearance

OptionTypeDescription
position"bottom-right" or "bottom-left"Corner in which the chat bubble appears.
theme"light", "dark" or "auto"Color theme. auto follows the visitor's system setting.
primaryColorstringBrand color as a hex value, for example "#7C3AED".
widthnumberWidth of the chat window in pixels.
heightnumberHeight of the chat window in pixels.

Branding and messages

OptionTypeDescription
titlestringTitle shown in the chat header.
brandNamestringName of the assistant.
avatarstringURL of the assistant's avatar image.
inputPlaceholderstringPlaceholder text in the message box.
firstMessagesstring[]Messages shown when the chat opens.
suggestedMessagesstring[]Quick replies offered to the visitor.
persistChatbooleanKeep the conversation when the visitor returns.
domainstringBase URL of the Mochii API. Use https://www.mochii.ai.

Contextual messages

The widget can generate its greeting and suggestions from the page the visitor is on:

new MochiiWidget({
  apiKey: "YOUR_API_KEY",
  generateContextualMessages: {
    enabled: true,
    prompt: "Based on the current page, write a relevant greeting",
    generateSuggestions: true,
  },
});

Callbacks

new MochiiWidget({
  apiKey: "YOUR_API_KEY",
  callbacks: {
    onOpen: () => console.log("Widget opened"),
    onClose: () => console.log("Widget closed"),
    onMessage: (message) => console.log("New message", message),
  },
});

Context providers

Context providers tell the chatbot about the current page and visitor, so it can give more relevant answers. Both functions are called when the chatbot needs the information.

new MochiiWidget({
  apiKey: "YOUR_API_KEY",
  contextProvider: {
    getPageContext: async () => ({
      url: window.location.href,
      title: document.title,
      description: document
        .querySelector('meta[name="description"]')
        ?.getAttribute("content"),
    }),
    getUserContext: async () => ({
      userId: "user_123",
      preferences: {},
    }),
  },
});

Only pass information you are comfortable sharing with the chatbot, and nothing the visitor has not agreed to share.

Custom actions

Actions let the chatbot do things on your site, such as navigating to a page or opening a dialog. Describe each action and its parameters; the chatbot decides when to call it.

new MochiiWidget({
  apiKey: "YOUR_API_KEY",
  actions: [
    {
      name: "navigateTo",
      description: "Navigate to a specific page",
      parameters: {
        path: {
          type: "string",
          description: "The path to navigate to",
          required: true,
        },
      },
      execute: async ({ path }) => {
        window.location.href = path;
        return { success: true };
      },
    },
  ],
});

Write clear descriptions. The chatbot relies on them to choose the right action and fill in the parameters.