Skip to main content
Your page can put text into the chat for the visitor. Use setDraft() to prefill the message box so the visitor can review and send it, or sendMessage() to send it directly. For example, a returns page can open the chat with the order number already filled in. Neither method opens the chat. Call ChatWidget.open() when the visitor should see it.

Prefill a message

setDraft(text) replaces the text in the message box and keeps any attachments the visitor already added. Pass an empty string to clear the text. It does not send anything and does not save a draft between visits.

Send a message

sendMessage(text) sends the text as the current visitor, in their current conversation. If there is no conversation yet, it starts one. Text the visitor already typed and their attachments are kept.

Results

Both methods resolve to an object with a status. They do not throw. When sendMessage() returns requires_input or failed, it places your text in the message box if the box is empty, so the visitor can send it after completing the form.

Failure codes

Rules to follow

  • Do not retry automatically. A result of unknown, or a timeout after sending, can mean the message was delivered. Retrying can send it twice.
  • One call at a time. Calls from the same page run in order. While one message is still sending, the next can return busy.
  • Send once per action. If your page sends a message on load, for example after a redirect, make sure it does not send again when the page re-renders or the visitor comes back.
  • Contact and verification steps still apply. If the channel requires a contact form or OTP, the visitor must complete it before a message is sent.
  • Identify first. If the visitor is a signed-in customer, wait for identify() to finish before sending. See Identity.
  • Plain text only. Both methods accept a text string. To send a file, the visitor attaches it in the chat.
A page that opens chat about a specific order when the visitor arrives from an email link such as https://example.com/help?order=12345:
Validate anything you read from the URL before you put it in a message. The widget does not read your page’s URL parameters itself.