@livechat/customer-sdk 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2402 -0
- package/dist/customer-sdk.cjs.js +3791 -0
- package/dist/customer-sdk.cjs.native.js +3790 -0
- package/dist/customer-sdk.esm.js +3764 -0
- package/dist/customer-sdk.js +5229 -0
- package/dist/customer-sdk.min.js +1 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,2402 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
**LiveChat Customer SDK** is a set of tools that helps you build a custom chat widget. Under the hood, it makes use of the [LiveChat Customer Chat API](https://developers.livechat.com/docs/messaging/customer-chat-api/). Customer SDK lets you communicate with LiveChat services directly from the browser environment using JavaScript without the need to develop your backend.
|
|
4
|
+
|
|
5
|
+
## Is it for me?
|
|
6
|
+
|
|
7
|
+
If you need to customize the LiveChat Widget, using LiveChat Customer SDK is
|
|
8
|
+
one of the options to do this. If you need a fully customizable solution and you feel
|
|
9
|
+
brave, dive into LiveChat Customer SDK. We provide [methods](#methods) and
|
|
10
|
+
[events](#events) for deep integration with the LiveChat environment.
|
|
11
|
+
|
|
12
|
+
Keep in mind that interacting with this API requires **some development skills**.
|
|
13
|
+
|
|
14
|
+
Customer SDK allows you to create frontend apps, so if you're looking for server-side solutions, you should explore the [LiveChat Customer Chat API](https://developers.livechat.com/docs/messaging/customer-chat-api/) instead.
|
|
15
|
+
If you want to dive deeper into the LiveChat Platform, you might find the [Platform Overview](https://developers.livechat.com/docs/getting-started/) article handy.
|
|
16
|
+
|
|
17
|
+
## About LiveChat Customer SDK
|
|
18
|
+
|
|
19
|
+
We provide an asynchronous API. Most methods return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). You can subscribe to the emitted events with the `on` and `off` methods.
|
|
20
|
+
Not familiar with promises? Read <a href="https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Global_Objects/Promise">this article</a> to learn more.
|
|
21
|
+
|
|
22
|
+
We authenticate your sessions with the use of
|
|
23
|
+
[customer-auth package](https://www.npmjs.com/package/@livechat/customer-auth)
|
|
24
|
+
and expose the created `auth` object to the returned SDK instance. In general,
|
|
25
|
+
you don't have to worry about it or use the exposed object. If you need to
|
|
26
|
+
get the authentication token, you can get it through the SDK like this:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
customerSDK.auth.getToken().then(token => {
|
|
30
|
+
console.log(token)
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Questions
|
|
35
|
+
|
|
36
|
+
If you have any questions, you can start a chat with our [24/7 Support](https://direct.lc.chat/1520/125).
|
|
37
|
+
|
|
38
|
+
# How to start
|
|
39
|
+
|
|
40
|
+
This tutorial is here to help you get started with LiveChat Customer SDK.
|
|
41
|
+
|
|
42
|
+
## Create an application
|
|
43
|
+
|
|
44
|
+
First, you need to create an application in
|
|
45
|
+
[Developer Console](https://developers.livechat.com/console) (select the _Web app (frontend,
|
|
46
|
+
e.g. JavaScript)_ type). Then, you will have to give it the access to the `customers:own` scope and the correct URI to the `Redirect URI whitelist`.
|
|
47
|
+
|
|
48
|
+
## Install Customer SDK
|
|
49
|
+
|
|
50
|
+
You can use the LiveChat Customer SDK in two different ways:
|
|
51
|
+
|
|
52
|
+
### Using npm
|
|
53
|
+
|
|
54
|
+
`npm install --save @livechat/customer-sdk`
|
|
55
|
+
|
|
56
|
+
Import the SDK in your code:
|
|
57
|
+
|
|
58
|
+
`import * as CustomerSDK from '@livechat/customer-sdk'`
|
|
59
|
+
|
|
60
|
+
Or use the node-style `require` call:
|
|
61
|
+
|
|
62
|
+
`const CustomerSDK = require('@livechat/customer-sdk')`
|
|
63
|
+
|
|
64
|
+
### Using a script tag - UMD module hosted on unpkg's CDN
|
|
65
|
+
|
|
66
|
+
`<script src="https://unpkg.com/@livechat/customer-sdk@3.1.0"></script>`
|
|
67
|
+
|
|
68
|
+
If you just want to look around and play with the SDK, check out our
|
|
69
|
+
[sample chat widget implementation](https://codesandbox.io/s/rm3prxw88n).
|
|
70
|
+
|
|
71
|
+
For the time being you need to register your application in the <a href="https://developers.livechat.com/console" target="_blank">Developers Console</a>
|
|
72
|
+
as a "Web app (frontend, eg. JavaScript)" type. Then, you have to pass the configured `redirectUri` to the `init`, along with the regular required properties (`licenseId` and `clientId`).
|
|
73
|
+
|
|
74
|
+
## Using the API
|
|
75
|
+
|
|
76
|
+
To use the API you will first need to create an instance using the `init` function.
|
|
77
|
+
You will need to provide your licenseId and clientId when creating a Customer SDK instance.
|
|
78
|
+
|
|
79
|
+
Other optional configuration parameters are also available:
|
|
80
|
+
|
|
81
|
+
| parameters | type | default | description |
|
|
82
|
+
| -------------------- | ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
83
|
+
| licenseId | number | | Your license number, you receive this value when creating a new livechat account. |
|
|
84
|
+
| clientId | string | | Your client id, you receive this value when you register your application in the LiveChat Developer Console. |
|
|
85
|
+
| autoConnect | boolean | true | Optional; should the library try to reconnect on it's own. |
|
|
86
|
+
| groupId | number | 0 | Optional; the id of the group you wish to connect to. |
|
|
87
|
+
| region | 'dal' \| 'fra' | 'dal' | Optional; the server region your license is at. |
|
|
88
|
+
| redirectUri | string | | Optional; should only be used inside ReactNative, this is the URI which your webview is redirected to after authorization. |
|
|
89
|
+
| customerDataProvider | () => CustomerData | | Optional; should only be used if you need to send customer data during login. In general, [`updateCustomer()`](#updateCustomer) should be prefered for sending customer data. |
|
|
90
|
+
| identityProvider | () => CustomerAuth | | Optional; allows for providing own instance of the CustomerAuth object which contains the customer access token handlers. See [Custom Identity Provider](https://developers.livechat.com/docs/extending-chat-widget/custom-identity-provider) for more information. |
|
|
91
|
+
|
|
92
|
+
CustomerData:
|
|
93
|
+
|
|
94
|
+
| parameters | type | description |
|
|
95
|
+
| ------------- | ------ | ---------------- |
|
|
96
|
+
| name | string | Optional |
|
|
97
|
+
| email | string | Optional |
|
|
98
|
+
| sessionFields | object | Key: value pairs |
|
|
99
|
+
|
|
100
|
+
CustomerAuth:
|
|
101
|
+
|
|
102
|
+
| parameters | type | description |
|
|
103
|
+
| ------------- | ---------------------- | -------------------------------------------------------------------------------------- |
|
|
104
|
+
| getFreshToken | () => Promise<Token> | Should resolve with freshly requested customer access token. |
|
|
105
|
+
| getToken | () => Promise<Token> | Should resolve with currently stored customer access token. |
|
|
106
|
+
| hasToken | () => Promise<boolean> | Should resolve with a boolean value representing if a token has been already acquired. |
|
|
107
|
+
| invalidate | () => Promise<void> | Should handle token invalidation and/or clearing the locally cached value. |
|
|
108
|
+
|
|
109
|
+
The `init` function will return a Customer SDK instance:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
const customerSDK = CustomerSDK.init({
|
|
113
|
+
licenseId: LICENSE_ID,
|
|
114
|
+
clientId: CLIENT_ID,
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
With `customerSDK`, you can attach [events](#events):
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
customerSDK.on('new_event', newEvent => {
|
|
122
|
+
console.log(newEvent)
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Or execute [methods](#methods):
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
const chatId = 'OU0V0P0OWT'
|
|
130
|
+
customerSDK
|
|
131
|
+
.sendEvent({
|
|
132
|
+
chatId,
|
|
133
|
+
event: {
|
|
134
|
+
type: 'message',
|
|
135
|
+
text: 'Hi!',
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
.then(response => {
|
|
139
|
+
console.log(response)
|
|
140
|
+
})
|
|
141
|
+
.catch(error => {
|
|
142
|
+
console.log(error)
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Using the API in React Native
|
|
147
|
+
|
|
148
|
+
If you want to use LiveChat Customer SDK in React Native, keep in mind that we
|
|
149
|
+
use cookies to authenticate your sessions, so we need some sort of browser
|
|
150
|
+
environment for that. We've prepared a special wrapper for you to use in React
|
|
151
|
+
Native. It opens a WebView component to get an authentication token. All you
|
|
152
|
+
have to do is import it from our authentication package (no need to install
|
|
153
|
+
it - the SDK depends on it, so you already have it) and mount it in your React
|
|
154
|
+
Native application:
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { AuthWebView } from '@livechat/customer-auth'
|
|
158
|
+
import { init } from '@livechat/customer-sdk'
|
|
159
|
+
|
|
160
|
+
export default class App extends React.Component {
|
|
161
|
+
customerSDK = null
|
|
162
|
+
|
|
163
|
+
componentDidMount() {
|
|
164
|
+
this.customerSDK = init({
|
|
165
|
+
licenseId: LICENSE_ID,
|
|
166
|
+
clientId: CLIENT_ID,
|
|
167
|
+
redirectUri: REDIRECT_URI,
|
|
168
|
+
})
|
|
169
|
+
// you can start using customerSDK from now
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
render() {
|
|
173
|
+
return (
|
|
174
|
+
<View>
|
|
175
|
+
<AuthWebView />
|
|
176
|
+
</View>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
If you are looking for something simpler, you can use a <a href="https://github.com/livechat/react-native-livechat" target="_blank">LiveChat for React Native</a> library. This is a React Native component to easily add the LiveChat Widget with basic functionality to your application.
|
|
183
|
+
|
|
184
|
+
# Key Concepts
|
|
185
|
+
|
|
186
|
+
The LiveChat system includes four basic types of entities - users, chats, threads, and events.
|
|
187
|
+
|
|
188
|
+
- Chats consist of threads and threads consist of events.
|
|
189
|
+
- Threads are parts of chats.
|
|
190
|
+
- Users can add events to chats, which then are automatically added to threads.
|
|
191
|
+
- Users can participate in many chats at the same time.
|
|
192
|
+
|
|
193
|
+
Threads are a vital part of the LiveChat architecture.
|
|
194
|
+
Grouping events in threads allows us to provide the continuous chat experience (i.e. the Customer always has the option to continue the conversation) while still maintaining smaller, logical chunks of events (e.g. for reporting and caching purposes).
|
|
195
|
+
Handling operations such as loading archival events from the chat history can be challenging, but you won't have to worry about managing threads most of the time.
|
|
196
|
+
Customer SDK provides wrappers for common tasks and most methods expect to receive chat IDs.
|
|
197
|
+
You will only get notified about thread metadata if you explicitly ask for it.
|
|
198
|
+
|
|
199
|
+
You can read more about key concepts of the LiveChat messaging in the [Messaging Overview](https://developers.livechat.com/docs/messaging/#key-concepts).
|
|
200
|
+
|
|
201
|
+
## User
|
|
202
|
+
|
|
203
|
+
### Agent
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
{
|
|
207
|
+
id: 'ed9d4095-45d6-428d-5093-f8ec7f1f81b9',
|
|
208
|
+
type: 'agent',
|
|
209
|
+
name: 'Jane Doe',
|
|
210
|
+
jobTitle: 'Agent',
|
|
211
|
+
avatar: 'https://cdn.livechat.com/cloud/?uri=https://livechat.s3.amazonaws.com/default/avatars/a7.png',
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Customer
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
{
|
|
219
|
+
id: 'ed9d0195-45d6-428d-5093-f8ec7f1471b9',
|
|
220
|
+
type: 'customer',
|
|
221
|
+
name: 'Jon Doe',
|
|
222
|
+
avatar: 'https://cdn.livechat.com/cloud/?uri=https://livechat.s3.amazonaws.com/default/avatars/a6.png',
|
|
223
|
+
fields: {
|
|
224
|
+
custom_property: 'BasketValue=10usd',
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Chat
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
{
|
|
233
|
+
id: 'OU0V0P0OWT',
|
|
234
|
+
users: [{
|
|
235
|
+
id: 'ed9d4095-45d6-428d-5093-f8ec7f1f81b9',
|
|
236
|
+
// ... more user properties
|
|
237
|
+
}],
|
|
238
|
+
lastSeenTimestamps: {
|
|
239
|
+
'ed9d4095-45d6-428d-5093-f8ec7f1f81b9': 1503062591000, // might be null
|
|
240
|
+
},
|
|
241
|
+
threads: ['OU0V0U3IMN'],
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Event
|
|
246
|
+
|
|
247
|
+
```js
|
|
248
|
+
{
|
|
249
|
+
type: 'message',
|
|
250
|
+
text: 'hi!',
|
|
251
|
+
author: 'ed9d4095-45d6-428d-5093-f8ec7f1f81b9', // assigned by server
|
|
252
|
+
id: 'OU0V0U3IMN_1', // assigned by server
|
|
253
|
+
timestamp: 1503062591000, // assigned by server
|
|
254
|
+
customId: '814.3316641404942', // optional
|
|
255
|
+
thread: 'OU0V4R0OXP',
|
|
256
|
+
properties: {},
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Threads
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
{
|
|
264
|
+
id: 'OU0V0U3IMN',
|
|
265
|
+
active: true,
|
|
266
|
+
order: 3,
|
|
267
|
+
users: ['ed9d4095-45d6-428d-5093-f8ec7f1f81b9'],
|
|
268
|
+
lastSeenTimestamps: {
|
|
269
|
+
'ed9d4095-45d6-428d-5093-f8ec7f1f81b9': 1503062591000, // might be null
|
|
270
|
+
},
|
|
271
|
+
events: [ /* events */ ],
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
# Methods
|
|
276
|
+
|
|
277
|
+
## acceptGreeting
|
|
278
|
+
|
|
279
|
+
You can use this method to inform that a Customer has seen a greeting. Based on that, the Reports section displays only the greetings seen by Customers instead of all the sent greetings. If a Customer started a chat from a greeting but you didn't execute `acceptGreeting` method, the greeting counts as seen in Reports anyway.
|
|
280
|
+
|
|
281
|
+
As arguments to this method you should use `uniqueId` & `greetingId` received in the [`incoming_greeting`](#incoming_greeting) or [`connected`](#connected) event.
|
|
282
|
+
|
|
283
|
+
```js
|
|
284
|
+
customerSDK
|
|
285
|
+
.acceptGreeting({
|
|
286
|
+
greetingId: 7,
|
|
287
|
+
uniqueId: 'Q10X0W041P',
|
|
288
|
+
})
|
|
289
|
+
.then(response => {
|
|
290
|
+
console.log(response)
|
|
291
|
+
})
|
|
292
|
+
.catch(error => {
|
|
293
|
+
console.log(error)
|
|
294
|
+
})
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Parameters:
|
|
298
|
+
|
|
299
|
+
| parameters | type |
|
|
300
|
+
| ---------- | ------ |
|
|
301
|
+
| greetingId | number |
|
|
302
|
+
| uniqueId | string |
|
|
303
|
+
|
|
304
|
+
### Errors
|
|
305
|
+
|
|
306
|
+
- `GREETING_NOT_FOUND` - a given `uniqueId` couldn't be found on the server
|
|
307
|
+
|
|
308
|
+
## cancelGreeting
|
|
309
|
+
|
|
310
|
+
Cancels a greeting (an invitation to the chat). For example, Customers could cancel greetings by clicking close icon on the displayed greeting.
|
|
311
|
+
|
|
312
|
+
```js
|
|
313
|
+
customerSDK
|
|
314
|
+
.cancelGreeting({
|
|
315
|
+
uniqueId: 'Q10X0W041P',
|
|
316
|
+
})
|
|
317
|
+
.then(response => {
|
|
318
|
+
console.log(response)
|
|
319
|
+
})
|
|
320
|
+
.catch(error => {
|
|
321
|
+
console.log(error)
|
|
322
|
+
})
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Parameters:
|
|
326
|
+
|
|
327
|
+
| parameters | type |
|
|
328
|
+
| ---------- | ------ |
|
|
329
|
+
| uniqueId | string |
|
|
330
|
+
|
|
331
|
+
### Errors
|
|
332
|
+
|
|
333
|
+
- `GREETING_NOT_FOUND` - given `uniqueId` could not be found on the server
|
|
334
|
+
|
|
335
|
+
## cancelRate
|
|
336
|
+
|
|
337
|
+
Cancels rate-related thread properties.
|
|
338
|
+
|
|
339
|
+
```js
|
|
340
|
+
customerSDK
|
|
341
|
+
.cancelRate({
|
|
342
|
+
chatId: 'ON0X0R0L67',
|
|
343
|
+
properties: ['score', 'comment'],
|
|
344
|
+
})
|
|
345
|
+
.then(response => {
|
|
346
|
+
console.log(response)
|
|
347
|
+
})
|
|
348
|
+
.catch(() => {
|
|
349
|
+
console.log(error)
|
|
350
|
+
})
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Errors
|
|
354
|
+
|
|
355
|
+
- `MISSING_CHAT_THREAD` - the targeted chat is empty and has no threads.
|
|
356
|
+
|
|
357
|
+
## connect
|
|
358
|
+
|
|
359
|
+
Starts the connection process to our servers. It is needed when:
|
|
360
|
+
|
|
361
|
+
- the argument `autoConnect: false` has been passed to the `init` method
|
|
362
|
+
- you get disconnected for a reason that suspends reconnection attempts (e.g. [`inactivity_timeout`](#inactivity_timeout))
|
|
363
|
+
|
|
364
|
+
## deactivateChat
|
|
365
|
+
|
|
366
|
+
```js
|
|
367
|
+
customerSDK
|
|
368
|
+
.deactivateChat({ id: 'ON0X0R0L67' })
|
|
369
|
+
.then(response => {
|
|
370
|
+
console.log(response)
|
|
371
|
+
})
|
|
372
|
+
.catch(error => {
|
|
373
|
+
console.log(error)
|
|
374
|
+
})
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Parameters:
|
|
378
|
+
|
|
379
|
+
| parameters | type | description |
|
|
380
|
+
| ---------- | ------ | ----------------------------------------- |
|
|
381
|
+
| id | string | Chat ID in which thread should get closed |
|
|
382
|
+
|
|
383
|
+
Returned value:
|
|
384
|
+
|
|
385
|
+
| properties | type |
|
|
386
|
+
| ---------- | ------- |
|
|
387
|
+
| success | boolean |
|
|
388
|
+
|
|
389
|
+
## deleteChatProperties
|
|
390
|
+
|
|
391
|
+
Deletes given chat properties.
|
|
392
|
+
|
|
393
|
+
```js
|
|
394
|
+
customerSDK
|
|
395
|
+
.deleteChatProperties({
|
|
396
|
+
id: 'ON0X0R0L67',
|
|
397
|
+
properties: {
|
|
398
|
+
property_namespace: ['sample'],
|
|
399
|
+
},
|
|
400
|
+
})
|
|
401
|
+
.then(response => {
|
|
402
|
+
console.log(response)
|
|
403
|
+
})
|
|
404
|
+
.catch(error => {
|
|
405
|
+
console.log(error)
|
|
406
|
+
})
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Parameters:
|
|
410
|
+
|
|
411
|
+
| parameters | type | description |
|
|
412
|
+
| ---------- | ------ | --------------------------------------------------- |
|
|
413
|
+
| id | string | ID of the chat whose properties you want to delete. |
|
|
414
|
+
| properties | object | Chat properties to delete |
|
|
415
|
+
|
|
416
|
+
Returned value:
|
|
417
|
+
|
|
418
|
+
| properties | type |
|
|
419
|
+
| ---------- | ------- |
|
|
420
|
+
| success | boolean |
|
|
421
|
+
|
|
422
|
+
## deleteEventProperties
|
|
423
|
+
|
|
424
|
+
Deletes given event properties.
|
|
425
|
+
|
|
426
|
+
```js
|
|
427
|
+
customerSDK
|
|
428
|
+
.deleteEventProperties({
|
|
429
|
+
chatId: 'ON0X0R0L67',
|
|
430
|
+
threadId: 'OS0C0W0Z1B',
|
|
431
|
+
eventId: 'Q50W0A0P0Y',
|
|
432
|
+
properties: {
|
|
433
|
+
property_namespace: ['sample'],
|
|
434
|
+
},
|
|
435
|
+
})
|
|
436
|
+
.then(response => {
|
|
437
|
+
console.log(response)
|
|
438
|
+
})
|
|
439
|
+
.catch(error => {
|
|
440
|
+
console.log(error)
|
|
441
|
+
})
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
Parameters:
|
|
445
|
+
|
|
446
|
+
| parameters | type | description |
|
|
447
|
+
| ---------- | ------ | ----------------------------------------------------- |
|
|
448
|
+
| chatId | string | ID of the chat whose properties you want to delete. |
|
|
449
|
+
| threadId | string | ID of the thread whose properties you want to delete. |
|
|
450
|
+
| eventId | string | ID of the event whose properties you want to delete. |
|
|
451
|
+
| properties | object | Properties to delete |
|
|
452
|
+
|
|
453
|
+
Returned value:
|
|
454
|
+
|
|
455
|
+
| properties | type |
|
|
456
|
+
| ---------- | ------- |
|
|
457
|
+
| success | boolean |
|
|
458
|
+
|
|
459
|
+
## deleteThreadProperties
|
|
460
|
+
|
|
461
|
+
Deletes given chat thread properties.
|
|
462
|
+
|
|
463
|
+
```js
|
|
464
|
+
customerSDK
|
|
465
|
+
.deleteThreadProperties({
|
|
466
|
+
chatId: 'ON0X0R0L67',
|
|
467
|
+
threadId: 'OS0C0W0Z1B',
|
|
468
|
+
properties: {
|
|
469
|
+
property_namespace: ['sample'],
|
|
470
|
+
},
|
|
471
|
+
})
|
|
472
|
+
.then(response => {
|
|
473
|
+
console.log(response)
|
|
474
|
+
})
|
|
475
|
+
.catch(error => {
|
|
476
|
+
console.log(error)
|
|
477
|
+
})
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
Parameters:
|
|
481
|
+
|
|
482
|
+
| parameters | type | description |
|
|
483
|
+
| ---------- | ------ | ----------------------------------------------------- |
|
|
484
|
+
| chatId | string | ID of the chat whose properties you want to delete. |
|
|
485
|
+
| threadId | string | ID of the thread whose properties you want to delete. |
|
|
486
|
+
| properties | object | Properties to delete |
|
|
487
|
+
|
|
488
|
+
Returned value:
|
|
489
|
+
|
|
490
|
+
| properties | type |
|
|
491
|
+
| ---------- | ------- |
|
|
492
|
+
| success | boolean |
|
|
493
|
+
|
|
494
|
+
## destroy
|
|
495
|
+
|
|
496
|
+
Clears any stored resources, removes all listeners, and disconnects from the network.
|
|
497
|
+
After using this method, you won't be able to use the destroyed Customer SDK instance.
|
|
498
|
+
|
|
499
|
+
```js
|
|
500
|
+
customerSDK.destroy()
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
## disconnect
|
|
504
|
+
|
|
505
|
+
Disconnects from the server.
|
|
506
|
+
|
|
507
|
+
```js
|
|
508
|
+
customerSDK.disconnect()
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## getChat
|
|
512
|
+
|
|
513
|
+
Returns the chat data about the requested chat ID together with a single thread's data. If the method is called with the `threadId` parameter, then this particular thread is being returned. If no `threadId` is given, the latest thread is automatically returned.
|
|
514
|
+
|
|
515
|
+
```js
|
|
516
|
+
customerSDK
|
|
517
|
+
.getChat({
|
|
518
|
+
chatId: 'ON0X0R0L67',
|
|
519
|
+
})
|
|
520
|
+
.then(chat => {
|
|
521
|
+
const { id, access, users, properties, thread } = chat
|
|
522
|
+
console.log({ id, access, users, properties, thread })
|
|
523
|
+
})
|
|
524
|
+
.catch(error => {
|
|
525
|
+
console.log(error)
|
|
526
|
+
})
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
Parameters:
|
|
530
|
+
|
|
531
|
+
| parameters | type | description |
|
|
532
|
+
| ---------- | ------ | ----------- |
|
|
533
|
+
| chatId | string | |
|
|
534
|
+
| threadId | string | optional |
|
|
535
|
+
|
|
536
|
+
Returned value:
|
|
537
|
+
|
|
538
|
+
| properties | type | description |
|
|
539
|
+
| ---------- | -------- | ------------------------------------ |
|
|
540
|
+
| id | string | Chat ID |
|
|
541
|
+
| access | object | Chat initial access |
|
|
542
|
+
| users | object[] | Users objects referenced in the chat |
|
|
543
|
+
| properties | object | Chat properties |
|
|
544
|
+
| thread | object | |
|
|
545
|
+
|
|
546
|
+
## getChatHistory
|
|
547
|
+
|
|
548
|
+
Helps loading in historical thread events.
|
|
549
|
+
|
|
550
|
+
First, call `getChatHistory` to access the `history` object of a particular chat.
|
|
551
|
+
The returned `history` object has only one method, `next`, which gives you a `Promise` with a `{ done, value }` object.
|
|
552
|
+
|
|
553
|
+
- `done` - indicates if there is anything more to load
|
|
554
|
+
- `value` - an object with an array of threads, each containing an array of its events
|
|
555
|
+
|
|
556
|
+
Then, you can keep calling `history.next()` multiple times to load previous historical events. They're going to be grouped into threads and might require merging with already loaded events.
|
|
557
|
+
This is useful for implementing an infinite scroll or otherwise showing your Customer's archival chats.
|
|
558
|
+
Keep in mind, though, that you generally shouldn't call `next` while the history is loading - we queue those requests, so the previous one must resolve before we proceed with the next one.
|
|
559
|
+
|
|
560
|
+
The structure such as our `history` object is called an **async iterator**.
|
|
561
|
+
|
|
562
|
+
```js
|
|
563
|
+
let wholeChatHistoryLoaded = false
|
|
564
|
+
|
|
565
|
+
const history = customerSDK.getChatHistory({ chatId: 'OU0V0P0OWT' })
|
|
566
|
+
|
|
567
|
+
history.next().then(result => {
|
|
568
|
+
if (result.done) {
|
|
569
|
+
wholeChatHistoryLoaded = true
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const { threads } = result.value
|
|
573
|
+
|
|
574
|
+
const events = threads
|
|
575
|
+
.map(thread => thread.events || [])
|
|
576
|
+
.reduce((acc, current) => acc.concat(current), [])
|
|
577
|
+
|
|
578
|
+
console.log(events)
|
|
579
|
+
})
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
Parameters:
|
|
583
|
+
|
|
584
|
+
| parameters | type | description |
|
|
585
|
+
| ---------- | ------ | --------------------------------------- |
|
|
586
|
+
| chatId | string | Chat ID of the requested history object |
|
|
587
|
+
|
|
588
|
+
## getCustomer
|
|
589
|
+
|
|
590
|
+
Returns the info about the Customer requesting it.
|
|
591
|
+
|
|
592
|
+
```js
|
|
593
|
+
customerSDK
|
|
594
|
+
.getCustomer()
|
|
595
|
+
.then(customer => {
|
|
596
|
+
console.log(customer)
|
|
597
|
+
})
|
|
598
|
+
.catch(error => {
|
|
599
|
+
console.log(error)
|
|
600
|
+
})
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
Returned value:
|
|
604
|
+
|
|
605
|
+
| properties | type | description |
|
|
606
|
+
| --------------------------------- | ---------- | -------------------- |
|
|
607
|
+
| type | 'customer' | |
|
|
608
|
+
| id | string | |
|
|
609
|
+
| name | string | Returned only if set |
|
|
610
|
+
| email | string | Returned only if set |
|
|
611
|
+
| avatar | string | Returned only if set |
|
|
612
|
+
| sessionFields | object | |
|
|
613
|
+
| statistics | object | |
|
|
614
|
+
| statistics.chatsCount | number | |
|
|
615
|
+
| statistics.threadsCount | number | |
|
|
616
|
+
| statistics.visitsCount | number | |
|
|
617
|
+
| statistics.pageViewsCount | number | |
|
|
618
|
+
| statistics.greetingsShownCount | number | |
|
|
619
|
+
| statistics.greetingsAcceptedCount | number | |
|
|
620
|
+
|
|
621
|
+
## getForm
|
|
622
|
+
|
|
623
|
+
Allows you to fetch a form template for a given group and form type.
|
|
624
|
+
|
|
625
|
+
```js
|
|
626
|
+
customerSDK
|
|
627
|
+
.getForm({
|
|
628
|
+
groupId: 0,
|
|
629
|
+
type: 'prechat',
|
|
630
|
+
})
|
|
631
|
+
.then(response => {
|
|
632
|
+
if (response.enabled) {
|
|
633
|
+
// prechat form is enabled for this group in the configurator
|
|
634
|
+
console.log(response.form)
|
|
635
|
+
}
|
|
636
|
+
})
|
|
637
|
+
.catch(error => {
|
|
638
|
+
console.log(error)
|
|
639
|
+
})
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
Parameters:
|
|
643
|
+
|
|
644
|
+
| parameters | type |
|
|
645
|
+
| ---------- | --------------------------------- |
|
|
646
|
+
| groupId | number |
|
|
647
|
+
| type | 'prechat', 'postchat' or 'ticket' |
|
|
648
|
+
|
|
649
|
+
Returned value:
|
|
650
|
+
|
|
651
|
+
| properties | type | description |
|
|
652
|
+
| ----------- | -------- | ------------------------------------------- |
|
|
653
|
+
| enabled | boolean | |
|
|
654
|
+
| form | object | Available only when a given form is enabled |
|
|
655
|
+
| form.id | string | |
|
|
656
|
+
| form.fields | object[] | |
|
|
657
|
+
|
|
658
|
+
## getPredictedAgent
|
|
659
|
+
|
|
660
|
+
```js
|
|
661
|
+
customerSDK
|
|
662
|
+
.getPredictedAgent({
|
|
663
|
+
groupId: 0,
|
|
664
|
+
})
|
|
665
|
+
.then(agent => {
|
|
666
|
+
console.log(agent)
|
|
667
|
+
})
|
|
668
|
+
.catch(error => {
|
|
669
|
+
console.log(error)
|
|
670
|
+
})
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
Parameters:
|
|
674
|
+
|
|
675
|
+
| parameters | type | description |
|
|
676
|
+
| ---------- | ------ | ----------- |
|
|
677
|
+
| groupId | number | Optional |
|
|
678
|
+
|
|
679
|
+
Returned value:
|
|
680
|
+
|
|
681
|
+
| properties | type | description |
|
|
682
|
+
| -------------- | ------- | ------------------------------------------------------------- |
|
|
683
|
+
| agent | object | |
|
|
684
|
+
| agent.id | string | |
|
|
685
|
+
| agent.name | string | |
|
|
686
|
+
| agent.jobTitle | string | |
|
|
687
|
+
| agent.type | 'agent' | |
|
|
688
|
+
| agent.isBot | boolean | |
|
|
689
|
+
| queue | boolean | True when the current group has reached concurrent chat limit |
|
|
690
|
+
|
|
691
|
+
### Errors
|
|
692
|
+
|
|
693
|
+
- `GROUP_OFFLINE` - the requested group is offline, and it was not possible to return a predicted Agent for it.
|
|
694
|
+
- `GROUP_UNAVAILABLE` - thrown when manual routing is enabled for the group and a predicted Agent is requested for it. If you call `startChat` or `resumeChat` accordingly, you'll end up in the queue.
|
|
695
|
+
|
|
696
|
+
## getUrlInfo
|
|
697
|
+
|
|
698
|
+
It returns the info on a given URL.
|
|
699
|
+
|
|
700
|
+
```js
|
|
701
|
+
customerSDK
|
|
702
|
+
.getUrlInfo({ url: 'https://www.livechat.com' })
|
|
703
|
+
.then(urlDetails => {
|
|
704
|
+
if (urlDetails.title) {
|
|
705
|
+
console.log(`The title of requested URL is: ${urlDetails.title}`)
|
|
706
|
+
}
|
|
707
|
+
if (urlDetails.description) {
|
|
708
|
+
console.log(
|
|
709
|
+
`The description of requested URL is: ${urlDetails.description}`,
|
|
710
|
+
)
|
|
711
|
+
}
|
|
712
|
+
if (urlDetails.imageUrl) {
|
|
713
|
+
console.log(
|
|
714
|
+
`The preview image of requested URL is available under: ${urlDetails.imageUrl}`,
|
|
715
|
+
)
|
|
716
|
+
if (urlDetails.imageWidth && urlDetails.imageHeight) {
|
|
717
|
+
console.log(`Its width is: ${urlDetails.imageWidth}`)
|
|
718
|
+
console.log(`Its height is: ${urlDetails.imageHeight}`)
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
})
|
|
722
|
+
.catch(error => {
|
|
723
|
+
console.log(error)
|
|
724
|
+
})
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
Parameters:
|
|
728
|
+
|
|
729
|
+
| parameters | type |
|
|
730
|
+
| ---------- | ------ |
|
|
731
|
+
| url | string |
|
|
732
|
+
|
|
733
|
+
Returned value:
|
|
734
|
+
|
|
735
|
+
| properties | type | description |
|
|
736
|
+
| ----------- | ------ | ----------- |
|
|
737
|
+
| url | string | |
|
|
738
|
+
| title | string | Optional |
|
|
739
|
+
| description | string | Optional |
|
|
740
|
+
| imageUrl | string | Optional |
|
|
741
|
+
| imageWidth | number | Optional |
|
|
742
|
+
| imageHeight | number | Optional |
|
|
743
|
+
|
|
744
|
+
## off
|
|
745
|
+
|
|
746
|
+
Unsubscribes from emitted events, which are described [here](#events).
|
|
747
|
+
|
|
748
|
+
## on
|
|
749
|
+
|
|
750
|
+
Subscribes to emitted events, which are described [here](#events).
|
|
751
|
+
|
|
752
|
+
## once
|
|
753
|
+
|
|
754
|
+
Subscribes to emitted events, which are described [here](#events). Unsubscribes immediately after the callback gets called.
|
|
755
|
+
|
|
756
|
+
## listChats
|
|
757
|
+
|
|
758
|
+
It returns summaries of the chats a Customer participated in.
|
|
759
|
+
|
|
760
|
+
```js
|
|
761
|
+
customerSDK
|
|
762
|
+
.listChats({
|
|
763
|
+
pageId: 'MTU5MTEwMTUxNDM5NTk5OTpkZXNj',
|
|
764
|
+
limit: 10,
|
|
765
|
+
})
|
|
766
|
+
.then(({ chatsSummary, totalChats }) => {
|
|
767
|
+
console.log(chatsSummary)
|
|
768
|
+
console.log(totalChats)
|
|
769
|
+
})
|
|
770
|
+
.catch(error => {
|
|
771
|
+
console.log(error)
|
|
772
|
+
})
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
Parameters:
|
|
776
|
+
|
|
777
|
+
| parameters | type | description |
|
|
778
|
+
| ---------- | ------ | ------------------------------------------------------------------------------- |
|
|
779
|
+
| pageId | string | Optional; the cursor returned from the previous `listChats` calls |
|
|
780
|
+
| limit | number | Optional; the limit of returned results. Default is set to 10 and maximum is 25 |
|
|
781
|
+
|
|
782
|
+
Returned value:
|
|
783
|
+
|
|
784
|
+
| properties | type | description |
|
|
785
|
+
| --------------------------------- | -------- | ---------------------------------------------- |
|
|
786
|
+
| chatsSummary | object[] | |
|
|
787
|
+
| chatsSummary[].id | string | Chat ID |
|
|
788
|
+
| chatsSummary[].active | boolean | |
|
|
789
|
+
| chatsSummary[].users | object[] | Users objects referenced in the chat |
|
|
790
|
+
| chatsSummary[].lastEvent | object | Event |
|
|
791
|
+
| chatsSummary[].lastEventsPerType | object | Map of event types to event objects |
|
|
792
|
+
| chatsSummary[].lastSeenTimestamps | object | Map of user IDs to optional lastSeenTimestamps |
|
|
793
|
+
| chatsSummary[].lastThread | string | Thread ID |
|
|
794
|
+
| totalChats | number | |
|
|
795
|
+
|
|
796
|
+
## listGroupStatuses
|
|
797
|
+
|
|
798
|
+
Returns availability statuses of the requested groups.
|
|
799
|
+
|
|
800
|
+
```js
|
|
801
|
+
customerSDK
|
|
802
|
+
.listGroupStatuses({
|
|
803
|
+
groupIds: [3, 10],
|
|
804
|
+
})
|
|
805
|
+
.then(statusMap => {
|
|
806
|
+
console.log(`Status of the group 3: ${statusMap[3]}`)
|
|
807
|
+
console.log(`Status of the group 10: ${statusMap[10]}`)
|
|
808
|
+
})
|
|
809
|
+
.catch(error => {
|
|
810
|
+
console.log(error)
|
|
811
|
+
})
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
Parameters:
|
|
815
|
+
|
|
816
|
+
| parameters | type | description |
|
|
817
|
+
| ---------- | -------- | ---------------------------------------------------------- |
|
|
818
|
+
| groupsIds | number[] | Optional; if omitted, statuses of all groups are returned. |
|
|
819
|
+
|
|
820
|
+
Returned value:
|
|
821
|
+
|
|
822
|
+
| properties | type | description |
|
|
823
|
+
| ---------- | ------ | --------------------------------------------- |
|
|
824
|
+
| statusMap | object | Map of group numbers to availability statuses |
|
|
825
|
+
|
|
826
|
+
## listThreads
|
|
827
|
+
|
|
828
|
+
Returns a list of thread objects together with the previous and next page ID cursors that can be used to load more threads.
|
|
829
|
+
If you want to load consecutive events, consider using [`getChatHistory`](#getchathistory).
|
|
830
|
+
|
|
831
|
+
```js
|
|
832
|
+
customerSDK
|
|
833
|
+
.listThreads({
|
|
834
|
+
chatId: 'ON0X0R0L67',
|
|
835
|
+
})
|
|
836
|
+
.then(response => {
|
|
837
|
+
console.log(response.threads)
|
|
838
|
+
console.log(response.previousPageId)
|
|
839
|
+
console.log(response.nextPageId)
|
|
840
|
+
})
|
|
841
|
+
.catch(error => {
|
|
842
|
+
console.log(error)
|
|
843
|
+
})
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
Parameters:
|
|
847
|
+
|
|
848
|
+
| parameters | type | description |
|
|
849
|
+
| -------------- | --------------- | ------------------------------------------------------------------- |
|
|
850
|
+
| chatId | string | |
|
|
851
|
+
| pageId | string | Optional, the cursor returned from the previous `listThreads` calls |
|
|
852
|
+
| sortOrder | 'desc' \| 'asc' | Optional, default: 'desc' |
|
|
853
|
+
| limit | number | Optional, default: 3, can't be used together with `minEventsCount` |
|
|
854
|
+
| minEventsCount | number | Optional, can't be used together with `limit` |
|
|
855
|
+
|
|
856
|
+
Returned value:
|
|
857
|
+
|
|
858
|
+
| properties | type | description |
|
|
859
|
+
| ------------------------ | -------- | -------------------------------------------------------------------------- |
|
|
860
|
+
| threads | object[] | |
|
|
861
|
+
| threads[].id | string | Thread ID |
|
|
862
|
+
| threads[].chatId | string | Chat ID |
|
|
863
|
+
| threads[].active | boolean | Active state |
|
|
864
|
+
| threads[].createdAt | string | Thread creation date in RFC 3339 date-time format |
|
|
865
|
+
| threads[].userIds | string[] | User IDs |
|
|
866
|
+
| threads[].events | object[] | Events |
|
|
867
|
+
| threads[].properties | object | Chat properties |
|
|
868
|
+
| threads[].access | object | |
|
|
869
|
+
| threads[].queue | object | Optional |
|
|
870
|
+
| threads[].queue.position | number | Current position in the queue |
|
|
871
|
+
| threads[].queue.waitTime | number | Estimated waiting time for an agent to be assigned to the chat, in seconds |
|
|
872
|
+
| threads[].queue.queuedAt | string | RFC 3339 date-time format |
|
|
873
|
+
| previousPageId | string | |
|
|
874
|
+
| nextPageId | string | |
|
|
875
|
+
|
|
876
|
+
## markEventsAsSeen
|
|
877
|
+
|
|
878
|
+
Marks events as seen by the current Customer up to the given date.
|
|
879
|
+
|
|
880
|
+
```js
|
|
881
|
+
customerSDK
|
|
882
|
+
.markEventsAsSeen({
|
|
883
|
+
chatId: 'ON0X0R0L67',
|
|
884
|
+
seenUpTo: '2017-10-12T15:19:21.010200Z',
|
|
885
|
+
})
|
|
886
|
+
.then(response => {
|
|
887
|
+
console.log(response)
|
|
888
|
+
})
|
|
889
|
+
.catch(error => {
|
|
890
|
+
console.log(error)
|
|
891
|
+
})
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
Parameters:
|
|
895
|
+
|
|
896
|
+
| parameters | type | description |
|
|
897
|
+
| ---------- | ------ | ---------------------------------------------------------------------------------------- |
|
|
898
|
+
| chatId | string | ID of the chat in which you want to mark events as seen. |
|
|
899
|
+
| seenUpTo | string | RFC 3339 date-time format; you should use the event's `createdAt` value as the argument. |
|
|
900
|
+
|
|
901
|
+
Returned value:
|
|
902
|
+
|
|
903
|
+
| properties | type |
|
|
904
|
+
| ---------- | ------- |
|
|
905
|
+
| success | boolean |
|
|
906
|
+
|
|
907
|
+
## rateChat
|
|
908
|
+
|
|
909
|
+
Sends chat rating and a comment for the most recent chat thread.
|
|
910
|
+
|
|
911
|
+
```js
|
|
912
|
+
customerSDK
|
|
913
|
+
.rateChat({
|
|
914
|
+
chatId: 'ON0X0R0L67',
|
|
915
|
+
rating: {
|
|
916
|
+
score: 1,
|
|
917
|
+
comment: 'Agent helped me a lot!',
|
|
918
|
+
},
|
|
919
|
+
})
|
|
920
|
+
.then(() => {
|
|
921
|
+
console.log('Rating has been set')
|
|
922
|
+
})
|
|
923
|
+
.catch(error => {
|
|
924
|
+
console.log(error)
|
|
925
|
+
})
|
|
926
|
+
```
|
|
927
|
+
|
|
928
|
+
Parameters:
|
|
929
|
+
|
|
930
|
+
| parameters | type | description |
|
|
931
|
+
| -------------- | ------ | -------------------------------------------------------- |
|
|
932
|
+
| chatId | | Destination chat ID |
|
|
933
|
+
| rating | | |
|
|
934
|
+
| rating.score | 0 or 1 | Rating value: 0 for a bad rating and 1 for a good rating |
|
|
935
|
+
| rating.comment | string | Optional comment |
|
|
936
|
+
|
|
937
|
+
Returned value:
|
|
938
|
+
|
|
939
|
+
| properties | type |
|
|
940
|
+
| ---------- | ------- |
|
|
941
|
+
| success | boolean |
|
|
942
|
+
|
|
943
|
+
### Errors
|
|
944
|
+
|
|
945
|
+
- `MISSING_CHAT_THREAD` - the targeted chat cannot be rated because it has no threads.
|
|
946
|
+
|
|
947
|
+
## resumeChat
|
|
948
|
+
|
|
949
|
+
Resumes an archived chat.
|
|
950
|
+
|
|
951
|
+
```js
|
|
952
|
+
customerSDK
|
|
953
|
+
.resumeChat({
|
|
954
|
+
chat: {
|
|
955
|
+
id: 'OU0V0P0OWT',
|
|
956
|
+
thread: {
|
|
957
|
+
events: [],
|
|
958
|
+
},
|
|
959
|
+
},
|
|
960
|
+
})
|
|
961
|
+
.then(chat => {
|
|
962
|
+
console.log(chat)
|
|
963
|
+
})
|
|
964
|
+
.catch(error => {
|
|
965
|
+
console.log(error)
|
|
966
|
+
})
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
Parameters:
|
|
970
|
+
|
|
971
|
+
| parameters | type | description |
|
|
972
|
+
| --------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
973
|
+
| data.active | boolean | Optional; defaults to `true` but can be used to create threads that are immediately inactive |
|
|
974
|
+
| data.continuous | boolean | Optional |
|
|
975
|
+
| data.chat.id | string | |
|
|
976
|
+
| data.chat.access | Access | Optional |
|
|
977
|
+
| data.chat.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
978
|
+
| data.chat.thread.events | Event[] | Optional; you can pass initial events which will immediately become part of the created thread. |
|
|
979
|
+
| data.chat.thread.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
980
|
+
|
|
981
|
+
### Errors
|
|
982
|
+
|
|
983
|
+
- `CHAT_ALREADY_ACTIVE` - the chat is already active and you can't activate it again.
|
|
984
|
+
- `GROUPS_OFFLINE` - a group in the targeted chat is offline. It can happen for licenses without continuous chats enabled.
|
|
985
|
+
|
|
986
|
+
## sendEvent
|
|
987
|
+
|
|
988
|
+
Sends a provided object as an event with a specified type.
|
|
989
|
+
|
|
990
|
+
```js
|
|
991
|
+
const event = {
|
|
992
|
+
type: 'message',
|
|
993
|
+
// ... other properties specific for the event's type
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
customerSDK
|
|
997
|
+
.sendEvent({
|
|
998
|
+
chatId: 'ON0X0R0L67',
|
|
999
|
+
event,
|
|
1000
|
+
})
|
|
1001
|
+
.then(event => {
|
|
1002
|
+
console.log(event)
|
|
1003
|
+
})
|
|
1004
|
+
.catch(error => {
|
|
1005
|
+
console.log(error)
|
|
1006
|
+
})
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
Parameters:
|
|
1010
|
+
|
|
1011
|
+
| parameters | type | description |
|
|
1012
|
+
| ------------------ | ------- | ------------------- |
|
|
1013
|
+
| chatId | string | Destination chat ID |
|
|
1014
|
+
| event | | |
|
|
1015
|
+
| event.type | string | Type of the event |
|
|
1016
|
+
| attachToLastThread | boolean | Optional |
|
|
1017
|
+
|
|
1018
|
+
## sendRichMessagePostback
|
|
1019
|
+
|
|
1020
|
+
Sends information to the server about a user's interaction with a rich message button.
|
|
1021
|
+
|
|
1022
|
+
```js
|
|
1023
|
+
customerSDK
|
|
1024
|
+
.sendRichMessagePostback({
|
|
1025
|
+
chatId: 'ON0X0R0L67',
|
|
1026
|
+
threadId: 'OS0C0W0Z1B',
|
|
1027
|
+
eventId: 'OS0C0W0Z1B01',
|
|
1028
|
+
postback: {
|
|
1029
|
+
id: 'OS0C0W0Z1B01002',
|
|
1030
|
+
toggled: true,
|
|
1031
|
+
},
|
|
1032
|
+
})
|
|
1033
|
+
.then(() => {
|
|
1034
|
+
console.log('success')
|
|
1035
|
+
})
|
|
1036
|
+
.catch(error => {
|
|
1037
|
+
console.log(error)
|
|
1038
|
+
})
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
Parameters:
|
|
1042
|
+
|
|
1043
|
+
| parameters | type | default | description |
|
|
1044
|
+
| ---------------- | ------- | ------- | ------------------ |
|
|
1045
|
+
| chatId | string | | postback chat ID |
|
|
1046
|
+
| threadId | string | | postback thread ID |
|
|
1047
|
+
| eventId | string | | postback event ID |
|
|
1048
|
+
| postback | | | |
|
|
1049
|
+
| postback.id | string | | Postback button ID |
|
|
1050
|
+
| postback.toggled | boolean | true | Postback toggled |
|
|
1051
|
+
|
|
1052
|
+
## sendTicketForm
|
|
1053
|
+
|
|
1054
|
+
Can be used to send a filled ticket form.
|
|
1055
|
+
|
|
1056
|
+
```js
|
|
1057
|
+
customerSDK
|
|
1058
|
+
.sendTicketForm({
|
|
1059
|
+
groupId: 10,
|
|
1060
|
+
filledForm: {
|
|
1061
|
+
type: 'filled_form',
|
|
1062
|
+
formId: '',
|
|
1063
|
+
fields: [
|
|
1064
|
+
{
|
|
1065
|
+
type: 'subject',
|
|
1066
|
+
id: '0',
|
|
1067
|
+
label: 'Subject:',
|
|
1068
|
+
answer: 'Order number 123',
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
type: 'email',
|
|
1072
|
+
id: '1',
|
|
1073
|
+
label: 'Your email:',
|
|
1074
|
+
answer: 'john.doe@example.com',
|
|
1075
|
+
},
|
|
1076
|
+
{
|
|
1077
|
+
type: 'checkbox',
|
|
1078
|
+
id: '2',
|
|
1079
|
+
label: 'Question:',
|
|
1080
|
+
answers: [
|
|
1081
|
+
{ id: '0', label: 'First answer' },
|
|
1082
|
+
{ id: '1', label: 'Second answer' },
|
|
1083
|
+
],
|
|
1084
|
+
},
|
|
1085
|
+
{
|
|
1086
|
+
type: 'textarea',
|
|
1087
|
+
id: '3',
|
|
1088
|
+
label: 'Your message:',
|
|
1089
|
+
answer:
|
|
1090
|
+
'Could I get a status update on this order? Have you already shipped it?',
|
|
1091
|
+
},
|
|
1092
|
+
],
|
|
1093
|
+
},
|
|
1094
|
+
})
|
|
1095
|
+
.then(response => {
|
|
1096
|
+
console.log(`Created a ticket with id: ${response.id}`)
|
|
1097
|
+
})
|
|
1098
|
+
.catch(error => {
|
|
1099
|
+
console.log(error)
|
|
1100
|
+
})
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
Parameters:
|
|
1104
|
+
|
|
1105
|
+
| parameters | type | description |
|
|
1106
|
+
| ----------------- | ----------------- | ------------------------------ |
|
|
1107
|
+
| filledForm.type | 'filled_form' | |
|
|
1108
|
+
| filledForm.formId | string | |
|
|
1109
|
+
| filledForm.fields | FilledFormField[] | |
|
|
1110
|
+
| groupId | number | Optional |
|
|
1111
|
+
| timeZone | string | Optional, valid IANA Time Zone |
|
|
1112
|
+
|
|
1113
|
+
Returned value:
|
|
1114
|
+
|
|
1115
|
+
| properties | type | description |
|
|
1116
|
+
| ---------- | ------ | ------------------------ |
|
|
1117
|
+
| id | string | ID of the created ticket |
|
|
1118
|
+
|
|
1119
|
+
## setCustomerSessionFields
|
|
1120
|
+
|
|
1121
|
+
Sends the request to set customer's session fields. They are available for the duration of the session.
|
|
1122
|
+
|
|
1123
|
+
```js
|
|
1124
|
+
customerSDK.setCustomerSessionFields({
|
|
1125
|
+
sessionFields: {
|
|
1126
|
+
foo: 'bar',
|
|
1127
|
+
test: 'qwerty',
|
|
1128
|
+
},
|
|
1129
|
+
})
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
Parameters:
|
|
1133
|
+
|
|
1134
|
+
| parameters | type |
|
|
1135
|
+
| ------------- | ------ |
|
|
1136
|
+
| sessionFields | object |
|
|
1137
|
+
|
|
1138
|
+
## setSneakPeek
|
|
1139
|
+
|
|
1140
|
+
You can use it to update the [sneak peek](https://www.livechat.com/blog/customer-message-sneak-peak/) in the Agent App.
|
|
1141
|
+
It is sent to the server only if the target chat is active. This method doesn't return a promise.
|
|
1142
|
+
|
|
1143
|
+
```js
|
|
1144
|
+
customerSDK.setSneakPeek({
|
|
1145
|
+
chatId: 'ON0X0R0L67',
|
|
1146
|
+
sneakPeekText: 'what is the price for your ',
|
|
1147
|
+
})
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
Parameters:
|
|
1151
|
+
|
|
1152
|
+
| parameters | type | description |
|
|
1153
|
+
| ------------- | ------ | ---------------------------------------- |
|
|
1154
|
+
| chatId | string | Target chat ID |
|
|
1155
|
+
| sneakPeekText | string | Message preview broadcasted to the Agent |
|
|
1156
|
+
|
|
1157
|
+
## startChat
|
|
1158
|
+
|
|
1159
|
+
Starts a new chat. For one Customer, you can only start one chat.
|
|
1160
|
+
In order to activate a previously started chat, use [`resumeChat`](#resumeChat).
|
|
1161
|
+
|
|
1162
|
+
```js
|
|
1163
|
+
customerSDK
|
|
1164
|
+
.startChat({
|
|
1165
|
+
chat: {
|
|
1166
|
+
thread: {
|
|
1167
|
+
events: [],
|
|
1168
|
+
},
|
|
1169
|
+
},
|
|
1170
|
+
})
|
|
1171
|
+
.then(chat => {
|
|
1172
|
+
console.log(chat)
|
|
1173
|
+
})
|
|
1174
|
+
.catch(error => {
|
|
1175
|
+
console.log(error)
|
|
1176
|
+
})
|
|
1177
|
+
```
|
|
1178
|
+
|
|
1179
|
+
Parameters:
|
|
1180
|
+
|
|
1181
|
+
| parameters | type | description |
|
|
1182
|
+
| ---------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
1183
|
+
| active | boolean | Optional, defaults to `true` but can be used to create threads that are immediately inactive |
|
|
1184
|
+
| continuous | boolean | Optional |
|
|
1185
|
+
| chat.access | access | Optional |
|
|
1186
|
+
| chat.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
1187
|
+
| chat.thread.events | event[] | Optional; initial events that will immediately become a part of the created thread. |
|
|
1188
|
+
| chat.thread.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
1189
|
+
|
|
1190
|
+
### Errors
|
|
1191
|
+
|
|
1192
|
+
- `CHAT_LIMIT_REACHED` - the maximum limit of chats per Customer has been reached, and it's not possible to start a new one. You should activate one of the existing chats. The limit is 1.
|
|
1193
|
+
- `GROUPS_OFFLINE` - a group in the target chat is offline. It can happen for licenses, which don't allow Customers to chat during their unavailability.
|
|
1194
|
+
|
|
1195
|
+
## updateChatProperties
|
|
1196
|
+
|
|
1197
|
+
```js
|
|
1198
|
+
const properties = {
|
|
1199
|
+
property_namespace: {
|
|
1200
|
+
sample: 'property',
|
|
1201
|
+
},
|
|
1202
|
+
}
|
|
1203
|
+
customerSDK
|
|
1204
|
+
.updateChatProperties({ id: 'ON0X0R0L67', properties })
|
|
1205
|
+
.then(response => {
|
|
1206
|
+
console.log(response)
|
|
1207
|
+
})
|
|
1208
|
+
.catch(error => {
|
|
1209
|
+
console.log(error)
|
|
1210
|
+
})
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
Parameters:
|
|
1214
|
+
|
|
1215
|
+
| parameters | type | description |
|
|
1216
|
+
| ---------- | ------ | ------------------------------------------------------------------------------------------------------- |
|
|
1217
|
+
| id | string | ID of the chat whose properties you want to update. |
|
|
1218
|
+
| properties | object | [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
1219
|
+
|
|
1220
|
+
## updateCustomer
|
|
1221
|
+
|
|
1222
|
+
Updates the specified Customer properties and fields.
|
|
1223
|
+
|
|
1224
|
+
```js
|
|
1225
|
+
const properties = {
|
|
1226
|
+
name: 'John Doe',
|
|
1227
|
+
email: 'john.doe@example.com',
|
|
1228
|
+
sessionFields: {
|
|
1229
|
+
custom_property: 'BasketValue=10usd',
|
|
1230
|
+
any_key_is_ok: 'sample custom field',
|
|
1231
|
+
},
|
|
1232
|
+
}
|
|
1233
|
+
customerSDK.updateCustomer(properties)
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
Parameters:
|
|
1237
|
+
|
|
1238
|
+
| parameters | type | description |
|
|
1239
|
+
| ------------------------ | ------ | ------------------------------------------ |
|
|
1240
|
+
| properties | | |
|
|
1241
|
+
| properties.name | string | Optional |
|
|
1242
|
+
| properties.email | string | Optional |
|
|
1243
|
+
| properties.sessionFields | object | Optional; custom fields with string values |
|
|
1244
|
+
|
|
1245
|
+
### Errors
|
|
1246
|
+
|
|
1247
|
+
- `CUSTOMER_SESSION_FIELDS_LIMIT_REACHED` - total amount of session fields would have been exceeded after requested update
|
|
1248
|
+
|
|
1249
|
+
## updateCustomerPage
|
|
1250
|
+
|
|
1251
|
+
Updates information about the Customer page using the provided page object.
|
|
1252
|
+
|
|
1253
|
+
```js
|
|
1254
|
+
const page = {
|
|
1255
|
+
url: 'https://developers.livechat.com/',
|
|
1256
|
+
title: 'LiveChat for Developers',
|
|
1257
|
+
}
|
|
1258
|
+
customerSDK.updateCustomerPage(page)
|
|
1259
|
+
```
|
|
1260
|
+
|
|
1261
|
+
Parameters:
|
|
1262
|
+
|
|
1263
|
+
| parameters | type |
|
|
1264
|
+
| ---------- | ------ |
|
|
1265
|
+
| page | |
|
|
1266
|
+
| page.url | string |
|
|
1267
|
+
| page.title | string |
|
|
1268
|
+
|
|
1269
|
+
## updateEventProperties
|
|
1270
|
+
|
|
1271
|
+
Updates given properties of an event.
|
|
1272
|
+
|
|
1273
|
+
```js
|
|
1274
|
+
const properties = {
|
|
1275
|
+
property_namespace: {
|
|
1276
|
+
sample: 'property',
|
|
1277
|
+
},
|
|
1278
|
+
}
|
|
1279
|
+
customerSDK
|
|
1280
|
+
.updateEventProperties({
|
|
1281
|
+
chatId: 'ON0X0R0L67',
|
|
1282
|
+
threadId: 'OS0C0W0Z1B',
|
|
1283
|
+
eventId: 'Q50W0A0P0Y',
|
|
1284
|
+
properties,
|
|
1285
|
+
})
|
|
1286
|
+
.then(response => {
|
|
1287
|
+
console.log(response)
|
|
1288
|
+
})
|
|
1289
|
+
.catch(error => {
|
|
1290
|
+
console.log(error)
|
|
1291
|
+
})
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
Parameters:
|
|
1295
|
+
|
|
1296
|
+
| parameters | type | description |
|
|
1297
|
+
| ---------- | ------ | ------------------------------------------------------------------------------------------------------- |
|
|
1298
|
+
| chatId | string | ID of the chat whose properties you want to update. |
|
|
1299
|
+
| threadId | string | ID of the thread whose properties you want to update. |
|
|
1300
|
+
| eventId | string | ID of the event whose properties you want to update. |
|
|
1301
|
+
| properties | object | [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
1302
|
+
|
|
1303
|
+
## updateThreadProperties
|
|
1304
|
+
|
|
1305
|
+
```js
|
|
1306
|
+
const properties = {
|
|
1307
|
+
property_namespace: {
|
|
1308
|
+
sample: 'property',
|
|
1309
|
+
},
|
|
1310
|
+
}
|
|
1311
|
+
customerSDK
|
|
1312
|
+
.updateThreadProperties({
|
|
1313
|
+
chatId: 'ON0X0R0L67',
|
|
1314
|
+
threadId: 'OS0C0W0Z1B',
|
|
1315
|
+
properties,
|
|
1316
|
+
})
|
|
1317
|
+
.then(response => {
|
|
1318
|
+
console.log(response)
|
|
1319
|
+
})
|
|
1320
|
+
.catch(error => {
|
|
1321
|
+
console.log(error)
|
|
1322
|
+
})
|
|
1323
|
+
```
|
|
1324
|
+
|
|
1325
|
+
Parameters:
|
|
1326
|
+
|
|
1327
|
+
| parameters | type | description |
|
|
1328
|
+
| ---------- | ------ | -------------------------------------------------------------------------------------------------------- |
|
|
1329
|
+
| chatId | string | ID of the chat whose properties you want to update. |
|
|
1330
|
+
| threadId | string | ID of the thread whose properties you want to update. |
|
|
1331
|
+
| properties | object | [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties). |
|
|
1332
|
+
|
|
1333
|
+
## uploadFile
|
|
1334
|
+
|
|
1335
|
+
Returns both a `promise` and a `cancel`. You can use `cancel` to abort a file upload.
|
|
1336
|
+
It also lets you pass the `onProgress` callback function. Keep in mind that the maximum accepted file size is 10 MB.
|
|
1337
|
+
|
|
1338
|
+
It returns a URL that expires after 24 hours unless the URL is used in [`sendEvent`](#sendevent)
|
|
1339
|
+
|
|
1340
|
+
```js
|
|
1341
|
+
const { promise, cancel } = customerSDK.uploadFile({
|
|
1342
|
+
file,
|
|
1343
|
+
onProgress: progress => console.log(`upload progress: ${progress}`),
|
|
1344
|
+
})
|
|
1345
|
+
|
|
1346
|
+
document.getElementById('cancel-upload').onclick = () => {
|
|
1347
|
+
cancel()
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
promise
|
|
1351
|
+
.then(response => {
|
|
1352
|
+
console.log(response.url)
|
|
1353
|
+
})
|
|
1354
|
+
.catch(error => {
|
|
1355
|
+
console.log(error)
|
|
1356
|
+
})
|
|
1357
|
+
```
|
|
1358
|
+
|
|
1359
|
+
Parameters:
|
|
1360
|
+
|
|
1361
|
+
| parameters | type | description |
|
|
1362
|
+
| ---------- | -------- | ------------------------- |
|
|
1363
|
+
| file | blob | |
|
|
1364
|
+
| onProgress | function | Receives a progress value |
|
|
1365
|
+
|
|
1366
|
+
onProgress parameters:
|
|
1367
|
+
|
|
1368
|
+
| parameters | type | min | max |
|
|
1369
|
+
| ---------- | ------ | --- | --- |
|
|
1370
|
+
| progress | number | 0 | 1 |
|
|
1371
|
+
|
|
1372
|
+
Returned value:
|
|
1373
|
+
|
|
1374
|
+
| properties | type |
|
|
1375
|
+
| ---------- | ------ |
|
|
1376
|
+
| url | string |
|
|
1377
|
+
|
|
1378
|
+
In React Native, instead of passing a blob you need to pass an object of
|
|
1379
|
+
[such a shape](https://github.com/facebook/react-native/blob/56fef9b6225ffc1ba87f784660eebe842866c57d/Libraries/Network/FormData.js#L34-L38):
|
|
1380
|
+
|
|
1381
|
+
```js
|
|
1382
|
+
const file = {
|
|
1383
|
+
uri: uriFromCameraRoll,
|
|
1384
|
+
type: 'image/jpeg', // optional
|
|
1385
|
+
name: 'photo.jpg', // optional
|
|
1386
|
+
}
|
|
1387
|
+
```
|
|
1388
|
+
|
|
1389
|
+
# Events
|
|
1390
|
+
|
|
1391
|
+
You can listen for emitted events by subscribing to them using the [on](#on) method with your custom callback.
|
|
1392
|
+
For example, your function can be executed every time a message is received.
|
|
1393
|
+
|
|
1394
|
+
## Availability updated
|
|
1395
|
+
|
|
1396
|
+
Informs about a changed availability status.
|
|
1397
|
+
|
|
1398
|
+
```js
|
|
1399
|
+
customerSDK.on('availability_updated', ({ availability }) => {
|
|
1400
|
+
console.log('availability_updated', availability)
|
|
1401
|
+
})
|
|
1402
|
+
```
|
|
1403
|
+
|
|
1404
|
+
Payload:
|
|
1405
|
+
|
|
1406
|
+
| properties | type | description |
|
|
1407
|
+
| ------------ | ------ | --------------------- |
|
|
1408
|
+
| availability | string | 'online' or 'offline' |
|
|
1409
|
+
|
|
1410
|
+
## Chat deactivated
|
|
1411
|
+
|
|
1412
|
+
Informs that thread has been closed.
|
|
1413
|
+
|
|
1414
|
+
```js
|
|
1415
|
+
customerSDK.on('chat_deactivated', payload => {
|
|
1416
|
+
const { chatId } = payload
|
|
1417
|
+
console.log('chat_deactivated', { chatId })
|
|
1418
|
+
})
|
|
1419
|
+
```
|
|
1420
|
+
|
|
1421
|
+
Payload:
|
|
1422
|
+
|
|
1423
|
+
| properties | type | description |
|
|
1424
|
+
| ---------- | ------ | ----------- |
|
|
1425
|
+
| chatId | string | Chat ID |
|
|
1426
|
+
|
|
1427
|
+
## Chat properties deleted
|
|
1428
|
+
|
|
1429
|
+
Informs about deleted chat properties.
|
|
1430
|
+
|
|
1431
|
+
```js
|
|
1432
|
+
customerSDK.on('chat_properties_deleted', payload => {
|
|
1433
|
+
const { chatId, properties } = payload
|
|
1434
|
+
console.log('chat_properties_deleted', { chatId, properties })
|
|
1435
|
+
})
|
|
1436
|
+
```
|
|
1437
|
+
|
|
1438
|
+
Payload:
|
|
1439
|
+
|
|
1440
|
+
| properties | type | description |
|
|
1441
|
+
| ---------- | ------ | --------------- |
|
|
1442
|
+
| chatId | string | Chat ID |
|
|
1443
|
+
| properties | object | Chat properties |
|
|
1444
|
+
|
|
1445
|
+
## Chat properties updated
|
|
1446
|
+
|
|
1447
|
+
Informs about updated chat properties.
|
|
1448
|
+
|
|
1449
|
+
```js
|
|
1450
|
+
customerSDK.on('chat_properties_updated', payload => {
|
|
1451
|
+
const { chatId, properties } = payload
|
|
1452
|
+
console.log('chat_properties_updated', { chatId, properties })
|
|
1453
|
+
})
|
|
1454
|
+
```
|
|
1455
|
+
|
|
1456
|
+
Payload:
|
|
1457
|
+
|
|
1458
|
+
| properties | type | description |
|
|
1459
|
+
| ---------- | ------ | --------------- |
|
|
1460
|
+
| chatId | string | Chat ID |
|
|
1461
|
+
| properties | object | Chat properties |
|
|
1462
|
+
|
|
1463
|
+
## Chat transferred
|
|
1464
|
+
|
|
1465
|
+
Informs that a chat was transferred to a different group or an Agent.
|
|
1466
|
+
|
|
1467
|
+
```js
|
|
1468
|
+
customerSDK.on('chat_transferred', payload => {
|
|
1469
|
+
const { chatId, threadId, transferredTo } = payload
|
|
1470
|
+
console.log('chat_transferred', {
|
|
1471
|
+
chatId,
|
|
1472
|
+
threadId,
|
|
1473
|
+
transferredTo,
|
|
1474
|
+
})
|
|
1475
|
+
})
|
|
1476
|
+
```
|
|
1477
|
+
|
|
1478
|
+
Payload:
|
|
1479
|
+
|
|
1480
|
+
| properties | type | description |
|
|
1481
|
+
| ---------------------- | -------- | -------------------------------------------------------------------------- |
|
|
1482
|
+
| chatId | string | |
|
|
1483
|
+
| threadId | string | |
|
|
1484
|
+
| reason | string | |
|
|
1485
|
+
| requesterId | string | returned only if `reason` is equal to `'manual'` |
|
|
1486
|
+
| transferredTo | | |
|
|
1487
|
+
| transferredTo.agentIds | string[] | optional |
|
|
1488
|
+
| transferredTo.groupIds | number[] | optional |
|
|
1489
|
+
| queue | | optional |
|
|
1490
|
+
| queue.position | number | Current place in the queue |
|
|
1491
|
+
| queue.waitTime | number | Estimated waiting time for an agent to be assigned to the chat, in seconds |
|
|
1492
|
+
| queue.queuedAt | string | RFC 3339 date-time format |
|
|
1493
|
+
|
|
1494
|
+
## Connected
|
|
1495
|
+
|
|
1496
|
+
Informs that the connection has been established.
|
|
1497
|
+
|
|
1498
|
+
```js
|
|
1499
|
+
customerSDK.on('connected', payload => {
|
|
1500
|
+
const { customer, availability, greeting } = payload
|
|
1501
|
+
console.log('connected', { customer, availability, greeting })
|
|
1502
|
+
})
|
|
1503
|
+
```
|
|
1504
|
+
|
|
1505
|
+
Payload:
|
|
1506
|
+
|
|
1507
|
+
| argument | type | description |
|
|
1508
|
+
| ------------ | -------- | ---------------------------------------------------------------------------- |
|
|
1509
|
+
| customer | object | Customer object, the same as the response from [`getCustomer`](#getcustomer) |
|
|
1510
|
+
| availability | string | 'online' or 'offline' |
|
|
1511
|
+
| greeting | greeting | Optional greeting received before the thread started |
|
|
1512
|
+
|
|
1513
|
+
Greeting:
|
|
1514
|
+
|
|
1515
|
+
| argument | type | description |
|
|
1516
|
+
| ------------------ | ------- | ------------------------------------ |
|
|
1517
|
+
| id | number | Greeting template identifier |
|
|
1518
|
+
| text | string | Text content of the greeting message |
|
|
1519
|
+
| uniqueId | string | Unique event ID of the greeting |
|
|
1520
|
+
| displayedFirstTime | boolean | |
|
|
1521
|
+
| accepted | boolean | |
|
|
1522
|
+
| agent.id | string | |
|
|
1523
|
+
| agent.name | string | |
|
|
1524
|
+
| agent.avatar | string | |
|
|
1525
|
+
| agent.jobTitle | string | |
|
|
1526
|
+
| agent.isBot | boolean | |
|
|
1527
|
+
|
|
1528
|
+
## Connection recovered
|
|
1529
|
+
|
|
1530
|
+
Informs that Customer SDK has recovered from an "unstable" connection state. It's always preceded by the [`"connection_unstable"`](#connection-unstable) event.
|
|
1531
|
+
|
|
1532
|
+
```js
|
|
1533
|
+
customerSDK.on('connection_recovered', () => {
|
|
1534
|
+
console.log('connection_recovered')
|
|
1535
|
+
})
|
|
1536
|
+
```
|
|
1537
|
+
|
|
1538
|
+
This event doesn't carry any additional payload.
|
|
1539
|
+
|
|
1540
|
+
## Connection unstable
|
|
1541
|
+
|
|
1542
|
+
Informs that Customer SDK has detected that connection quality is poor. It doesn't mean that it has disconnected from the server just yet.
|
|
1543
|
+
|
|
1544
|
+
```js
|
|
1545
|
+
customerSDK.on('connection_unstable', () => {
|
|
1546
|
+
console.log('connection_unstable')
|
|
1547
|
+
})
|
|
1548
|
+
```
|
|
1549
|
+
|
|
1550
|
+
This event doesn't carry any additional payload.
|
|
1551
|
+
|
|
1552
|
+
## Customer ID
|
|
1553
|
+
|
|
1554
|
+
Informs about the ID of the Customer.
|
|
1555
|
+
|
|
1556
|
+
```js
|
|
1557
|
+
customerSDK.on('customer_id', id => {
|
|
1558
|
+
console.log('customer id is', id)
|
|
1559
|
+
})
|
|
1560
|
+
```
|
|
1561
|
+
|
|
1562
|
+
Payload:
|
|
1563
|
+
|
|
1564
|
+
| argument | type |
|
|
1565
|
+
| -------- | ------ |
|
|
1566
|
+
| id | string |
|
|
1567
|
+
|
|
1568
|
+
## Customer page updated
|
|
1569
|
+
|
|
1570
|
+
The Customer moved to another page, for example by following a link on your website.
|
|
1571
|
+
|
|
1572
|
+
```js
|
|
1573
|
+
customerSDK.on('customer_page_updated', payload => {
|
|
1574
|
+
const { url, title, openedAt } = payload
|
|
1575
|
+
console.log('customer_page_updated', { url, title, openedAt })
|
|
1576
|
+
})
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
Payload:
|
|
1580
|
+
|
|
1581
|
+
| properties | type | |
|
|
1582
|
+
| ---------- | ------ | ---------------------------------------------------- |
|
|
1583
|
+
| url | string | URL of the Customer current website |
|
|
1584
|
+
| title | string | Title of the Customer current website |
|
|
1585
|
+
| openedAt | string | Date of the last update in RFC 3339 date-time format |
|
|
1586
|
+
|
|
1587
|
+
## Customer updated
|
|
1588
|
+
|
|
1589
|
+
Informs that Customer's data was updated.
|
|
1590
|
+
Each property in payload is available only if it was updated.
|
|
1591
|
+
|
|
1592
|
+
```js
|
|
1593
|
+
customerSDK.on('customer_updated', customer => {
|
|
1594
|
+
if (customer.name) {
|
|
1595
|
+
console.log(`Name got updated to: ${customer.name}`)
|
|
1596
|
+
}
|
|
1597
|
+
if (customer.email) {
|
|
1598
|
+
console.log(`Email got updated to: ${customer.email}`)
|
|
1599
|
+
}
|
|
1600
|
+
if (customer.avatar) {
|
|
1601
|
+
console.log(`Avatar got updated to: ${customer.avatar}`)
|
|
1602
|
+
}
|
|
1603
|
+
if (customer.fields) {
|
|
1604
|
+
console.log(`Fields got updated:`)
|
|
1605
|
+
console.log(customer.fields)
|
|
1606
|
+
}
|
|
1607
|
+
})
|
|
1608
|
+
```
|
|
1609
|
+
|
|
1610
|
+
Payload:
|
|
1611
|
+
|
|
1612
|
+
| properties | type |
|
|
1613
|
+
| ---------- | ------ |
|
|
1614
|
+
| name | string |
|
|
1615
|
+
| email | string |
|
|
1616
|
+
| avatar | string |
|
|
1617
|
+
| fields | object |
|
|
1618
|
+
|
|
1619
|
+
## Disconnected
|
|
1620
|
+
|
|
1621
|
+
Informs that SDK has disconnected from the server. The event provides the disconnection reason.
|
|
1622
|
+
|
|
1623
|
+
```js
|
|
1624
|
+
customerSDK.on('disconnected', payload => {
|
|
1625
|
+
const { reason } = payload
|
|
1626
|
+
console.log('disconnected', { reason })
|
|
1627
|
+
})
|
|
1628
|
+
```
|
|
1629
|
+
|
|
1630
|
+
Payload:
|
|
1631
|
+
|
|
1632
|
+
| properties | type | description |
|
|
1633
|
+
| ---------- | ------ | ----------------------------------------------- |
|
|
1634
|
+
| reason | string | [disconnection reasons](#disconnection-reasons) |
|
|
1635
|
+
|
|
1636
|
+
## Event properties deleted
|
|
1637
|
+
|
|
1638
|
+
Informs about the event properties that were deleted.
|
|
1639
|
+
|
|
1640
|
+
```js
|
|
1641
|
+
customerSDK.on('event_properties_deleted', payload => {
|
|
1642
|
+
const { chatId, threadId, eventId, properties } = payload
|
|
1643
|
+
console.log('event_properties_deleted', {
|
|
1644
|
+
chatId,
|
|
1645
|
+
threadId,
|
|
1646
|
+
eventId,
|
|
1647
|
+
properties,
|
|
1648
|
+
})
|
|
1649
|
+
})
|
|
1650
|
+
```
|
|
1651
|
+
|
|
1652
|
+
Payload:
|
|
1653
|
+
|
|
1654
|
+
| properties | type | description |
|
|
1655
|
+
| ---------- | ------ | ---------------- |
|
|
1656
|
+
| chatId | string | Chat ID |
|
|
1657
|
+
| threadId | string | Thread ID |
|
|
1658
|
+
| eventId | string | Event ID |
|
|
1659
|
+
| properties | object | Event properties |
|
|
1660
|
+
|
|
1661
|
+
## Event properties updated
|
|
1662
|
+
|
|
1663
|
+
Informs about the event properties that were updated.
|
|
1664
|
+
|
|
1665
|
+
```js
|
|
1666
|
+
customerSDK.on('event_properties_updated', payload => {
|
|
1667
|
+
const { chatId, threadId, eventId, properties } = payload
|
|
1668
|
+
console.log('event_properties_updated', {
|
|
1669
|
+
chatId,
|
|
1670
|
+
threadId,
|
|
1671
|
+
eventId,
|
|
1672
|
+
properties,
|
|
1673
|
+
})
|
|
1674
|
+
})
|
|
1675
|
+
```
|
|
1676
|
+
|
|
1677
|
+
Payload:
|
|
1678
|
+
|
|
1679
|
+
| properties | type | description |
|
|
1680
|
+
| ---------- | ------ | ---------------- |
|
|
1681
|
+
| chatId | string | Chat ID |
|
|
1682
|
+
| threadId | string | Thread ID |
|
|
1683
|
+
| eventId | string | Event ID |
|
|
1684
|
+
| properties | object | Event properties |
|
|
1685
|
+
|
|
1686
|
+
## Event updated
|
|
1687
|
+
|
|
1688
|
+
Informs that an event was updated.
|
|
1689
|
+
|
|
1690
|
+
```js
|
|
1691
|
+
customerSDK.on('event_updated', payload => {
|
|
1692
|
+
const { chatId, threadId, event } = payload
|
|
1693
|
+
console.log('event_updated', { chatId, threadId, event })
|
|
1694
|
+
})
|
|
1695
|
+
```
|
|
1696
|
+
|
|
1697
|
+
Payload:
|
|
1698
|
+
|
|
1699
|
+
| properties | type | description |
|
|
1700
|
+
| ---------- | ------ | ------------------------ |
|
|
1701
|
+
| chatId | string | Chat ID |
|
|
1702
|
+
| threadId | string | Thread ID |
|
|
1703
|
+
| event | object | The entire updated event |
|
|
1704
|
+
|
|
1705
|
+
## Events marked as seen
|
|
1706
|
+
|
|
1707
|
+
Informs that the events were seen by the particular user.
|
|
1708
|
+
|
|
1709
|
+
```js
|
|
1710
|
+
customerSDK.on('events_marked_as_seen', payload => {
|
|
1711
|
+
const { chatId, userId, seenUpTo } = payload
|
|
1712
|
+
console.log('events_marked_as_seen', { chatId, userId, seenUpTo })
|
|
1713
|
+
})
|
|
1714
|
+
```
|
|
1715
|
+
|
|
1716
|
+
Payload:
|
|
1717
|
+
|
|
1718
|
+
| properties | type | description |
|
|
1719
|
+
| ---------- | ------ | ------------------------- |
|
|
1720
|
+
| chatId | string | Chat ID |
|
|
1721
|
+
| userId | string | User ID |
|
|
1722
|
+
| seenUpTo | string | RFC 3339 date-time format |
|
|
1723
|
+
|
|
1724
|
+
## Greeting accepted
|
|
1725
|
+
|
|
1726
|
+
Informs about a greeting accepted by the Customer.
|
|
1727
|
+
|
|
1728
|
+
```js
|
|
1729
|
+
customerSDK.on('greeting_accepted', payload => {
|
|
1730
|
+
console.log('greeting_accepted', payload.uniqueId)
|
|
1731
|
+
})
|
|
1732
|
+
```
|
|
1733
|
+
|
|
1734
|
+
Payload:
|
|
1735
|
+
|
|
1736
|
+
| properties | type |
|
|
1737
|
+
| ---------- | ------ |
|
|
1738
|
+
| uniqueId | string |
|
|
1739
|
+
|
|
1740
|
+
## Greeting canceled
|
|
1741
|
+
|
|
1742
|
+
Informs about a greeting canceled by the Customer. It is also emitted when a new greeting automatically cancels the currently displayed one.
|
|
1743
|
+
|
|
1744
|
+
```js
|
|
1745
|
+
customerSDK.on('greeting_canceled', payload => {
|
|
1746
|
+
console.log('greeting_canceled', payload.uniqueId)
|
|
1747
|
+
})
|
|
1748
|
+
```
|
|
1749
|
+
|
|
1750
|
+
Payload:
|
|
1751
|
+
|
|
1752
|
+
| properties | type |
|
|
1753
|
+
| ---------- | ------ |
|
|
1754
|
+
| uniqueId | string |
|
|
1755
|
+
|
|
1756
|
+
## Incoming chat
|
|
1757
|
+
|
|
1758
|
+
Informs about a newly started chat thread.
|
|
1759
|
+
The payload contains the chat data structure and an object describing the new thread.
|
|
1760
|
+
If the chat was started with some initial events, they will be included in the thread object.
|
|
1761
|
+
|
|
1762
|
+
```js
|
|
1763
|
+
customerSDK.on('incoming_chat', payload => {
|
|
1764
|
+
const { chat } = payload
|
|
1765
|
+
const { id, access, users, properties, thread } = chat
|
|
1766
|
+
console.log('incoming_chat', { id, access, users, properties, thread })
|
|
1767
|
+
})
|
|
1768
|
+
```
|
|
1769
|
+
|
|
1770
|
+
Payload:
|
|
1771
|
+
|
|
1772
|
+
| properties | type | description |
|
|
1773
|
+
| --------------- | -------- | ------------------------------------ |
|
|
1774
|
+
| chat.id | string | Chat ID |
|
|
1775
|
+
| chat.access | object | Chat initial access |
|
|
1776
|
+
| chat.users | object[] | Users objects referenced in the chat |
|
|
1777
|
+
| chat.properties | object | Chat properties |
|
|
1778
|
+
| chat.thread | object | |
|
|
1779
|
+
|
|
1780
|
+
## Incoming event
|
|
1781
|
+
|
|
1782
|
+
Informs about an incoming event sent to a chat.
|
|
1783
|
+
You should distinguish received events by their types.
|
|
1784
|
+
|
|
1785
|
+
```js
|
|
1786
|
+
customerSDK.on('incoming_event', payload => {
|
|
1787
|
+
const { chat, event } = payload
|
|
1788
|
+
switch (event.type) {
|
|
1789
|
+
case 'message':
|
|
1790
|
+
console.log('new message - ', event.text)
|
|
1791
|
+
break
|
|
1792
|
+
default:
|
|
1793
|
+
break
|
|
1794
|
+
}
|
|
1795
|
+
})
|
|
1796
|
+
```
|
|
1797
|
+
|
|
1798
|
+
Payload:
|
|
1799
|
+
|
|
1800
|
+
| properties | type | description |
|
|
1801
|
+
| ---------- | ------ | ---------------- |
|
|
1802
|
+
| type | string | Event type |
|
|
1803
|
+
| ... | | Other properties |
|
|
1804
|
+
|
|
1805
|
+
## Incoming greeting
|
|
1806
|
+
|
|
1807
|
+
Informs about an incoming greeting.
|
|
1808
|
+
|
|
1809
|
+
```js
|
|
1810
|
+
customerSDK.on('incoming_greeting', payload => {
|
|
1811
|
+
const { text, agent } = payload
|
|
1812
|
+
const { name } = agent
|
|
1813
|
+
console.log(`Received a greeting with "${text}" text content from ${name}.`)
|
|
1814
|
+
})
|
|
1815
|
+
```
|
|
1816
|
+
|
|
1817
|
+
Payload:
|
|
1818
|
+
|
|
1819
|
+
| properties | type | description |
|
|
1820
|
+
| ------------------ | ------- | ----------------------------------------------------------- |
|
|
1821
|
+
| id | number | Greeting template ID |
|
|
1822
|
+
| text | string | Greeting text content |
|
|
1823
|
+
| uniqueId | string | Greeting unique ID |
|
|
1824
|
+
| displayedFirstTime | boolean | Describes if the greeting was generated for the first time. |
|
|
1825
|
+
| accepted | boolean | Chat properties |
|
|
1826
|
+
| agent | object | Agent user |
|
|
1827
|
+
|
|
1828
|
+
## Incoming rich message postback
|
|
1829
|
+
|
|
1830
|
+
Informs about an incoming rich message postback.
|
|
1831
|
+
|
|
1832
|
+
```js
|
|
1833
|
+
customerSDK.on('incoming_rich_message_postback', payload => {
|
|
1834
|
+
const { chatId, threadId, eventId, userId, postback } = payload
|
|
1835
|
+
console.log('incoming_rich_message_postback', {
|
|
1836
|
+
chatId,
|
|
1837
|
+
threadId,
|
|
1838
|
+
eventId,
|
|
1839
|
+
userId,
|
|
1840
|
+
postback,
|
|
1841
|
+
})
|
|
1842
|
+
})
|
|
1843
|
+
```
|
|
1844
|
+
|
|
1845
|
+
Payload:
|
|
1846
|
+
|
|
1847
|
+
| properties | type | description |
|
|
1848
|
+
| ---------------- | ------- | ------------------------------------------- |
|
|
1849
|
+
| chatId | string | Chat ID of the sent postback |
|
|
1850
|
+
| threadId | string | Thread ID of the sent postback |
|
|
1851
|
+
| eventId | string | Event ID of the sent postback |
|
|
1852
|
+
| userId | number | User who has sent a rich message postback |
|
|
1853
|
+
| postback.id | boolean | ID of the sent postback |
|
|
1854
|
+
| postback.toggled | boolean | Describes if the sent postback was toggled. |
|
|
1855
|
+
|
|
1856
|
+
## Incoming typing indicator
|
|
1857
|
+
|
|
1858
|
+
Informs that one of the chat users is currently typing a message.
|
|
1859
|
+
The message hasn't been sent yet.
|
|
1860
|
+
The push payload contains the typing indicator object.
|
|
1861
|
+
|
|
1862
|
+
```js
|
|
1863
|
+
customerSDK.on('incoming_typing_indicator', payload => {
|
|
1864
|
+
if (payload.typingIndicator.isTyping) {
|
|
1865
|
+
console.log(
|
|
1866
|
+
`user with ${payload.typingIndicator.authorId} id is writing something in ${payload.chatId}`,
|
|
1867
|
+
)
|
|
1868
|
+
} else {
|
|
1869
|
+
console.log(
|
|
1870
|
+
`user with ${payload.typingIndicator.authorId} id stopped writing in ${payload.chatId}`,
|
|
1871
|
+
)
|
|
1872
|
+
}
|
|
1873
|
+
})
|
|
1874
|
+
```
|
|
1875
|
+
|
|
1876
|
+
Payload:
|
|
1877
|
+
|
|
1878
|
+
| properties | type | description |
|
|
1879
|
+
| ------------------------ | ------- | ----------- |
|
|
1880
|
+
| chatId | string | Chat ID |
|
|
1881
|
+
| typingIndicator | | |
|
|
1882
|
+
| typingIndicator.authorId | string | User ID |
|
|
1883
|
+
| typingIndicator.isTyping | boolean | |
|
|
1884
|
+
|
|
1885
|
+
## Queue position updated
|
|
1886
|
+
|
|
1887
|
+
Informs that the queue position has been updated.
|
|
1888
|
+
|
|
1889
|
+
```js
|
|
1890
|
+
customerSDK.on('queue_position_updated', payload => {
|
|
1891
|
+
console.log(payload.chatId)
|
|
1892
|
+
console.log(payload.threadId)
|
|
1893
|
+
console.log(payload.queue.position)
|
|
1894
|
+
console.log(payload.queue.waitTime)
|
|
1895
|
+
})
|
|
1896
|
+
```
|
|
1897
|
+
|
|
1898
|
+
Payload:
|
|
1899
|
+
|
|
1900
|
+
| properties | type | description |
|
|
1901
|
+
| -------------- | ------ | -------------------------------------------------------------------------- |
|
|
1902
|
+
| chatId | string | Chat ID |
|
|
1903
|
+
| threadId | string | Thread ID |
|
|
1904
|
+
| queue | | |
|
|
1905
|
+
| queue.position | number | Current place in the queue |
|
|
1906
|
+
| queue.waitTime | number | Estimated waiting time for an agent to be assigned to the chat, in seconds |
|
|
1907
|
+
|
|
1908
|
+
## Thread properties deleted
|
|
1909
|
+
|
|
1910
|
+
Informs about deleted thread properties.
|
|
1911
|
+
|
|
1912
|
+
```js
|
|
1913
|
+
customerSDK.on('thread_properties_deleted', payload => {
|
|
1914
|
+
const { chatId, threadId, properties } = payload
|
|
1915
|
+
console.log('thread_properties_deleted', { chatId, threadId, properties })
|
|
1916
|
+
})
|
|
1917
|
+
```
|
|
1918
|
+
|
|
1919
|
+
Payload:
|
|
1920
|
+
|
|
1921
|
+
| properties | type | description |
|
|
1922
|
+
| ---------- | ------ | ---------------------- |
|
|
1923
|
+
| chatId | string | Chat ID |
|
|
1924
|
+
| threadId | string | Thread ID |
|
|
1925
|
+
| properties | object | Chat thread properties |
|
|
1926
|
+
|
|
1927
|
+
## Thread properties updated
|
|
1928
|
+
|
|
1929
|
+
Informs about updated thread properties.
|
|
1930
|
+
|
|
1931
|
+
```js
|
|
1932
|
+
customerSDK.on('thread_properties_updated', payload => {
|
|
1933
|
+
const { chatId, threadId, properties } = payload
|
|
1934
|
+
console.log('thread_properties_updated', { chatId, threadId, properties })
|
|
1935
|
+
})
|
|
1936
|
+
```
|
|
1937
|
+
|
|
1938
|
+
Payload:
|
|
1939
|
+
|
|
1940
|
+
| properties | type | description |
|
|
1941
|
+
| ---------- | ------ | ----------------- |
|
|
1942
|
+
| chatId | string | Chat ID |
|
|
1943
|
+
| threadId | string | Thread ID |
|
|
1944
|
+
| properties | object | Thread properties |
|
|
1945
|
+
|
|
1946
|
+
## User added to chat
|
|
1947
|
+
|
|
1948
|
+
Informs that a user was added to a chat.
|
|
1949
|
+
|
|
1950
|
+
```js
|
|
1951
|
+
customerSDK.on('user_added_to_chat', payload => {
|
|
1952
|
+
const { chatId, user, present } = payload
|
|
1953
|
+
console.log('user_added_to_chat', { chatId, user, present })
|
|
1954
|
+
})
|
|
1955
|
+
```
|
|
1956
|
+
|
|
1957
|
+
Payload:
|
|
1958
|
+
|
|
1959
|
+
| properties | type | description |
|
|
1960
|
+
| ---------- | ------- | ----------- |
|
|
1961
|
+
| chatId | string | Chat ID |
|
|
1962
|
+
| user | object | User |
|
|
1963
|
+
| present | boolean | |
|
|
1964
|
+
|
|
1965
|
+
## User data
|
|
1966
|
+
|
|
1967
|
+
Contains the information about the User data.
|
|
1968
|
+
|
|
1969
|
+
```js
|
|
1970
|
+
customerSDK.on('user_data', user => {
|
|
1971
|
+
console.log(user)
|
|
1972
|
+
})
|
|
1973
|
+
```
|
|
1974
|
+
|
|
1975
|
+
### Customer user type:
|
|
1976
|
+
|
|
1977
|
+
| properties | type | description |
|
|
1978
|
+
| ---------- | -------------- | ----------- |
|
|
1979
|
+
| type | 'customer' | |
|
|
1980
|
+
| id | string | |
|
|
1981
|
+
| name | string | Optional |
|
|
1982
|
+
| email | string | Optional |
|
|
1983
|
+
| avatar | string | Optional |
|
|
1984
|
+
| fields | customerFields | |
|
|
1985
|
+
|
|
1986
|
+
### Agent user type:
|
|
1987
|
+
|
|
1988
|
+
| properties | type |
|
|
1989
|
+
| ---------- | ------- |
|
|
1990
|
+
| type | 'agent' |
|
|
1991
|
+
| id | string |
|
|
1992
|
+
| name | string |
|
|
1993
|
+
| avatar | string |
|
|
1994
|
+
| jobTitle | string |
|
|
1995
|
+
|
|
1996
|
+
## User removed from chat
|
|
1997
|
+
|
|
1998
|
+
Informs that a user was removed from a chat.
|
|
1999
|
+
|
|
2000
|
+
```js
|
|
2001
|
+
customerSDK.on('user_removed_from_chat', payload => {
|
|
2002
|
+
const { chatId, userId } = payload
|
|
2003
|
+
console.log('user_removed_from_chat', { chatId, userId })
|
|
2004
|
+
})
|
|
2005
|
+
```
|
|
2006
|
+
|
|
2007
|
+
Payload:
|
|
2008
|
+
|
|
2009
|
+
| properties | type | description |
|
|
2010
|
+
| ---------- | ------ | ----------- |
|
|
2011
|
+
| chatId | string | Chat ID |
|
|
2012
|
+
| userId | string | User ID |
|
|
2013
|
+
|
|
2014
|
+
# Disconnection reasons
|
|
2015
|
+
|
|
2016
|
+
Most of the disconnection reasons can be treated as errors. Because of that, you can find their detailed descriptions in this section.
|
|
2017
|
+
|
|
2018
|
+
```js
|
|
2019
|
+
customerSDK.on('disconnected', ({ reason }) => {
|
|
2020
|
+
switch (reason) {
|
|
2021
|
+
case 'access_token_expired':
|
|
2022
|
+
// handle particular disconnection reasons
|
|
2023
|
+
break
|
|
2024
|
+
// ...
|
|
2025
|
+
default:
|
|
2026
|
+
}
|
|
2027
|
+
})
|
|
2028
|
+
```
|
|
2029
|
+
|
|
2030
|
+
## Access token expired
|
|
2031
|
+
|
|
2032
|
+
Access token lifetime has elapsed. Customer SDK fetches a new token and reconnects to the server on its own. This is emitted to the user for informational purposes, so for example a reconnection bar can be displayed.
|
|
2033
|
+
|
|
2034
|
+
## Connection lost
|
|
2035
|
+
|
|
2036
|
+
Disconnected because of the poor connection quality. Customer SDK will try to reconnect on its own.
|
|
2037
|
+
|
|
2038
|
+
## Customer banned
|
|
2039
|
+
|
|
2040
|
+
The Customer has been banned.
|
|
2041
|
+
|
|
2042
|
+
This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
|
|
2043
|
+
|
|
2044
|
+
## Customer temporarily blocked
|
|
2045
|
+
|
|
2046
|
+
The Customer tried reconnecting too many times after the [`"too_many_connections"`](#too-many-connections) error had occurred.
|
|
2047
|
+
|
|
2048
|
+
This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
|
|
2049
|
+
|
|
2050
|
+
## Identity mismatch
|
|
2051
|
+
|
|
2052
|
+
The identity of the Customer has changed between reconnects. This might happen if cookies can't be persisted in the browser.
|
|
2053
|
+
|
|
2054
|
+
This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
|
|
2055
|
+
|
|
2056
|
+
## Inactivity timeout
|
|
2057
|
+
|
|
2058
|
+
The Customer didn't chat or change the page in the past 30 minutes. Customer SDK **won't** try to reconnect on its own after receiving this error. You should implement a reconnect login on your own. Preferably you should only try to reconnect when you detect a clear intention of chatting from your user.
|
|
2059
|
+
|
|
2060
|
+
## Internal error
|
|
2061
|
+
|
|
2062
|
+
Internal error. Customer SDK reconnects on its own.
|
|
2063
|
+
|
|
2064
|
+
## License expired
|
|
2065
|
+
|
|
2066
|
+
The license with the specified ID has expired. You should make sure that there are no unpaid invoices for it.
|
|
2067
|
+
|
|
2068
|
+
## License not found
|
|
2069
|
+
|
|
2070
|
+
The license with the specified ID doesn't exist. You should check the options passed in to Customer SDK and make sure that the license parameter is correct.
|
|
2071
|
+
|
|
2072
|
+
This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
|
|
2073
|
+
|
|
2074
|
+
## Misdirected connection
|
|
2075
|
+
|
|
2076
|
+
You have connected to a server in the wrong region. Customer SDK reconnects to the correct region on its own, but to avoid this problem altogether, you should provide the correct `region` parameter when initializing the SDK. This is emitted to the user for informational purposes, so for example a reconnection bar can be displayed.
|
|
2077
|
+
|
|
2078
|
+
## Too many connections
|
|
2079
|
+
|
|
2080
|
+
The Customer has reached the maximum number of connections. You should avoid opening too many concurrent connections for the same Customer.
|
|
2081
|
+
|
|
2082
|
+
This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
|
|
2083
|
+
|
|
2084
|
+
## Too many unauthorized connections
|
|
2085
|
+
|
|
2086
|
+
The maximum number of unauthorized connections has been reached. This error can only be received immediately after you try to connect to our servers when there are too many pending (unauthorized) connections. Once you get authorized, you stay that way and the Customer SDK reconnects on its own.
|
|
2087
|
+
|
|
2088
|
+
## Unsupported version
|
|
2089
|
+
|
|
2090
|
+
Connecting to an unsupported version of the Customer Chat API. You should upgrade your Customer SDK version.
|
|
2091
|
+
|
|
2092
|
+
This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
|
|
2093
|
+
|
|
2094
|
+
## Users limit reached
|
|
2095
|
+
|
|
2096
|
+
The maximum number of Customers connected at the same time has been reached. This can only be received immediately after we try to connect to our servers, because once you get authorized, you stay that way. The limit is different for each plan, and you can check the exact values on our [pricing page](https://www.livechat.com/pricing/).
|
|
2097
|
+
|
|
2098
|
+
This internally disconnects from the current instance of the Customer SDK. After that, the manual `connect()` call will be required, preferably linked to the user's action rather than automated.
|
|
2099
|
+
|
|
2100
|
+
# Errors
|
|
2101
|
+
|
|
2102
|
+
This is the list of standard error codes. You can receive them for all available methods which perform API calls. It means the errors can occur for methods returning Promises. Because we wrap API calls with Promise interface, the errors are available on the thrown `Error` objects under the `code` property. They can be caught using a regular Promise `catch` method.
|
|
2103
|
+
|
|
2104
|
+
There are also some per-method error codes, which are not described below. They are mentioned under corresponding methods instead.
|
|
2105
|
+
|
|
2106
|
+
## Connection lost
|
|
2107
|
+
|
|
2108
|
+
All in-flight requests fail with this one when the network connection gets lost.
|
|
2109
|
+
|
|
2110
|
+
## Customer banned
|
|
2111
|
+
|
|
2112
|
+
The Customer has been banned.
|
|
2113
|
+
|
|
2114
|
+
## Group not found
|
|
2115
|
+
|
|
2116
|
+
Can be received in response to any request that accepts a group somewhere in its payload.
|
|
2117
|
+
|
|
2118
|
+
## Internal
|
|
2119
|
+
|
|
2120
|
+
Internal error.
|
|
2121
|
+
|
|
2122
|
+
## Pending requests limit reached
|
|
2123
|
+
|
|
2124
|
+
This is a rate-limiting error.
|
|
2125
|
+
You have sent out too many requests in a too short time period without waiting for them to resolve.
|
|
2126
|
+
|
|
2127
|
+
## Request timeout
|
|
2128
|
+
|
|
2129
|
+
The request has timed out.
|
|
2130
|
+
|
|
2131
|
+
## Service unavailable
|
|
2132
|
+
|
|
2133
|
+
The backend service is under heavy traffic and it had to restrict creation of a new resource.
|
|
2134
|
+
|
|
2135
|
+
## Validation
|
|
2136
|
+
|
|
2137
|
+
Wrong format of request, for example a `string` sent in the place of a `number`.
|
|
2138
|
+
|
|
2139
|
+
# Recipes
|
|
2140
|
+
|
|
2141
|
+
## Chat transcript feature
|
|
2142
|
+
|
|
2143
|
+
To implement [Chat transcript](https://www.livechat.com/features/engaging-customers/#Chat-transcript), you need to set the `transcript_email` thread property in the `routing` namespace. The value of this property should be set to the email address of the requester.
|
|
2144
|
+
|
|
2145
|
+
```js
|
|
2146
|
+
customerSDK
|
|
2147
|
+
.updateThreadProperties({
|
|
2148
|
+
chatId: 'ON0X0R0L67',
|
|
2149
|
+
threadId: 'OS0C0W0Z1B',
|
|
2150
|
+
properties: {
|
|
2151
|
+
routing: {
|
|
2152
|
+
transcript_email: 'john.doe@example.com',
|
|
2153
|
+
},
|
|
2154
|
+
},
|
|
2155
|
+
})
|
|
2156
|
+
.then(response => {
|
|
2157
|
+
console.log(response)
|
|
2158
|
+
})
|
|
2159
|
+
.catch(error => {
|
|
2160
|
+
console.log(error)
|
|
2161
|
+
})
|
|
2162
|
+
```
|
|
2163
|
+
|
|
2164
|
+
## Hard limit error handling
|
|
2165
|
+
|
|
2166
|
+
In order to handle [hard limit error](https://developers.livechat.com/docs/extending-chat-widget/customer-sdk/#users-limit-reached) properly, you can listen for this specific disconnect reason and then react accordingly. In our case, we are showing simple information that our agents are not available at the moment.
|
|
2167
|
+
|
|
2168
|
+
```js
|
|
2169
|
+
customerSDK.on('disconnected', ({ reason }) => {
|
|
2170
|
+
if (reason === 'users_limit_reached') {
|
|
2171
|
+
console.log('Our agents are not available at the moment')
|
|
2172
|
+
}
|
|
2173
|
+
})
|
|
2174
|
+
```
|
|
2175
|
+
|
|
2176
|
+
# Changelog
|
|
2177
|
+
|
|
2178
|
+
## [v3.1.0] - 2021-10-7
|
|
2179
|
+
|
|
2180
|
+
### Added
|
|
2181
|
+
|
|
2182
|
+
- New optional `config` property `identityProvider`, which allows for specifying own custom access token handlers.
|
|
2183
|
+
- Handle new event type `'form'` representing the optional custom forms sent from the server.
|
|
2184
|
+
|
|
2185
|
+
## [v3.0.0] - 2021-05-25
|
|
2186
|
+
|
|
2187
|
+
### Fixed
|
|
2188
|
+
|
|
2189
|
+
- Chat structures can now have `thread` set to `null` since it's possible for threads to be removed
|
|
2190
|
+
- Prevented additional connections to be created in the case when SDK gets destroyed in the middle of the `login` flow
|
|
2191
|
+
|
|
2192
|
+
### Changed
|
|
2193
|
+
|
|
2194
|
+
- Switched to using Customer API 3.3:
|
|
2195
|
+
- `activateChat` method has been renamed to `resumeChat`.
|
|
2196
|
+
- In the `deactivateChat` method, the `chat_id` parameter was renamed to `id`.
|
|
2197
|
+
- In the `updateChatProperties` method, the `chat_id` parameter was renamed to `id`.
|
|
2198
|
+
- In the `deleteChatProperties` method, the `chat_id` parameter was renamed to `id`.
|
|
2199
|
+
- In the `getPredictedAgent` method, agent properties are grouped in `agent` property and additional `queue` parameter is returned.
|
|
2200
|
+
- In the `customer_page_updated` event the `timestamp` property has been replaced with `openedAt`.
|
|
2201
|
+
- In the `customer_updated` event customer data is no longer grouped in the `customer` object but rather all properties are returned at the top level.
|
|
2202
|
+
- The communication with the server is done now using WebSocket endpoint, without the SockJS overhead.
|
|
2203
|
+
- Users limit handling changed from destroying the instance to disconnecting.
|
|
2204
|
+
|
|
2205
|
+
### Added
|
|
2206
|
+
|
|
2207
|
+
- `active` parameter to the `startChat` & `resumeChat` methods. It defaults to `true` but can be used to create threads that are immediately inactive.
|
|
2208
|
+
- Greetings can now have a `subtype` property.
|
|
2209
|
+
- Support for `alternative_text` image property in:
|
|
2210
|
+
- image attachments
|
|
2211
|
+
- rich greetings
|
|
2212
|
+
- rich messages
|
|
2213
|
+
- `cancel` button type in rich messages.
|
|
2214
|
+
- Support for the events of type `"custom"`
|
|
2215
|
+
|
|
2216
|
+
## [v2.0.4] - 2020-10-28
|
|
2217
|
+
|
|
2218
|
+
### Added
|
|
2219
|
+
|
|
2220
|
+
- Updated documentation.
|
|
2221
|
+
|
|
2222
|
+
## [v2.0.3] - 2020-08-31
|
|
2223
|
+
|
|
2224
|
+
### Fixed
|
|
2225
|
+
|
|
2226
|
+
- Fixed API compatibility issues that could cause misalignment in data shape.
|
|
2227
|
+
|
|
2228
|
+
## [v2.0.2] - 2020-08-21
|
|
2229
|
+
|
|
2230
|
+
## Fixed
|
|
2231
|
+
|
|
2232
|
+
- Updated the `@livechat/file-upload` dependency to resolve compatibility issues.
|
|
2233
|
+
|
|
2234
|
+
## [v2.0.1] - 2020-06-24
|
|
2235
|
+
|
|
2236
|
+
### Fixed
|
|
2237
|
+
|
|
2238
|
+
- `rateChat` and `cancelRate` methods are updating properties of the correct thread now.
|
|
2239
|
+
|
|
2240
|
+
## [v2.0.0] - 2020-06-22
|
|
2241
|
+
|
|
2242
|
+
### Changed
|
|
2243
|
+
|
|
2244
|
+
- The iterator returned from `getChatHistory` no longer returns `users`. User data needs to be obtained independently, for example by using the `getChat` method.
|
|
2245
|
+
- `listChats` no longer accepts `offset` parameter. Instead, it now accepts `pageId` to which you can provide a value of `previousPageId` or `nextPageId` returned from the other `listChats` calls.
|
|
2246
|
+
- Chat objects returned from `listChats` no longer have the `lastThreadOrder` property, but they received a new `lastThreadCreatedAt` property instead.
|
|
2247
|
+
- The `threads` objects no longer have the `order` property, but they received a new `createdAt` property instead.
|
|
2248
|
+
- The `eventsSeenUpToMap` is no longer available on the thread object, it has been moved to chat objects.
|
|
2249
|
+
- The payload of the `chat_transferred` event was changed. It now always has the `reason` property. It contains the `queue` property if the chat has been transferred and queued immediately. `requesterId` is available when `reason` is equal to `"manual"`.
|
|
2250
|
+
|
|
2251
|
+
### Removed
|
|
2252
|
+
|
|
2253
|
+
- The `access_set` event has been removed. `chat_transferred` event covers for its use cases.
|
|
2254
|
+
- The `getChatThreads` and the `getChatThreadsSummary` methods have been removed. Newly introduced `listThreads` can be used instead.
|
|
2255
|
+
|
|
2256
|
+
### Added
|
|
2257
|
+
|
|
2258
|
+
- The `listThreads` and `getChat` methods have been added.
|
|
2259
|
+
- The thread objects gained back `userIds` property.
|
|
2260
|
+
- The thread objects got `previousThreadId` and `nextThreadId` properties.
|
|
2261
|
+
- The `sendTicketForm` methods accepts a new `timeZone` parameter which influences how times are formatted in a generated ticket.
|
|
2262
|
+
- Queue objects got a new `queuedAt` property. This doesn't apply to the information returned in `queue_position_updated` event.
|
|
2263
|
+
|
|
2264
|
+
## [v2.0.0-beta.2] - 2020-04-02
|
|
2265
|
+
|
|
2266
|
+
### Changed
|
|
2267
|
+
|
|
2268
|
+
- Renamed methods:
|
|
2269
|
+
- `closeThread` to `deactivateChat`
|
|
2270
|
+
- `deleteChatThreadProperties` to `deleteThreadProperties`
|
|
2271
|
+
- `getChatsSummary` to `listChats`
|
|
2272
|
+
- `getGroupsStatus` to `listGroupStatuses`
|
|
2273
|
+
- `getUrlDetails` to `getUrlInfo`
|
|
2274
|
+
- `updateChatThreadProperties` to `updateThreadProperties`
|
|
2275
|
+
- Renamed events:
|
|
2276
|
+
- `chat_thread_properties_deleted` to `thread_properties_deleted`
|
|
2277
|
+
- `chat_thread_properties_updated` to `thread_properties_updated`
|
|
2278
|
+
- `chat_user_added` to `user_added_to_chat`
|
|
2279
|
+
- `chat_user_removed` to `user_removed_from_chat`
|
|
2280
|
+
- `thread_closed` to `chat_deactivated`
|
|
2281
|
+
- `chat_transferred` event doesn't contain `type` and `ids` properties anymore. Instead `transferredTo` property is available. It has optional `agentIds` and `groupIds` properties
|
|
2282
|
+
|
|
2283
|
+
### Added
|
|
2284
|
+
|
|
2285
|
+
- `customer` data available in the `connected` callback
|
|
2286
|
+
- `statistics` property available on the Customer object returned from the `getCustomer` method
|
|
2287
|
+
|
|
2288
|
+
## [v2.0.0-beta.1] - 2020-03-13
|
|
2289
|
+
|
|
2290
|
+
### Fixed
|
|
2291
|
+
|
|
2292
|
+
- Updated the `@livechat/customer-auth` dependency, which has been previously published with broken dist files.
|
|
2293
|
+
|
|
2294
|
+
## [v2.0.0-beta.0] - 2020-03-12
|
|
2295
|
+
|
|
2296
|
+
### Changed
|
|
2297
|
+
|
|
2298
|
+
- Most methods have been changed to accept parameters by name instead of by position.
|
|
2299
|
+
We found this pattern to be easier to read and maintain in the long run.
|
|
2300
|
+
As an example, a call that previously might have looked like this: `customerSDK.updateChatProperties('ON0X0R0L67', properties)` will now look like this: `customerSDK.updateChatProperties({ chatId: 'ON0X0R0L67', properties })`.
|
|
2301
|
+
All methods and their respective parameters are described in the documentation.
|
|
2302
|
+
|
|
2303
|
+
- All data structures have been adjusted:
|
|
2304
|
+
Previously properties like `chat` or `thread` could hold a primitive value (usually a string) because they actually contained IDs.
|
|
2305
|
+
This has been confusing and all such properties have been renamed to have an `Id` suffix now.
|
|
2306
|
+
For example: `chat` was renamed to `chatId`, and `thread` was renamed to `threadId`.
|
|
2307
|
+
|
|
2308
|
+
- `updateCustomer` method now returns a Promise.
|
|
2309
|
+
Additionally, customer data is not sent automatically in the `login` request.
|
|
2310
|
+
If you still need to send customer data during the `login` request, you will need to provide a `customerDataProvider` in the configuration passed in the `init` call.
|
|
2311
|
+
This provider will be called before sending any `login` request.
|
|
2312
|
+
|
|
2313
|
+
- `connected` event no longer contains any chat information. You should use `getChatsSummary` and `getChatHistory` appropriately to fetch it.
|
|
2314
|
+
|
|
2315
|
+
- `getChatHistory` now returns an array of threads instead of an array of events.
|
|
2316
|
+
|
|
2317
|
+
- `sendEvent` can no longer activate an existing chat.
|
|
2318
|
+
You should use the `activateChat` method for that purpose.
|
|
2319
|
+
|
|
2320
|
+
- `new_event` event has been renamed to `incoming_event`.
|
|
2321
|
+
|
|
2322
|
+
- `customer_updated` doesn't provide the whole Customer object anymore.
|
|
2323
|
+
You will only receive the data that has actually been changed.
|
|
2324
|
+
|
|
2325
|
+
- Chat summary & incoming chat objects used to contain an array of user IDs.
|
|
2326
|
+
This has been changed to align with the API and you can now expect complete user objects in those objects.
|
|
2327
|
+
|
|
2328
|
+
- `getPredictedAgent` method requires a group argument now.
|
|
2329
|
+
|
|
2330
|
+
- `updateLastSeenTimestamp` method has been changed to `markEventsAsSeen`.
|
|
2331
|
+
|
|
2332
|
+
- `sendPostback` method has been changed to `sendRichMessagePostback`.
|
|
2333
|
+
|
|
2334
|
+
### Removed
|
|
2335
|
+
|
|
2336
|
+
- `reconnected` event got removed. You should just use a single `connected` handler for both initial connection and reconnets.
|
|
2337
|
+
|
|
2338
|
+
- `thread_summary` event got removed.
|
|
2339
|
+
|
|
2340
|
+
- `sendMessage` method has been removed. You can just use `sendEvent` to send any of the supported types of events.
|
|
2341
|
+
|
|
2342
|
+
- `user_is_typing` and `user_stopped_typing` events have been removed. You can use `incoming_typing_indicator` to receive those informations - it comes with a `isTyping` property.
|
|
2343
|
+
|
|
2344
|
+
- `user_joined_chat` and `user_left_chat` events have been renamed to `chat_user_added` and `chat_user_removed` respectively.
|
|
2345
|
+
|
|
2346
|
+
- `sendFile` method has been removed. You should use the new `uploadFile` method instead.
|
|
2347
|
+
|
|
2348
|
+
- Events of type `"annotation"` don't exist anymore. They were only used for rating events and now those are automatically added to a chat upon rating in a form of system events.
|
|
2349
|
+
|
|
2350
|
+
### Added
|
|
2351
|
+
|
|
2352
|
+
- `incoming_typing_indicator` event replaced `user_is_typing` and `user_stopped_typing` events.
|
|
2353
|
+
|
|
2354
|
+
- optional `queue` property has been added on thread objects.
|
|
2355
|
+
|
|
2356
|
+
- `chat_user_added` and `chat_user_removed` events replaced `user_joined_chat` and `user_left_chat` events respectively.
|
|
2357
|
+
|
|
2358
|
+
- `getForm` and `sendTicketForm` have been added.
|
|
2359
|
+
|
|
2360
|
+
- `deleteChatProperties`, `deleteChatThreadProperties` and `deleteEventProperties` methods have been added with accompanying `chat_properties_deleted`, `chat_thread_properties_deleted` and `event_properties_deleted` events.
|
|
2361
|
+
|
|
2362
|
+
- `acceptGreeting` and `cancelGreeting` have been added with accompanying `incoming_greeting`, `greeting_accepted` and `greeting_canceled` events.
|
|
2363
|
+
|
|
2364
|
+
- `getCustomer` method has been added.
|
|
2365
|
+
|
|
2366
|
+
- `setCustomerSessionFields` method has been added.
|
|
2367
|
+
|
|
2368
|
+
- `cancelRate` method has been added.
|
|
2369
|
+
|
|
2370
|
+
- `getGroupsStatus` method has been added.
|
|
2371
|
+
|
|
2372
|
+
- `uploadFile` method has been added. It replaces `sendFile` and doesn't add an event of type `"file"` to a chat but rather returns a URL which you can then use to send a `"file"` event using the `sendEvent` method.
|
|
2373
|
+
|
|
2374
|
+
- `queue_position_updated` event has been added.
|
|
2375
|
+
|
|
2376
|
+
- `availability_changed` event has been added.
|
|
2377
|
+
|
|
2378
|
+
- `event_updated` event has been added.
|
|
2379
|
+
|
|
2380
|
+
- `access_set` event has been added.
|
|
2381
|
+
|
|
2382
|
+
- `chat_transferred` event has been added.
|
|
2383
|
+
|
|
2384
|
+
- `connection_recovered` and `connection_unstable` have been added.
|
|
2385
|
+
|
|
2386
|
+
- All possible errors and disconnection reasons have been documented.
|
|
2387
|
+
|
|
2388
|
+
- SDK automatically reconnects to the correct region, but it's advised to pass the correct region of your license explicitly to the `init` function. `dal` is the default.
|
|
2389
|
+
|
|
2390
|
+
- Users of type `"agent"` got a `jobTitle` property.
|
|
2391
|
+
|
|
2392
|
+
- Events of type `"file"` got a `name` property.
|
|
2393
|
+
|
|
2394
|
+
- New types of rich message buttons have been added and some of them have additional properties. Buttons of type `"webview"` come with a `webviewHeight` and buttons of type `"url"` come with a `target`.
|
|
2395
|
+
|
|
2396
|
+
- `connected` event payload has a new `availability` property.
|
|
2397
|
+
|
|
2398
|
+
- You can send custom system message events using `sendEvent`.
|
|
2399
|
+
|
|
2400
|
+
## [v2.0.0-alpha.0] - 2018-08-17
|
|
2401
|
+
|
|
2402
|
+
Initial alpha release.
|