---
schema_version: "1"
id: 32ff2a6f8a1e652796650bfb35a50dc673565b0021e9818ca0368119b513af66
title: Send Message as the End User in Enhanced Web Chat
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/messaging-web/guides/send-message.md
canonical_url: https://developer.salesforce.com/docs/service/messaging-web/guide/send-message.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4a41b9608421ad7003cf30e08c7b8b1ce23a847522933e61b2a10e4543104196
products:
  - Enhanced Web Chat
  - Service Cloud Developer Content
---
# Send Message as the End User in Enhanced Web Chat

Send search queries, user actions, or any text to the Agentforce Service Agent, bot, or service rep in the chat window by displaying it as if the end user had sent it.

This sample code illustrates how you can use this API.

```javascript
<script>
  // In this example, we will send a message once bot has joined the conversation.
  window.addEventListener("onEmbeddedMessagingFirstBotMessageSent", (event) => {
    console.log("Received the onEmbeddedMessagingFirstBotMessageSent event…")
    sendMessage();
  });

  function sendMessage() {
    embeddedservice_bootstrap.utilAPI.sendTextMessage("Text");
      .then(() => {
        // Success handler used to perform actions when the message is sent successfully.
        // For example, create a method that logs the message was successfull.
        logMessageSuccessfullySent();
      }).catch(() => {
        // Error handler used to perform actions if the message fails to send.
        // For example, log the failure.
        logMessageFailed();
      }).finally(() => {
        // Finally handler used to perform any clean-up actions
        // regardless of whether the message was successfully sent or not.
        // For example, create a method that logs attempt to send message.
        logMessageAttempt();
      });
  }
</script>
```

Use the event handlers in the `utilAPI.sendMessage()` method to perform actions after the message is sent.

- `then` - Use this handler to perform actions when the message is sent successfully.
- `catch` - Use this handler to perform actions if the message fails to send.
- `finally` - Use this handler to perform clean-up actions, regardless of whether the message was successfully sent or not.
