Methods
This guide shares the list of methods, you can call to change the messenger behaviour without interacting with the messenger UI.
It opens the possibilities to control messenger window using your own custom buttons.
minimize
Minimize the messenger window.
kayako.minimize()
maximize
Maximize the messenger window.
kayako.maximize()
hide
Hide the messenger completely by setting it's display to none
.
kayako.hide()
show
Show messenger by toggling the display back to block
. This method will show the messenger in it's last state.
kayako.show()
visibility
Get the messenger visibility state. Returns one of the following values all in lower case.
- minimized - When messenger is minimized but not hidden.
- maximized - When messenger is maximized and visible to the user.
- hidden - When messenger is hidden.
// Creating toggle function
if (kayako.visibility() === 'minimized') {
kayako.maximize()
} else {
kayako.minimize()
}
identify
If you just want to identify user, set 'name' and 'email', and pass 'signature' as an empty string.
If you also want to make all existing user conversations available in Messenger, you will need to send a valid 'signature'. This lets you share conversations across devices.
You can generate signature on server side and hash it using SHA256 HMAC encryption to return all conversations linked to the identified user. Timestamp should be unix timestamp in seconds.
PHP
<?php
$timestamp = time();
$signature = hash_hmac('sha256', ($name . $email . $token . $timestamp), $token);
?>
Node.js
const crypto = require('crypto')
const data = `${name}${email}${token}${timestamp}`
const signature = crypto.createHmac('sha256', token).update(data).digest('hex')
Send this signature to client every time you want to let Messenger know that a user is authenticated. Place an identify() call to Messenger after your users have logged in to identify them in Kayako.
/**
* name: String
* email: String
* signature: String
* timestamp: Number (Unix timestamp in seconds)
*/
kayako.ready(function () {
kayako.identify(name, email, signature, timestamp)
})
forget
Place a forget() call before logging out your users to forget their identity. This function receives a callback which is executed right after forget request is completed.
kayako.ready(function () {
kayako.forget(function() {
// Apply your logout mechanism here
})
})