For the complete documentation index, see llms.txt. This page is also available as Markdown.

JavaScript API

Available API methods to programmatically interface with the chat widget

We expose some functions in the Frontend to programmatically control the Chat window.

Calls made before the widget finishes loading are queued and run once it loads. Every call requires a valid window.pylon.chat_settings with app_id, email, and name (see Chat Setup).

window.Pylon("show")

Opens the chat window. Useful for programmatically triggering the chat window from an explicit support flow or button on your site.

window.Pylon("hide")

Closes the chat window.

window.Pylon("onShow")

Pass in a callback function that is called when the chat is shown. Useful for managing state of the chat window. If you pass in null as the callback function, the existing callback is removed.

window.Pylon("onShow", function () {
  console.log("show chat!");
});

window.Pylon("onHide")

Pass in a callback function that is called when the chat is hidden. Useful for managing state of the chat window. If you pass in null as the callback function, the existing callback is removed.

window.Pylon("onHide", function () {
  console.log("hide chat!");
});

window.Pylon("hideChatBubble")

Hides the chat bubble (and closes the chat window if it's open). Useful for hiding it in situations where it’s inappropriate or it’s blocking something underneath (ie an open modal).

This has no effect when Show Chat Bubble is turned off in the widget's settings.

window.Pylon("showChatBubble")

Shows the chat bubble again after you've hidden it with hideChatBubble.

This has no effect when Show Chat Bubble is turned off in the widget's settings. In that case, use show to open the chat window directly.

window.Pylon("onShowChatBubble") / window.Pylon("onHideChatBubble")

Pass in a callback function that is called when the chat bubble is shown or hidden. Pass in null to remove the existing callback.

window.Pylon("setTheme", "string")

Sets the chat window theme based on the provided argument. Valid values are light and dark, e.g. window.Pylon("setTheme", "dark"). The widget uses light mode until you call this, and remembers the choice in the user's browser. You can set your light mode and dark mode palettes on the widget's Styling tab (see Styling).

window.Pylon("onChangeUnreadMessagesCount")

Pass in a callback function that is called immediately and when the unread message count changes. If you pass in null as the callback function, the existing callback is removed.

window.Pylon("onPopupMessageVisibilityChange")

Pass in a callback function that is called with true or false when the preview of a new reply above the chat bubble appears or disappears. Pass in null to remove the existing callback.

window.Pylon("onPopupSurveyVisibilityChange")

Pass in a callback function that is called with true or false when a popup survey appears or disappears. Pass in null to remove the existing callback.

window.Pylon("onSurveySubmitted")

Pass in a callback function that is called when the user submits a popup survey. It receives an object with surveyType (CSAT, NPS, or GENERIC), score, and, if the user left one, feedback. Pass in null to remove the existing callback.

window.Pylon("setNewIssueCustomFields")

Pass in an object of custom field slugs to their values. New issues created through the Chat Widget messaging will have these custom fields values set. Values can be strings, numbers, or booleans. Fields with null or undefined values are ignored.

You must first create the corresponding custom fields inside of Pylon.

Be sure to use the custom field slug, not the label!

Example:

You can find the slug value on the custom fields page next to the custom field.

window.Pylon("setTicketFormFields")

Pass in an object of field slugs to their values. Ticket forms in the Chat Widget will have these values set as default values. For multi-select fields, pass an array of values.

Note that the passed object will apply to all ticket forms. Superfluous and/or invalid fields will be ignored.

Example:

You can find the slug value on the custom fields page next to the custom field.

window.Pylon("setVisibleTicketForms")

Pass in an array of ticket form slug strings to make those ticket forms visible in the Chat Widget. Pass in null to revert back the originally visible ticket forms.

Only ticket forms that are selected in a Form Set within the Chat Widget's settings are allowed. In the example below, the ticket forms with the slugs test-ticket-form-1 and test-ticket-form-2 will not become visible unless they are also selected as part of any Form Set within the Chat Widget's settings.

Example:

The ticket form slug can be found in the edit ticket form page under Form Slug.

window.Pylon("showNewMessage", "string")

Opens a new conversation with a message prepopulated in the editor. For example, use this when a user runs into an error in your application and you want to prefill a message they can submit. Call it with no message to open a blank new conversation.

Optionally, this string can also be HTML. For example, for rendering a link. Pass an optional argument indicating the message to be shown is HTML.

NOTE: Only specific HTML tags are supported: <a>, <b>, <p>, and <i>. If other tags are used, the editor may error.

To set custom fields on just this conversation, pass customFields. These are merged over any values set with setNewIssueCustomFields.

The message can be at most 2,500 characters. showNewMessage does nothing when the Chat module is turned off for the user.

window.Pylon("showIssue", "string")

Opens the chat window to an existing conversation, by issue ID. Use it with onActiveIssueChange or getCurrentIssue to restore the conversation a user had open, for example after a page reload.

window.Pylon("getCurrentIssue")

Returns the conversation open in the chat window as { issueID, issueNumber }, or null if none is open. Unlike other methods, this returns a value directly, so call it after the widget has loaded (calls queued before then return nothing).

window.Pylon("onActiveIssueChange")

Pass in a callback function that is called when the open conversation changes. It receives { issueID, issueNumber }, or null when the user leaves the conversation. If a conversation is already open when you register the callback, it is called right away. Pass in null to remove the existing callback.

window.Pylon("showTicketForm", "string")

Navigates the chat bubble to a specified ticket form, by ticket form slug.

The ticket form slug can be found in the edit ticket form page under Form Slug.

window.Pylon("showKnowledgeBaseArticle", "string")

Navigates the chat bubble to a specified knowledge base article, by article ID.

The article ID can be found in the URL of the public view of a knowledge base article, as the first set of numbers following articles/. In the following example, the identifier is "1234567899"

https://support.usepylon.com/articles/1234567899-how-to

It can also be found in the article settings panel in the Pylon app, under the article slug input.

window.Pylon("setLocale", "string")

Sets the widget's language and saves it as the user's preferred language. This reloads the page so the new language takes effect.

Supported values: en, es, et, fr, de, it, ja, ko, and pt-br (pt is treated as pt-br). The language must also be one of your organization's supported languages.

If you already know the user's language when the page loads, set locale in chat_settings instead (see Chat Setup). It avoids the reload and takes priority over the saved preference.

Last updated

Was this helpful?