JavaScript

Send a Message

To send a message to other participants in the Conversation, you need to call the client.sendMessageTextEvent() method.

You can do this by adding a handler for the message box's Submit button at the end of the run function:

// Listen for clicks on the submit button and send the existing text value
sendButton.addEventListener("click", () => {
  client
    .sendMessageTextEvent(CONVERSATION_ID, messageTextarea.value)
    .then((timestamp) => {
      console.log("Successfully sent text message at ", timestamp);
      messageTextarea.value = "";
    })
    .catch((error) => {
      console.error("Error sending text message: ", error);
    });
});