Overview

The openChat API allows you to programmatically open the chat window and send a message on behalf of the user. This is useful for:
  • Sending automated support requests based on user actions
  • Creating contextual help buttons that send specific inquiries
  • Triggering chat conversations from forms, errors, or page events
  • Automating customer service workflows
For controlling widget visibility, see Show/Hide Widget.

Method

The widget exposes this method for opening the chat:
Open chat with optional message and auto-send control
window.Molin.openChat({ message, autoSend })

Alternative method (web component)

You can also use the web component selector:
Open chat using web component selector
document.querySelector("molin-shop-ai").openChat({ message, autoSend })

Parameters

options
object
Optional configuration object. Can be omitted entirely to simply open the chat without any message. When provided, can contain the following optional properties:
message
string
The message to send when opening the chat. If omitted, the chat opens without any pre-filled message.
autoSend
boolean
default:"false"
Whether to automatically send the message. When false (default), the message will only be prefilled in the input field for the user to review and send manually. When true, the message is sent immediately.
Valid function calls:
  • openChat() - Opens chat without any message
  • openChat({ message: "Hello" }) - Opens chat with pre-filled message (not sent)
  • openChat({ message: "Hello", autoSend: true }) - Opens chat and sends message immediately

Examples

Basic Usage - Open Chat Button

Basic Usage Example

Simple button that opens the chat widget
Basic Usage
// Method 1:
window.Molin.openChat()

// Method 2:
document.querySelector("molin-shop-ai").openChat()

Pre-filled Message - Product Inquiry

Pre-filled Message
// Method 1:
window.Molin.openChat({
  message:
    "I have questions about the product pricing, availability, and features. Can you help me with that?",
  autoSend: false,
})

// Method 2:
document.querySelector("molin-shop-ai").openChat({
  message:
    "I have questions about the product pricing, availability, and features. Can you help me with that?",
  autoSend: false,
})

Auto-send Messages - Support Scenarios

Auto-send Message Example

Quick support buttons that automatically send specific messages:
// Method 1:
window.Molin.openChat({
  message:
    "I need help with my order status. Can you please check what's happening with my recent purchase?",
  autoSend: false,
})

// Method 2:
document.querySelector("molin-shop-ai").openChat({
message:
"I need help with my order status. Can you please check what's happening with my recent purchase?",
autoSend: false,
})

Smart Search with AI Integration

AI Search Integration
// When user searches, open chat with search context
const searchQuery = "wireless headphones"
window.Molin.openChat({
  message: `I'm looking for: ${searchQuery}. Can you help me find what I need?`,
  autoSend: false
})
The search component integrates AI assistance with product search, allowing users to get personalized recommendations through the chat widget.

Product Grid with AI Expert

White fabric pouch with white zipper, black zipper pull, and black elastic loop.

Nomad Pouch

White and Black$50
Front of tote bag with washed black canvas body, black straps, and tan leather handles and accents.

Zip Tote Basket

Washed Black$140
Front of satchel with blue canvas body, black straps and handle, drawstring top, and front zipper pouch.

Medium Stuff Satchel

Blue$220
Front of zip tote bag with black canvas, black handles, and orange drawstring top.

High Wall Tote

Black and Orange$210
Front of zip tote bag with white canvas, blue canvas straps and handle, and front zipper pocket.

Zip High Wall Tote

White and blue$150
Product Grid with AI Expert
// When user clicks on AI expert card
window.Molin.openChat({
  message: "I need help finding the right product. Can you assist me with personalized recommendations?",
  autoSend: false
})
The product grid includes an AI expert consultation option that opens the chat widget with a pre-filled message for personalized assistance.

Interactive Playground

Try the openChat API with this interactive example:
This playground will only work if the Molin widget is installed on this documentation page. If you’re viewing this in the documentation, it may show a warning that the widget is not loaded.

Technical Note

The openChat method is only available after the widget script has loaded. Always check that the widget is available before calling methods. You can use either approach: Method 1: Check window.Molin
if (window.Molin && window.Molin.openChat) {
  window.Molin.openChat({ message: "Your message here" })
}
Method 2: Check if web component is loaded
const molinWidget = document.querySelector("molin-shop-ai")
if (molinWidget && typeof molinWidget.openChat === "function") {
  molinWidget.openChat({ message: "Your message here" })
}