Chat Messenger JavaScript API

The messenger's JavaScript API lets your website open and close the chat, start a conversation with pre-filled text, react to unread messages, and update who the visitor is. Every command goes through HelpGuidesChat(command, value). Commands sent before the messenger finishes loading are queued and run in order.

Boot settings

These go in window.HelpGuidesChatSettings, or are passed to HelpGuidesChat('boot', settings).

SettingDescription
app_idRequired. Your messenger's app ID, from the install snippet.
user_id, email, nameThe signed-in user. Shown to your team in the inbox.
user_hashIdentity verification signature. See Chat Identity Verification.
attributesUp to 50 extra details shown to your team, as simple values (text, numbers or true/false), for example { plan: "Business", company: "Northwind" }
alignment"left" or "right", overriding the Position setting
hide_default_launchertrue hides the chat button, so you can open the chat from your own button
hide_notificationstrue stops reply previews appearing above the button
cookie_domainShare one visitor across subdomains, for example "example.com". Overrides Share visitors across subdomains of in Messenger settings.

Commands

CommandWhat it does
HelpGuidesChat('boot', settings)Starts the messenger with the boot settings above. The install snippet does this for you. Call it again after shutdown to show the messenger to the next visitor.
HelpGuidesChat('show')Opens the messenger
HelpGuidesChat('hide')Closes it
HelpGuidesChat('toggle')Opens or closes it
HelpGuidesChat('showMessages')Opens the visitor's list of conversations
HelpGuidesChat('showNewMessage', 'Hi!')Opens a new conversation with text pre-filled
HelpGuidesChat('showConversation', id)Opens a specific conversation
HelpGuidesChat('update')Tells the messenger the page changed. The messenger checks for page changes every five seconds, so single-page apps work without it.
HelpGuidesChat('update', { user_id, email, name, user_hash })A different user signed in. The messenger restarts as that user.
HelpGuidesChat('shutdown')Forgets the visitor on this browser and removes the messenger from the page. Call this when a user signs out.
HelpGuidesChat('getVisitorId')Returns the visitor's ID, or null if the messenger hasn't started yet

When a user signs out

Call shutdown as part of your sign-out. Until you do, the browser stays signed in to the chat as that user. The next person on the same browser would continue their session and see their conversations, and actions set to Only for signed-in customers would still look up the previous user's account. See Chat Actions.

shutdown also removes the messenger from the page. If the page stays open after sign-out and should still show the chat, boot it again for an anonymous visitor:

HelpGuidesChat('shutdown'); HelpGuidesChat('boot', { app_id: "YOUR_APP_ID" });

To send a customer straight into the chat, for example from an email or a text, add ?chat=1 to any page address on your site. No code is needed:

https://www.example.com/?chat=1&chat_name=JamesThe name isn't verified

A chat link only labels the visitor. It doesn't sign them in, and it can't reach anyone's past conversations. To recognize signed-in customers, use Chat Identity Verification.

Events

CommandCalled when
HelpGuidesChat('onUnreadCountChange', function (count) { … })The number of unread replies changes. It's also called immediately with the current count.
HelpGuidesChat('onShow', fn)The messenger opens
HelpGuidesChat('onHide', fn)The messenger closes

Examples

A "Chat with us" link that opens a pre-filled conversation:

Chat with us

Your own button with an unread count, with the default chat button hidden:

window.HelpGuidesChatSettings = { app_id: "YOUR_APP_ID", hide_default_launcher: true }; // …install snippet… HelpGuidesChat('onUnreadCountChange', function (n) { document.getElementById('chat-badge').textContent = n || ''; }); document.getElementById('chat-button').onclick = function () { HelpGuidesChat('toggle'); };

See Installing the Chat Messenger on Your Website for the full install snippet.