JavaScript API - Methods
Pingstreams provides a Pingstreams JavaScript object that responds to a few methods. These allow you to update widget without a page refresh and interact with the messenger window.
Open the widget
Section titled “Open the widget”This will open the widget:
window.Pingstreams('open');Minimize the widget
Section titled “Minimize the widget”This will minimize the widget:
window.Pingstreams('close');Hide the widget
Section titled “Hide the widget”This will hide the widget:
window.Pingstreams('hide');Show the widget
Section titled “Show the widget”This will show the widget:
window.Pingstreams('show');Dispose the widget
Section titled “Dispose the widget”This will clear the widget html elements from the DOM:
window.Pingstreams('dispose');Reinitialize the widget
Section titled “Reinitialize the widget”If your app is characterized by very few page refreshes (ie., content is swapped out on the client side but no page refresh happens, Angular, React, jQuery, etc..) and lots of asynchronous JS, you’ll need to update Pingstreams when your user’s data changes. A reInit call simulates a page refresh, causing Pingstreams to reload the widget and all the configurations.
window.Pingstreams('reInit');Restart the widget
Section titled “Restart the widget”This method allow you to restart widget with the same user’s data without make a new authentication. This also maintains all the configurations.
window.Pingstreams('restart');Signin with anonymously
Section titled “Signin with anonymously”This method make a signin anonymously
window.Pingstreams('signInAnonymous');Signin with JWT Custom Token
Section titled “Signin with JWT Custom Token”This method make a signin using a JWT Custom Token as described here.
window.Pingstreams('signInWithCustomToken', customJwt);Make a logout
Section titled “Make a logout”This will logout the widget:
window.Pingstreams('logout');Show callout
Section titled “Show callout”This will show the widget callout if it is not open:
window.Pingstreams('showCallout');Show or hide the PreChatForm
Section titled “Show or hide the PreChatForm”This parameter configures the PreChatForm visibility:
window.Pingstreams('setPreChatForm', true|false);Set custom PreChatForm Json
Section titled “Set custom PreChatForm Json”This method allow you to customize preChatFormJson property, and change preChatForm structure if preChatForm is still active (ensure preChatForm value is set to true, otherwise use window.Pingstreams(‘setPreChatForm’, true) method before call setPreChatFormJson ). This method accept an Array (see docs for more detail about customize it):
window.Pingstreams('setPreChatFormJson', customFormArray);Get custom PreChatForm Json
Section titled “Get custom PreChatForm Json”This method allow you to get current preChatForm Json array used in the preChatForm component when is active (check preChatForm value is set to true):
window.Pingstreams('getPreChatFormJson');Set new value to Widget parameter
Section titled “Set new value to Widget parameter”You can change a value to the Pingstreams Widget parameter. Pass an object in the form of key/value, where key represent the name of the property you want to modify, and value is the new value you want to set:
window.Pingstreams('setParameter', {key: string, value: string});Set new value to Widget attribute parameter
Section titled “Set new value to Widget attribute parameter”You can change a value to the Pingstreams Widget attribute parameter. Pass an object in the form of key/value, where key represent the name of the property you want to modify, and value is the new value you want to set:
window.Pingstreams('setAttributeParameter', {key: string, value: string});Start a new conversation
Section titled “Start a new conversation”You can programmatically start a new conversation:
window.Pingstreams('startConversation');Open a conversation from a specific ID
Section titled “Open a conversation from a specific ID”You can programmatically open an already existing conversation by id in the form of 'support-group-'+<project_id>+'-'+uuid
window.Pingstreams('openConversationById', conversation_id);Clear site data
Section titled “Clear site data”You can programmatically clear saved session data:
window.Pingstreams('clearStorage');