Genesys Cloud Chat

This document describes how to integrate the chat service of Genesys Cloud (formerly PureCloud) with a Virtual Assistant (VA) using Teneo Web Chat (TWC) and Teneo Engine. With this integration, TWC serves as a frontend to both Teneo Engine and the chat service of Genesys Cloud so the user can start a conversation with the Virtual Assistant and get connected to a Live Chat agent later if needed.

genesys

Prerequisites

These instructions assume your Teneo solution is published and that you know the Engine URL.

Setup instructions

Frontend

  1. Deploy TWC as per these instructions.
  2. Add (the content of) the extensions file twcPureCloudExtension.js somewhere between the file "teneo-web-chat.js" (the TWC core code) and the TWC initialization code, i.e., after the link to "teneo-web-chat.js" and before the code block where window.TeneoWebChat.initialize(...) is called (both are explicitly mentioned in the TWC deployment instructions):
    <script src="/path/to/teneo-web-chat.js"></script>
    ...
    <script src="/path/to/twcPureCloudExtension.js"></script>
    ...
    <script>
    // The TWC initialization code
    ...
    window.TeneoWebChat.initialize(...);
    ...
    </script>

You can optionally assign the following values BEFORE calling window.TeneoWebChat.initialize():

window.TeneoWebChatExtensions.injected.defaults = {
    // The name of the avatar (string):
    title: 'My Virtual Assistant',

    // The URL of the default image of the avatar (string):
    titleIconUrl: './path/to/avatar/image.png',

    // The number of milliseconds in the Virtual Assistant mode
    // after which the TWC frontend will close (number):
    feSessionTimeoutMillis: 540000
};

Here, the string-valued properties title and titleIconUrl are, respectively, the name and the URL of the avatar image to appear in TWC, both in the Virtual Assistant mode and in the Live Chat mode, in case the agent's name or avatar image are not provided by the Genesys Cloud chat or by Teneo Engine. The value of the titleIconUrl property can be any valid URL, including a data URL. If any of these properties is omitted, the default TWC title and/or avatar image will be used.

The number-valued property feSessionTimeoutMillis is the frontend timeout; this is the number of milliseconds that pass without any requests being submitted to the Teneo Engine, after which the backend session is assumed to be about to expire. The frontend will close automatically after this time lapse provided it is in the Virtual Assistant mode. If it is in the Live Chat mode, this property has no effect. If this property is omitted, is null, NaN or is less than 0, the frontend timeout mechanism is deactivated. If this property is used, it is strongly recommended to set its value to 30-60 seconds less than the Teneo Engine timeout (which can be project-dependent, but is usually 10 minutes).

Teneo Engine

Initialization

Do the following global configurations:

  1. Upload reqproxy.jsp into the / folder of your solution (not into /views where JSPs are uploaded by default).
  2. Add the content of PureCloudChatAux.groovy to the 'Solution loaded' script. When adding it, configure your customer data in the variables clientId, clientSecret, organizationId, deploymentId, queueId, customerActionId, queueStatisticsUrl. You will find these variables right after the definition of the class PureCloudChatAux in PureCloudChatAux.groovy:
...
String clientId = 'your client ID';
String clientSecret = 'your client secret';
String organizationId = 'your organization ID';
String deploymentId = 'your deployment ID';
String queueId = 'your queue ID';
String customerActionId = 'your customer statistics action ID';
String queueStatisticsUrl = 'https://api.mypurecloud.ie/api/v2/integrations/actions/' +customerActionId + '/execute';

PureCloudChatAux.init(clientId, clientSecret, organizationId, deploymentId, queueId, queueStatisticsUrl);

Checking agent availability

The Live Chat agent availability can be checked in Teneo Engine with the PureCloudChatAux.getQueueStats() method. It returns an object containing the following properties:

  • agentsLoggedIn, the number of Live Chat agents currently logged in;
  • queueLength, the length of the queue;
  • agentsOnQueue, the number of the agents on the queue;
  • agentsOnQueueIdle, the number of the idle agents on the queue.

You can use any of these properties in your checking logic to decide whether the user should be redirected to the Live Chat.

An example:

def chatQueueState = null;
try {
    String accessToken = PureCloudChatAux.getAccessToken();
    chatQueueState = PureCloudChatAux.getQueueStats(accessToken);
} catch (err) {
    println 'Failure checking chat availability: '+err;
    // Handle the error here:
    // ...
}

