Control the chat window from your page

Open, close and toggle the Askocto chat window from your own buttons, send a message for the visitor and pass page context to the agent.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

The embed script adds a window.askocto object to your page. Its control methods let you open the chat from a help link, close it after a task, send a prefilled question and tell the agent which page the visitor is on.

Methods

Method What it does
open() Opens the chat window.
close() Closes the chat window. The conversation stays.
toggle() Opens the window if it is closed and closes it if it is open.
sendMessage(text) Sends a message as the visitor and opens the window if needed. The agent replies as usual.
setContext(object) Gives the agent facts about the page or session. Each call replaces the previous context.

Run your code after the script

The embed script uses defer, so window.askocto exists only after it has run. Put your own script after the embed tag, or wait for the ready event.

window.askocto.on("ready", () => {
  document.querySelector("#help-link").addEventListener("click", (event) => {
    event.preventDefault()
    window.askocto.open()
  })
})

If you use your own button instead of the bubble, hide the launcher with data-launcher="hidden". See Chat bubble.

Send a prefilled question

Use sendMessage for buttons that ask a specific question, such as "Track my order" on an order page.

document.querySelector("#track-order").addEventListener("click", () => {
  window.askocto.sendMessage("Where is my order?")
})

You should see the chat window open, the question appear as the visitor's message and the agent start to answer.

Pass page context

setContext accepts a plain object. Call it when the page loads and again when something relevant changes, such as the cart.

window.askocto.setContext({
  page: "checkout",
  cartItems: 3,
  plan: "pro",
})

The agent can use these values when it answers and when a procedure needs them. Send only what helps the conversation. Do not put passwords, payment details or other secrets in the context.

Tip: Open the chat automatically only when it helps, for example after a visitor has been on the pricing page for a while. A window that opens on every page load tends to get closed without being read.

Something unclear or missing? Tell us and we will fix the page.