JavaScript API
Every command and event the widget understands.
Every call has the same shape: CorplandDesk("command", ...arguments). Calls made before the loader arrives are queued and run in order.
Commands
init
Starts the widget. Call it once.
CorplandDesk("init", {
key: "pk_live_...",
identity: { externalId: "user_123", name: "Ama Mensah", email: "ama@example.com", userHash: "..." },
hideLauncher: false,
launcherLabel: "Help",
});| Option | Type | Notes |
|---|---|---|
key | string | Required. Your widget key. |
identity | object | Optional. Same fields as identify. |
hideLauncher | boolean | Hide the floating button and open the widget from your own UI. |
launcherLabel | string | Text beside the launcher icon. Overrides the dashboard setting. |
identify
Tells Desk who the visitor is. With a valid userHash the contact is verified and sees their own history on any device. Without one, the visitor stays anonymous.
CorplandDesk("identify", {
externalId: "user_123",
name: "Ama Mensah",
email: "ama@example.com",
phone: "+233200000000",
avatar: "https://example.com/ama.png",
userHash: "<hex HMAC from your server>",
attributes: { plan: "pro", company: "Kente Labs" },
});Attributes show beside the conversation in the dashboard. Keys are strings; values are strings, numbers, booleans or null.
setAttributes
Adds or changes attributes for the current visitor without identifying them again.
CorplandDesk("setAttributes", { plan: "business", seats: 12 });track
Records an event on the contact's timeline. Useful for knowing what someone did right before they wrote in.
CorplandDesk("track", "export_failed", { format: "mp4" });open, close, toggle
CorplandDesk("open");
CorplandDesk("close");
CorplandDesk("toggle");openChat, newMessage
openChat opens the chat tab on the latest conversation. newMessage starts a new conversation, optionally with text already typed.
CorplandDesk("openChat");
CorplandDesk("newMessage", "Hi, I need help with billing");openFeedback
Opens the feedback tab: the idea board, voting and a rating.
reportBug
Opens the bug report form. Desk attaches the page address, browser, screen size and the last 20 console errors automatically. The visitor can add a screenshot.
CorplandDesk("reportBug", { title: "Checkout button does nothing", attributes: { cartId: "c_42" } });openTicket, openHelp
openTicket opens the support request form. openHelp opens the list of the visitor's own requests and their status. The list only shows for verified visitors.
showLauncher, hideLauncher
Show or hide the floating button without closing an open widget.
getUnread
Returns the unread count, or passes it to a callback.
CorplandDesk("getUnread", (count) => console.log(count));logout and shutdown
Forgets the visitor on this browser and closes the widget. Call it when your user signs out.
CorplandDesk("logout");Events
Listen with on and stop with off.
const onMessage = (event) => console.log(event);
CorplandDesk("on", "message", onMessage);
CorplandDesk("off", "message", onMessage);| Event | Payload | When |
|---|---|---|
ready | { open, agentsOnline } | The loader has booted. open says whether you are inside business hours, agentsOnline whether a teammate is in the dashboard. |
open | none | The widget opened. |
close | none | The widget closed. |
unread | number | The unread count changed. Use it for your own badge when the launcher is hidden. |
message | { conversationId, body, authorName } | A teammate replied. |
typing | { conversationId, typing, preview? } | The visitor started or stopped typing in the chat box. |
conversation | { conversationId } | The visitor started a conversation. |
ticket | the ticket | The visitor filed a bug report or request. |
feedback | the feedback | The visitor shared feedback or a rating. |
page | { url, title } | The visitor moved to another page in a single page app. |
identified | { name, email } | A signed out visitor typed their name and email on the intro screen. |
Single page apps
While the widget is connected it checks the address every two seconds and tells your team when the visitor moves to another page. You do not need to call anything on navigation.