if (chatQueueState && chatQueueState.agentsLoggedIn > 0) {
    // Live Chat is available.
    // Your code to handle it:
    // ...
} else {
    // Live chat is NOT available.
    // Your code to handle it:
    // ...
}

Transferring the user to the Live Chat

In order to transfer the user to the Live Chat, your Teneo Engine should simultaneously return to the TWC the output parameters described below.

Obligatory output parameters
  • liveChatAuth: The value of this output parameter is a stringified JSON object containing all the data needed by the chat service to start the Live Chat. This value is obtained with the following code (the value in question is assigned to the global session variable sLiveChatAuth for illustration purposes only and you have to make sure this value makes it to the output parameter):
def liveChatAuth = null;
try {
    String accessToken = PureCloudChatAux.getAccessToken();
    liveChatAuth = PureCloudChatAux.getChat(accessToken);
} catch (err) {
    println 'Failure creating chat start object: '+err;
    // Handle the error here:
    // ...
}

sLiveChatAuth = liveChatAuth ? new groovy.json.JsonBuilder(liveChatAuth).toString() : '';

The fact the output parameter liveChatAuth is returned is the indication to the TWC to start the handover process.

  • liveChatMsgConnectionFailure: the message to be displayed in the frontend if the chat connection failed. It is supposed to be returned together with liveChatAuth. If it is not, a default message in English ("Failure starting live chat") will be used.
Optional output parameters
  • liveChatMsgConnecting: the message to be displayed when the frontend tries to establish connection with the Live Chat service as a result of receiving the data in liveChatAuth.
  • liveChatAgentName: the name of the Live Chat agent to display if the Live Chat service has not returned a name.
  • liveChatAgentIcon: the URL of the avatar image of the Live Chat agent to display if the Live Chat service has not returned any image. It may also be a data URL.
  • liveChatMsgClosingChat: the message to be displayed in the frontend when the Live Chat agent closes the conversation with the user.
  • liveChatFrontendCloseDelayMillisUponAgentLeave: the number of milliseconds to wait before closing the frontend as a result of the Live Chat agent closing the conversation with the user. If this value is not defined, it will be 5000 milliseconds. During this time, the message of liveChatMsgClosingChat (if it has been returned) will be displayed.
  • askCloseLiveChat: the confirmation dialog to appear if the user clicks the close button of the frontend in the Live Chat mode. The goal of this dialog is to prevent the user from accidentally closing the Live Chat. Regarding its format, see the description of the add_message method in the TWC API. A possible value can be as follows:
{
    "type": "modal",
    "data": {
        "title": "Confirm",
        "text": "Do you really want to close the chat?",
        "button_items": [
            {
                "style": "secondary",
                "title": "Yes, close it!",
                "postback": "close",
                "operation": "closeFrontend"
            },{
                "style": "secondary",
                "title": "Cancel",
                "postback": "cancel",
                "operation": "cancel"
            }
        ]
    }
}

Additional convenience functionalities

There are several other output parameters that can be used for some convenience functionalities.

  • reset: If this output parameter is not empty, it causes the frontend to close, terminating the Virtual Assistant backend session.
  • minimize: If this output parameter is not empty, it causes the frontend to minimize without terminating the Virtual Assistant backend session.
  • closingFeedback: the confirmation/feedback dialog to appear if the user clicks the close button of the frontend in the Virtual Assistant mode. Regarding its format, see the description of the add_message method in the TWC API. A possible value can be as follows:
    {
    "type": "modal",
    "data": {
        "title": "FEEDBACK",
        "text": "Have you received the answer you were looking for?",
        "button_items": [
            {
                "style": "secondary",
                "title": "Yes",
                "postback": "yes",
                "parameters": {
                    "command": "userFeedback",
                    "feedbackRating": "positive",
                    "abortActiveFlows": "true"
                }
            },{
                "style": "secondary",
                "title": "No",
                "postback": "no",
                "parameters": {
                    "command": "userFeedback",
                    "feedbackRating": "negative",
                    "abortActiveFlows": "true"
                }
            },{
                "style": "secondary",
                "title": "Close anyway",
                "postback": "close",
                "operation": "closeFrontend"
            },{
                "style": "secondary",
                "title": "Cancel",
                "postback": "cancel",
                "operation": "cancel"
            }
        ]
    }
    }

Was this page helpful?