Skip to main content

Functions

showParleyMessenger()

Version: 1.0.1

Opens the chat window while skipping the inviteNotification window.
To show the inviteNotification window, please use showInviteNotification(title, body)


<button onclick="parleySettings.showParleyMessenger()">show chat</button>

hideParleyMessenger()

Version: 1.0.1

Hides the chat, just like what would happen if a customer clicked on the minimize button inside the chat.


<button onclick="parleySettings.hideParleyMessenger()">hide chat</button>

destroyParleyMessenger()

Version: 1.0.1

Destroys the html element in which the chat lives. This means the chat is completely removed from the page.


<button onclick="parleySettings.destroyParleyMessenger()">destroy chat</button>

initParleyMessenger()

Version: 1.0.1

Initializes the chat and creating the html elements. This can be called after destroyParleyMessenger() to recreate the chat.


<button onclick="parleySettings.initParleyMessenger()">init chat</button>

showInviteNotification(title, body)

Version: 1.0.1

Shows the invite notification with a title and body.
When the parameters are left empty, the function will use parleySettings.runOptions.interfaceTexts.inviteNotification

NameType
Titlestring (HTML)
Bodystring (HTML)
Show after click

<button onclick="parleySettings.showInviteNotification(
'<b>Test title</b>',
'If you have any questions, feel free to ask them!'
)">
show invite notification
</button>
Show delayed

<script>
setTimeout(function () {
window.parleySettings.showInviteNotification();
}, 10000);
</script>
Show delayed during business hours

<script>
setTimeout(function () {
var date = new Date();
var businessHours = window.parleySettings.weekdays[date.getDay()];
if (businessHours[1] <= date.getHours() && businessHours[2] >= date.getHours()) {
window.parleySettings.showInviteNotification();
}
}, 10000);
</script>

sendInitialMessage(text, type)

Deprecated

The sendInitialMessage function is deprecated, please use the sendMessage function instead

Version: 1.0.1
Added optional param type in Version: 1.2.16

Sends a message to the chat (from the customer). Just like how a customer would send his own message by typing it in the textarea. The chat will open automatically after this method, so it is not needed to call showParleyMessenger() when calling this method.

The optional param type tells the library what type of message to send. There are 2 types: userMessage = 1 (default), userSystemMessage = 4. Any other type will result in an error.

NameType
Textstring (plain text)
Typeint (1,4)

<button onclick="parleySettings.sendInitialMessage('Hello, i need help.')">send initial message</button>

<button onclick="parleySettings.sendInitialMessage('User would like to speak to an Agent', 4)">send initial message
</button>

sendMessage(message, type)

Version: 1.2.16

Sends a message to the chat (from the customer). Just like how a customer would send his own message by typing it in the textarea. The chat will open automatically after this method, so it is not needed to call showParleyMessenger() when calling this method.

The optional param type tells the library what type of message to send. There are 2 types: userMessage = 1 (default), userSystemMessage = 4. Any other type will result in an error.

NameType
Messagestring (plain text)
Typeint (1,4)

<button onclick="parleySettings.sendMessage('Hello, i need help.')">send message</button>

<button onclick="parleySettings.sendMessage('User would like to speak to an Agent', 4)">send message</button>

unregisterServiceWorker(skipCookieCheck)

Version: 1.0.1

Unregister service worker used by FCM (Firebase Cloud Messaging).

NameTypedefaultDescription
SkipCookieCheckbooleantrue* true unregisters service worker even when parley cookies (are now in local storage) are still on the pc,
* false unregisters service worker only when parley cookies are deleted.

<button onclick="window.parleySettings.fcmConfig.unregisterServiceWorker()">Unregister Service Worker</button>

initializeFCM()

Version: 1.0.1

Registers the device to be used with FCM (and Push system). This enables the device to receive notifications when the chat tab is not active/closed in the browser.


<button onclick="window.parleySettings.fcmConfig.initializeFCM()">Unregister Service Worker</button>

deleteAllDataFromStorage()

Version: 1.0.1

First minimizes the chat window. Then removes all data from the local storage and stops any polling and/or service worker(s).

<button onclick="window.parleySettings.deleteAllDataFromStorage()">
Delete all from storage
</button>

registerNewDevice(authHeader, callback, errorCallback, force = false, fetchMessages = true)

Version: 1.0.4

Registers the client as a new device to the Parley API and refresh the chat. This is done automatically when someone starts a chat.

You can use this in the following scenario:

  • Client starts chat as anonymous (aka: no autHeader present)
  • Client logs into his website account
    Website calls registerNewDevice(authHeader) to turn the anonymous chat into a non-anonymous chat (because the chat now has a authHeader)
  • Client sees his previous anonymous messages merged with his old non-anonymous conversation, without reloading the page.

As of version 1.2.10, you can provide a force parameter that will (if true) forcefully re-register the device. Forcefully means that it will not care if the device has already been registered.

This new addition can be used to update the user's userAdditionalInformation whenever you want.

As of version 1.3.0, you can provide a fetchMessages parameter that will (if true) fetch the messages once the new device is successfully registered.

This behavior was already default, but you now have the possibility to disable it if you only want to use this function for updating the userAdditionalInformation.

nametypedescription
authHeaderstringAn authHeader as you could also set in the settings.
callbackfunctionWe call this function when a new device is succesfully registered
errorCallbackfunctionCalled when we couldn't register a new device
forcebooleanForcefully re-register the device
fetchMessagesbooleanFetch messages from the server after successfully registering the new device
<button onclick="window.parleySettings.registerNewDevice("lkh45kjhsdf8u045nldkgn435")">Log in</button>