> ## Documentation Index
> Fetch the complete documentation index at: https://botpress.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Send a message from user

You can programmatically send a message to your bot on the user's behalf using JavaScript.

> [!NOTE]
>
> You will need:
>
> * A website with an [embedded bot](https://botpress.com/docs/webchat/get-started/quick-start.md)
> * Familiarity with JavaScript

## Send a message on the user's behalf

To send a message on a user's behalf, use the [`window.botpress.sendMessage`](https://botpress.com/docs/webchat/interact/reference#sendmessage) method wrapped in an event listener:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.on('webchat:ready', () => {
  const message = "Hi there!"; // Replace with your own message
  window.botpress.sendMessage(message);
});
```

This snippet:

1. Waits until [Webchat is open and ready to receive messages](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-ready)
2. Sends the message on behalf of the user

> [!NOTE]
>
> The message won't send until the user has voluntarily opened the Webchat window.

## Start the conversation on the user's behalf

To proactively open Webchat and start a conversation on the user's behalf when they visit your website:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.on('webchat:initialized', (event) => {
    window.botpress.open()
})

window.botpress.on('webchat:ready', () => {
    const message = "Hi there!"; // Replace with your own message
    window.botpress.sendMessage(message);
});
```

This snippet:

1. Waits until [Webchat is initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized)
2. [Opens Webchat](https://botpress.com/docs/webchat/interact/open-close-webchat.md#open-webchat)
3. Waits until [Webchat is ready to receive messages](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-ready)
4. Sends the message on behalf on the user's behalf


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.