Skip to content

Documentation

JavaScript API

After the snippet loads, a global TicketDM object lets your site open the chat, identify the visitor and react to events.

Older snippets that use the global TopicDesk keep working. It is the same object.

Methods

MethodWhat it does
TicketDM.open()Opens the chat panel.
TicketDM.close()Closes the chat panel.
TicketDM.toggle()Opens the panel if it is closed, closes it if it is open.
TicketDM.identify({ name, email, userId })Tells TicketDM who the visitor is. All fields are optional.
TicketDM.on(event, fn)Listens for an event. Returns a function that removes the listener.

Open the chat from your own button

<button onclick="TicketDM.open()">Talk to us</button>

Identify a logged-in user

Call identify after your user logs in. Their name and email show up in the ticket in Telegram, and the email lets us follow up by email if they leave the page.

TicketDM.identify({
  name: "Jane Doe",
  email: "[email protected]",
  userId: "user_8231"
});
  • name: shown in the topic name and the ticket summary instead of a random visitor name.
  • email: used for email follow-up.
  • userId: your own id for the user, shown on the ticket so you can find them in your system.

Treat these values as unverified hints from the browser. Do not use them to decide who can see account data. Agents can also set the name and email from Telegram with /name and /email.

Events

EventFires when
readyThe widget has loaded and is ready.
openThe chat panel opens.
closeThe chat panel closes.
unreadThe number of unread agent messages changes. Your function receives the new count.
TicketDM.on("unread", function (count) {
  document.title = count ? "(" + count + ") My site" : "My site";
});

TicketDM.on("open", function () {
  console.log("chat opened");
});

var stop = TicketDM.on("ready", function () { /* ... */ });
stop(); // removes the listener

Calling before the widget has loaded

The snippet loads asynchronously, so TicketDM may not exist yet when your own code runs. Calls made before the widget is ready are safe if you use the queue. Put this before the snippet, or anywhere before you first call the API:

<script>
  window.TicketDM = window.TicketDM || { q: [] };
  TicketDM.q.push(["identify", { name: "Jane Doe", email: "[email protected]", userId: "user_8231" }]);
</script>
<script src="https://ticketdm.com/w.js" data-key="pk_live_…" data-cfasync="false" async></script>

Each queue entry is an array: the method name, followed by its arguments. The widget runs the queued calls as soon as it loads. After that, call the methods directly.

Single-page apps

The widget stays loaded as the visitor moves between pages, so you only add the snippet once. Call identify when the user logs in. If a different user logs in on the same browser, call identify again with their details.