Megadesk Documentation

Client-Side API

Discover how to interface with the chatbot using JavaScript on your website.

megadeskSendText

A global function available on the window object that programmatically sends a message to the Megadesk chatbot widget.

Signature

window.megadeskSendText(message: string)

Parameters

ParameterTypeDescription
messagestringThe text message to send to the chatbot

Usage

This API is useful for triggering the chatbot with pre-defined messages based on user actions, such as clicking buttons or links throughout your site.

Example

// Open chatbot with a product inquiry
document.getElementById("pricing-btn").addEventListener("click", () => {
  window.megadeskSendText("Tell me about your pricing plans.");
});

// Or in a React component
<button onClick={() => window.megadeskSendText("How do I get started?")}>
  Get Started
</button>

Notes

  • The function is attached to the global window object, so it's accessible from anywhere in your client-side code
  • Call it after the Megadesk widget script has loaded
  • Useful for creating contextual entry points to support (e.g., triggering specific help topics from relevant pages)