@livechat/customer-sdk 4.0.2 → 5.0.1
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 +212 -58
- package/dist/customer-sdk.cjs.js +1473 -1206
- package/dist/customer-sdk.cjs.native.js +1482 -1215
- package/dist/customer-sdk.esm.js +1475 -1207
- package/dist/customer-sdk.js +2088 -1816
- package/dist/customer-sdk.min.js +1 -1
- package/package.json +15 -17
- package/types/actions.d.ts +40 -24
- package/types/clientDataParsers.d.ts +4 -1
- package/types/constants/clientErrorCodes.d.ts +0 -1
- package/types/constants/organizationIds.d.ts +1 -1
- package/types/constants/reduxActions.d.ts +2 -0
- package/types/constants/serverPushActions.d.ts +3 -1
- package/types/constants/serverRequestActions.d.ts +3 -1
- package/types/graylog/index.d.ts +2 -2
- package/types/index.d.ts +27 -9
- package/types/reducer.d.ts +111 -87
- package/types/sendCustomerActions.d.ts +17 -0
- package/types/sendGreetingButtonClicked.d.ts +13 -0
- package/types/serverFrameParser.d.ts +49 -15
- package/types/sideEffects/checkGoals.d.ts +1 -1
- package/types/sideEffects/index.d.ts +4 -3
- package/types/sideStorage.d.ts +3 -2
- package/types/socketClient.d.ts +1 -1
- package/types/socketListener.d.ts +3 -3
- package/types/types/actions.d.ts +13 -3
- package/types/types/clientEntities.d.ts +77 -4
- package/types/types/frames.d.ts +59 -24
- package/types/types/serverEntities.d.ts +78 -3
- package/types/types/state.d.ts +2 -0
- package/types/sendTicketForm.d.ts +0 -14
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ customerSDK.auth.getToken().then(token => {
|
|
|
33
33
|
|
|
34
34
|
## Questions
|
|
35
35
|
|
|
36
|
-
If you have any questions, you can start a chat with our [24/7 Support](https://direct.lc.chat/
|
|
36
|
+
If you have any questions, you can start a chat with our [24/7 Support](https://direct.lc.chat/19196658/11).
|
|
37
37
|
|
|
38
38
|
# How to start
|
|
39
39
|
|
|
@@ -93,6 +93,7 @@ Other optional configuration parameters are also available:
|
|
|
93
93
|
| page.url | string | | Optional; customer page url. |
|
|
94
94
|
| page.title | string | | Optional; customer page title. |
|
|
95
95
|
| referrer | string | | Optional; page referrer |
|
|
96
|
+
| tabId | string | | Optional; an identifier for the browser tab. When provided, it is sent as `tab_id` in the login payload. Useful for distinguishing multiple tabs from the same customer. |
|
|
96
97
|
|
|
97
98
|
CustomerData:
|
|
98
99
|
|
|
@@ -367,7 +368,7 @@ Starts the connection process to our servers. It is needed when:
|
|
|
367
368
|
|
|
368
369
|
```js
|
|
369
370
|
const customerSDK = CustomerSDK.init({
|
|
370
|
-
|
|
371
|
+
organizationId: ORGANIZATION_ID,
|
|
371
372
|
clientId: CLIENT_ID,
|
|
372
373
|
autoConnect: false,
|
|
373
374
|
})
|
|
@@ -681,44 +682,6 @@ Returned value:
|
|
|
681
682
|
| form.id | string | |
|
|
682
683
|
| form.fields | object[] | |
|
|
683
684
|
|
|
684
|
-
## getPredictedAgent
|
|
685
|
-
|
|
686
|
-
```js
|
|
687
|
-
customerSDK
|
|
688
|
-
.getPredictedAgent({
|
|
689
|
-
groupId: 0,
|
|
690
|
-
})
|
|
691
|
-
.then(agent => {
|
|
692
|
-
console.log(agent)
|
|
693
|
-
})
|
|
694
|
-
.catch(error => {
|
|
695
|
-
console.log(error)
|
|
696
|
-
})
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
Parameters:
|
|
700
|
-
|
|
701
|
-
| parameters | type | description |
|
|
702
|
-
| ---------- | ------ | ----------- |
|
|
703
|
-
| groupId | number | Optional |
|
|
704
|
-
|
|
705
|
-
Returned value:
|
|
706
|
-
|
|
707
|
-
| properties | type | description |
|
|
708
|
-
| -------------- | ------- | ------------------------------------------------------------- |
|
|
709
|
-
| agent | object | |
|
|
710
|
-
| agent.id | string | |
|
|
711
|
-
| agent.name | string | |
|
|
712
|
-
| agent.jobTitle | string | |
|
|
713
|
-
| agent.type | 'agent' | |
|
|
714
|
-
| agent.isBot | boolean | |
|
|
715
|
-
| queue | boolean | True when the current group has reached concurrent chat limit |
|
|
716
|
-
|
|
717
|
-
### Errors
|
|
718
|
-
|
|
719
|
-
- `GROUP_OFFLINE` - the requested group is offline, and it was not possible to return a predicted Agent for it.
|
|
720
|
-
- `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.
|
|
721
|
-
|
|
722
685
|
## getUrlInfo
|
|
723
686
|
|
|
724
687
|
It returns the info on a given URL.
|
|
@@ -970,6 +933,49 @@ Returned value:
|
|
|
970
933
|
|
|
971
934
|
- `MISSING_CHAT_THREAD` - the targeted chat cannot be rated because it has no threads.
|
|
972
935
|
|
|
936
|
+
## requestWelcomeMessage
|
|
937
|
+
|
|
938
|
+
Requests a welcome message for the current customer. The welcome message is returned via the [`incoming_welcome_message`](#incoming_welcome_message) event.
|
|
939
|
+
|
|
940
|
+
```js
|
|
941
|
+
customerSDK
|
|
942
|
+
.requestWelcomeMessage({
|
|
943
|
+
id: 'previous-welcome-message-id',
|
|
944
|
+
})
|
|
945
|
+
.then(response => {
|
|
946
|
+
console.log(response)
|
|
947
|
+
})
|
|
948
|
+
.catch(error => {
|
|
949
|
+
console.log(error)
|
|
950
|
+
})
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
Parameters:
|
|
954
|
+
|
|
955
|
+
| parameters | type | description |
|
|
956
|
+
| ---------- | ------ | ----------------------------------------------------- |
|
|
957
|
+
| id | string | Optional; ID of a previously received welcome message |
|
|
958
|
+
|
|
959
|
+
Returned value:
|
|
960
|
+
|
|
961
|
+
| properties | type | description |
|
|
962
|
+
| ----------------------- | ------- | ------------------------------------------------------------- |
|
|
963
|
+
| id | string | Welcome message ID |
|
|
964
|
+
| predictedAgent | object | Predicted agent object |
|
|
965
|
+
| predictedAgent.id | string | Predicted agent ID |
|
|
966
|
+
| predictedAgent.avatar | string | Predicted agent avatar URL |
|
|
967
|
+
| predictedAgent.name | string | Predicted agent name |
|
|
968
|
+
| predictedAgent.jobTitle | string | Predicted agent job title |
|
|
969
|
+
| predictedAgent.type | string | Predicted agent type |
|
|
970
|
+
| predictedAgent.botType | string | Predicted agent bot type: 'chatbot' or 'ai_agent' |
|
|
971
|
+
| predictedAgent.isBot | boolean | Predicted agent is bot flag |
|
|
972
|
+
| queue | boolean | True when the current group has reached concurrent chat limit |
|
|
973
|
+
|
|
974
|
+
### Errors
|
|
975
|
+
|
|
976
|
+
- `GROUP_OFFLINE` - the requested group is offline, and it was not possible to return a predicted Agent for it.
|
|
977
|
+
- `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.
|
|
978
|
+
|
|
973
979
|
## resumeChat
|
|
974
980
|
|
|
975
981
|
Resumes an archived chat.
|
|
@@ -998,6 +1004,7 @@ Parameters:
|
|
|
998
1004
|
| --------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
999
1005
|
| data.active | boolean | Optional; defaults to `true` but can be used to create threads that are immediately inactive |
|
|
1000
1006
|
| data.continuous | boolean | Optional |
|
|
1007
|
+
| data.welcomeMessageId | string | Optional; ID of a previously received welcome message |
|
|
1001
1008
|
| data.chat.id | string | |
|
|
1002
1009
|
| data.chat.access | Access | Optional |
|
|
1003
1010
|
| data.chat.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
@@ -1075,6 +1082,31 @@ Parameters:
|
|
|
1075
1082
|
| postback.id | string | | Postback button ID |
|
|
1076
1083
|
| postback.toggled | boolean | true | Postback toggled |
|
|
1077
1084
|
|
|
1085
|
+
## sendGreetingButtonClicked
|
|
1086
|
+
|
|
1087
|
+
Sends information to the server about a Customer's interaction with a greeting button. This is used for tracking button clicks in greetings that have a `buttonId` property.
|
|
1088
|
+
|
|
1089
|
+
```js
|
|
1090
|
+
customerSDK
|
|
1091
|
+
.sendGreetingButtonClicked({
|
|
1092
|
+
greetingUniqueId: 'Q10X0W041P',
|
|
1093
|
+
buttonId: '20ff0b3f-fbed-49f4-b13f-788c9ec66f03',
|
|
1094
|
+
})
|
|
1095
|
+
.then(() => {
|
|
1096
|
+
console.log('success')
|
|
1097
|
+
})
|
|
1098
|
+
.catch(error => {
|
|
1099
|
+
console.log(error)
|
|
1100
|
+
})
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
Parameters:
|
|
1104
|
+
|
|
1105
|
+
| parameters | type | description |
|
|
1106
|
+
| ---------------- | ------ | --------------------------------------------------------- |
|
|
1107
|
+
| greetingUniqueId | string | Unique ID of the greeting received in `incoming_greeting` |
|
|
1108
|
+
| buttonId | string | ID of the clicked button |
|
|
1109
|
+
|
|
1078
1110
|
## setCustomerSessionFields
|
|
1079
1111
|
|
|
1080
1112
|
Sends the request to set customer's session fields. They are available for the duration of the session.
|
|
@@ -1141,6 +1173,7 @@ Parameters:
|
|
|
1141
1173
|
| ---------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
1142
1174
|
| active | boolean | Optional, defaults to `true` but can be used to create threads that are immediately inactive |
|
|
1143
1175
|
| continuous | boolean | Optional |
|
|
1176
|
+
| welcomeMessageId | string | Optional; ID of a previously received welcome message |
|
|
1144
1177
|
| chat.access | access | Optional |
|
|
1145
1178
|
| chat.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
|
|
1146
1179
|
| chat.thread.events | event[] | Optional; initial events that will immediately become a part of the created thread. |
|
|
@@ -1209,6 +1242,8 @@ Parameters:
|
|
|
1209
1242
|
|
|
1210
1243
|
Updates information about the Customer page using the provided page object.
|
|
1211
1244
|
|
|
1245
|
+
If the page URL change triggers a group reassignment via routing rules, the [`availability_updated`](#availability_updated) event will be emitted with the new group's availability status.
|
|
1246
|
+
|
|
1212
1247
|
```js
|
|
1213
1248
|
const page = {
|
|
1214
1249
|
url: 'https://developers.livechat.com/',
|
|
@@ -1524,24 +1559,27 @@ Payload:
|
|
|
1524
1559
|
| -------- | ------ |
|
|
1525
1560
|
| id | string |
|
|
1526
1561
|
|
|
1527
|
-
## Customer
|
|
1562
|
+
## Customer identity changed
|
|
1528
1563
|
|
|
1529
|
-
|
|
1564
|
+
Informs that the customer identity has changed, typically due to browser privacy features blocking authentication cookies. The SDK handles this gracefully by clearing sensitive session data and switching to the new identity without crashing.
|
|
1530
1565
|
|
|
1531
1566
|
```js
|
|
1532
|
-
customerSDK.on('
|
|
1533
|
-
|
|
1534
|
-
|
|
1567
|
+
customerSDK.on('identity_changed', ({ previousId, newId }) => {
|
|
1568
|
+
console.log('Customer identity changed', {
|
|
1569
|
+
from: previousId,
|
|
1570
|
+
to: newId,
|
|
1571
|
+
})
|
|
1572
|
+
// Clear any application-specific cached data
|
|
1573
|
+
// tied to the previous customer identity
|
|
1535
1574
|
})
|
|
1536
1575
|
```
|
|
1537
1576
|
|
|
1538
1577
|
Payload:
|
|
1539
1578
|
|
|
1540
|
-
| properties | type |
|
|
1541
|
-
| ---------- | ------ |
|
|
1542
|
-
|
|
|
1543
|
-
|
|
|
1544
|
-
| openedAt | string | Date of the last update in RFC 3339 date-time format |
|
|
1579
|
+
| properties | type | description |
|
|
1580
|
+
| ---------- | ------ | ------------------------ |
|
|
1581
|
+
| previousId | string | The previous customer ID |
|
|
1582
|
+
| newId | string | The new customer ID |
|
|
1545
1583
|
|
|
1546
1584
|
## Customer updated
|
|
1547
1585
|
|
|
@@ -1841,6 +1879,88 @@ Payload:
|
|
|
1841
1879
|
| typingIndicator.authorId | string | User ID |
|
|
1842
1880
|
| typingIndicator.isTyping | boolean | |
|
|
1843
1881
|
|
|
1882
|
+
## Incoming thinking indicator
|
|
1883
|
+
|
|
1884
|
+
Informs that an AI agent is currently thinking or processing a request.
|
|
1885
|
+
The push payload contains information about the thinking state including optional custom title and description.
|
|
1886
|
+
|
|
1887
|
+
```js
|
|
1888
|
+
customerSDK.on('incoming_thinking_indicator', payload => {
|
|
1889
|
+
console.log(`Agent ${payload.authorId} is thinking in chat ${payload.chatId}`)
|
|
1890
|
+
|
|
1891
|
+
if (payload.title) {
|
|
1892
|
+
console.log(`Thinking title: ${payload.title}`)
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
if (payload.description) {
|
|
1896
|
+
console.log(`Thinking description: ${payload.description}`)
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
if (payload.customId) {
|
|
1900
|
+
console.log(`Custom ID: ${payload.customId}`)
|
|
1901
|
+
}
|
|
1902
|
+
})
|
|
1903
|
+
```
|
|
1904
|
+
|
|
1905
|
+
Payload:
|
|
1906
|
+
|
|
1907
|
+
| properties | type | description |
|
|
1908
|
+
| ----------- | ------ | ----------------------------------------------------------- |
|
|
1909
|
+
| chatId | string | Chat ID |
|
|
1910
|
+
| threadId | string | Thread ID |
|
|
1911
|
+
| authorId | string | Agent ID who is thinking |
|
|
1912
|
+
| sentAt | string | ISO timestamp when the thinking indicator was sent |
|
|
1913
|
+
| customId | string | Optional. Custom identifier for dismissing this indicator |
|
|
1914
|
+
| title | string | Optional. Custom thinking title (defaults to "Thinking...") |
|
|
1915
|
+
| description | string | Optional. Additional description text |
|
|
1916
|
+
|
|
1917
|
+
## Incoming welcome message
|
|
1918
|
+
|
|
1919
|
+
Informs about a welcome message received in response to [`requestWelcomeMessage`](#requestwelcomemessage).
|
|
1920
|
+
If you want to include the welcome message in the chat, you can use the `welcome_message_id` parameter in the [`resumeChat`](#resumechat) or [`startChat`](#startchat) method.
|
|
1921
|
+
|
|
1922
|
+
```js
|
|
1923
|
+
customerSDK.on('incoming_welcome_message', payload => {
|
|
1924
|
+
const { id, event } = payload
|
|
1925
|
+
console.log('incoming_welcome_message', { id, event })
|
|
1926
|
+
})
|
|
1927
|
+
```
|
|
1928
|
+
|
|
1929
|
+
Payload:
|
|
1930
|
+
|
|
1931
|
+
| properties | type | description |
|
|
1932
|
+
| ---------- | ------ | ----------------------------- |
|
|
1933
|
+
| id | string | Welcome message ID |
|
|
1934
|
+
| event | object | Message or rich message event |
|
|
1935
|
+
|
|
1936
|
+
## Incoming event preview
|
|
1937
|
+
|
|
1938
|
+
Informs about an event preview before it's officially sent to the chat.
|
|
1939
|
+
This allows clients to display a preview of the event content.
|
|
1940
|
+
Only text events are supported for preview.
|
|
1941
|
+
|
|
1942
|
+
```js
|
|
1943
|
+
customerSDK.on('incoming_event_preview', payload => {
|
|
1944
|
+
console.log(
|
|
1945
|
+
`Event preview in chat ${payload.chatId}, thread ${payload.threadId}`,
|
|
1946
|
+
)
|
|
1947
|
+
|
|
1948
|
+
if (payload.event && payload.event.type === 'message') {
|
|
1949
|
+
console.log(`Preview text: ${payload.event.text}`)
|
|
1950
|
+
}
|
|
1951
|
+
})
|
|
1952
|
+
```
|
|
1953
|
+
|
|
1954
|
+
Payload:
|
|
1955
|
+
|
|
1956
|
+
| properties | type | description |
|
|
1957
|
+
| ---------- | ------ | --------------------------------------------- |
|
|
1958
|
+
| chatId | string | Chat ID |
|
|
1959
|
+
| threadId | string | Thread ID |
|
|
1960
|
+
| event | object | Event object (only text events are supported) |
|
|
1961
|
+
| event.type | string | Event type |
|
|
1962
|
+
| event.text | string | Event text content (for message type events) |
|
|
1963
|
+
|
|
1844
1964
|
## Queue position updated
|
|
1845
1965
|
|
|
1846
1966
|
Informs that the queue position has been updated.
|
|
@@ -1958,17 +2078,18 @@ Informs that a user was removed from a chat.
|
|
|
1958
2078
|
|
|
1959
2079
|
```js
|
|
1960
2080
|
customerSDK.on('user_removed_from_chat', payload => {
|
|
1961
|
-
const { chatId, userId } = payload
|
|
1962
|
-
console.log('user_removed_from_chat', { chatId, userId })
|
|
2081
|
+
const { chatId, userId, reason } = payload
|
|
2082
|
+
console.log('user_removed_from_chat', { chatId, userId, reason })
|
|
1963
2083
|
})
|
|
1964
2084
|
```
|
|
1965
2085
|
|
|
1966
2086
|
Payload:
|
|
1967
2087
|
|
|
1968
|
-
| properties | type | description
|
|
1969
|
-
| ---------- | ------ |
|
|
1970
|
-
| chatId | string | Chat ID
|
|
1971
|
-
| userId | string | User ID
|
|
2088
|
+
| properties | type | description |
|
|
2089
|
+
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
2090
|
+
| chatId | string | Chat ID |
|
|
2091
|
+
| userId | string | User ID |
|
|
2092
|
+
| reason | string | Reason why user was removed, one of: 'disconnected', 'signed_out', 'remotely_signed_out', 'deleted', 'chat_deactivated', 'manual', 'inactive', 'other' |
|
|
1972
2093
|
|
|
1973
2094
|
# Disconnection reasons
|
|
1974
2095
|
|
|
@@ -2008,9 +2129,12 @@ This internally destroys the current instance of Customer SDK, so it won't be po
|
|
|
2008
2129
|
|
|
2009
2130
|
## Identity mismatch
|
|
2010
2131
|
|
|
2011
|
-
|
|
2132
|
+
Customer SDK handles identity changes gracefully by:
|
|
2012
2133
|
|
|
2013
|
-
|
|
2134
|
+
- Automatically switching to the new customer identity
|
|
2135
|
+
- Clearing sensitive session data (chats, cached user data) for security
|
|
2136
|
+
- Maintaining SDK functionality without crashes
|
|
2137
|
+
- Emitting an `identity_changed` event for developer awareness
|
|
2014
2138
|
|
|
2015
2139
|
## Inactivity timeout
|
|
2016
2140
|
|
|
@@ -2134,6 +2258,36 @@ customerSDK.on('disconnected', ({ reason }) => {
|
|
|
2134
2258
|
|
|
2135
2259
|
# Changelog
|
|
2136
2260
|
|
|
2261
|
+
## [v5.0.1] - 2026-07-16
|
|
2262
|
+
|
|
2263
|
+
### Fixed
|
|
2264
|
+
|
|
2265
|
+
- Fixed missing environment variable injection in the unpkg build.
|
|
2266
|
+
|
|
2267
|
+
## [v5.0.0] - 2026-05-12
|
|
2268
|
+
|
|
2269
|
+
### Added
|
|
2270
|
+
|
|
2271
|
+
- New `reason` field to `user_removed_from_chat` event, indicating why the user was removed.
|
|
2272
|
+
- New `sendGreetingButtonClicked` method for tracking greeting button clicks.
|
|
2273
|
+
- New `requestWelcomeMessage` method for requesting welcome messages.
|
|
2274
|
+
- Support for `incoming_thinking_indicator` push event.
|
|
2275
|
+
- Support for `incoming_event_preview` push event.
|
|
2276
|
+
- Support for `incoming_welcome_message` push event.
|
|
2277
|
+
- Support for `identity_changed` event.
|
|
2278
|
+
- Support for `ecommerce` template in rich messages.
|
|
2279
|
+
- Optional `formType` field on parsed `form` and `filled_form` events, representing the custom form type assigned by the server.
|
|
2280
|
+
- Support for optional `tabId` configuration parameter, sent as `tab_id` in the login payload.
|
|
2281
|
+
|
|
2282
|
+
### Changed
|
|
2283
|
+
|
|
2284
|
+
- Switched to using Customer API 3.6.
|
|
2285
|
+
|
|
2286
|
+
### Removed
|
|
2287
|
+
|
|
2288
|
+
- Support for `customer_page_updated` push.
|
|
2289
|
+
- Support for `get_predicted_agent` request.
|
|
2290
|
+
|
|
2137
2291
|
## [v4.0.2] - 2023-11-02
|
|
2138
2292
|
|
|
2139
2293
|
### Added
|