---
description: Leopard has a tight integration with LiveChat.inc
---

# Live Chat

## Screenshots

<div align="left"><img src="https://4062709520-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La71Iy76rotlqbCOWoQ%2F-LaHWcguxoqjZuP9BjWk%2F-LaHc-gLN9BgJsuyfJjH%2Flivechat-screenshot.jpg?alt=media&#x26;token=3ee2678b-b7ee-4bb9-ae35-66bc80f60a65" alt=""></div>

## Setup and Configuration

### LiveChat Account Setup

You will need to have an account at LiveChat.inc

{% embed url="https://www.livechatinc.com/" %}

### LiveChat Key for Leopard

You will then need to configure Leopard with your LiveChat key that points at your account. This key can be found on `/settings/chat-link` . It's a numerical number.&#x20;

<div align="left"><img src="https://4062709520-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La71Iy76rotlqbCOWoQ%2F-MGOvtus5lYR1nrAvFHs%2F-MGOwA7TDfbWwDV4T-_d%2Flivechat.png?alt=media&#x26;token=c72d903d-54a0-4bcd-ab5d-05258aaa3e50" alt="Key found in page link url"></div>

{% hint style="info" %}
Leopard's [build variables](../installation/build-variables) control access to the integration with LiveChat.&#x20;
{% endhint %}

```javascript
const config = {
  ...,
  /**
   * https://www.livechat.com/ integration - live chat handover
   */
  liveChatInc: {
    agentAssist: {
      /**
       * Server URL for creating agent assist canned responses -
       * https://github.com/jolzee/agent-assist-livechat-server-leopard
       */
      serverUrl: ""
    },
    key: "" // livechat.com license key
  },
  ...
};

module.exports = config;

```

### LiveChat API Key

You will also need to acquire the LiveChat Personal Access Token (PAT) so that an Integration in Teneo can be created. This integration will be responsible for checking to see if there is a live agent currently available before initiating a handover.

Login to LiveChat's web interface and head over to the LiveChat Deverloper Console - [https://developers.livechat.com/console/tools/personal-access-tokens](https://developers.livechat.com/console/tools/personal-access-tokens) . Create a new token.&#x20;

You can control you authorization scopes. At the very least you will need **agents\_read.**

<div align="left"><img src="https://4062709520-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La71Iy76rotlqbCOWoQ%2F-MGOzwB82lJZOaMiIYow%2F-MGP0Du55WuLJGhWj4qF%2Fcheck-agent-availability.png?alt=media&#x26;token=b4651ee2-deb9-4677-b865-4ce5e5c89678" alt=""></div>

## Studio

### Integration

When a user explicitly asks to speak to a human or some other handover rule has been triggered you will want to first check to see if there's a live agent available. This can be done using a custom integration in Teneo Studio.  **You will need to update the entity id and pat in the integration script.**

<div align="left"><img src="https://4062709520-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La71Iy76rotlqbCOWoQ%2F-LaHWcguxoqjZuP9BjWk%2F-LaHZpR_21GOgjBnyt5o%2Flivechat-integration.jpg?alt=media&#x26;token=48a79aa7-90a4-48b2-a509-fa9cd59ee4c8" alt="Integration in Studio"></div>

```groovy
def addr = "https://api.livechatinc.com/agents"
def authString = "entity-id:personal-access-token".getBytes().encodeBase64().toString()

def result = new groovy.json.JsonSlurper().parseText(addr.toURL().getText(connectTimeout: 2000, readTimeout: 3000,requestProperties: ['X-API-VERSION': '2','Authorization':'Basic ' + authString]));
def availableAgents = result.findAll { it.status == "accepting chats" }

agentAvailable = false
if (availableAgents.size() > 0) {
    agentAvailable = true
}
```

### Trigger Handover

The handover in Teneo is triggered by adding an output parameter to any output node.

```groovy
liveChat = ${dialogTranscript}
```

### Building the Dialog Transcript

Create a global variable called `dialogTranscript`&#x20;

#### Pre-processing Script

```groovy
if (_.userInputText) {
	dialogTranscript += "Visitor: " + _.userInputText + "\n";
}
```

#### Post-processing Script

```groovy
if (_.getOutputText()) {
	dialogTranscript += "Bot: " + _.getOutputText() + "\n";
}
```

### Example Flow

<div align="left"><img src="https://4062709520-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La71Iy76rotlqbCOWoQ%2F-LaHWcguxoqjZuP9BjWk%2F-LaHbHoVACgJ4386JnOW%2Flive-chat-handover.jpg?alt=media&#x26;token=63f5dccc-85fa-4d1b-9c28-e2b5701fabb8" alt="Live Chat Handover in Studio"></div>

### Setting User Info

If you want the LiveChat human agent to know who they're about to talk to then you can send some additional JSON back in an output parameter.

```groovy
userInfo =   {
  "name": "John Doe",
  "email": "john.doe@example.com",
  "sessionFields": {
	 "custom_property": "BasketValue=10usd",
	 "any_key_is_ok": "sample custom field"
  }
}
```

<div align="left"><img src="https://4062709520-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La71Iy76rotlqbCOWoQ%2F-MMvI55Fl3ee-gh6M7no%2F-MMvJ7Msr8y9vTczAckF%2Fjohndoe.png?alt=media&#x26;token=ff419e7a-0cc1-42d6-a1f2-0abf0892e65a" alt=""></div>

&#x20;
