Webchat Embedding
Webchat Headless Mode
Learn how to use webchat in headless mode to create custom chat interfaces.
Headless mode allows you to use the core webchat functionality with your own custom UI. This is useful when you want complete control over the appearance and behavior of the chat interface.
Note: This example demonstrates only text messaging functionality. Advanced features like file uploads and voice notes are not covered in this basic implementation.
Getting Started
To use webchat in headless mode, you need to include the webchat core script in your HTML:
This script makes the StubberWebchatCore
object available globally, which provides all the necessary methods for connecting to and interacting with the webchat service.
Accessing the Webchat Core Object
After the script is loaded, you can access the webchat core object from the global window object:
This is typically done inside the window.onload event handler to ensure the script has finished loading:
Configuration Options
When configuring the webchat connection, you need to provide several options:
Sending Messages
To send a text message:
Receiving Messages
Messages are received through the payload_callback
function provided during configuration. Each message has the following structure:
Complete Example
Here's a complete example with a simple UI for sending and receiving messages:
API Reference
webchat_connection_config(config)
Configures the webchat connection.
webchat_connect()
Connects to the webchat service using the current configuration.
webchat_send_payload(payload)
Sends a message to the webchat service.