@livechat/customer-sdk 4.0.2 → 5.0.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 +204 -58
- package/dist/customer-sdk.cjs.js +1460 -1206
- package/dist/customer-sdk.cjs.native.js +1470 -1216
- package/dist/customer-sdk.esm.js +1457 -1202
- package/dist/customer-sdk.js +2079 -1820
- package/dist/customer-sdk.min.js +1 -1
- package/package.json +15 -17
- package/types/actions.d.ts +27 -11
- 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 +38 -14
- package/types/sendCustomerActions.d.ts +17 -0
- package/types/sendGreetingButtonClicked.d.ts +13 -0
- package/types/serverFrameParser.d.ts +45 -12
- 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. |
|
|
@@ -1524,24 +1557,27 @@ Payload:
|
|
|
1524
1557
|
| -------- | ------ |
|
|
1525
1558
|
| id | string |
|
|
1526
1559
|
|
|
1527
|
-
## Customer
|
|
1560
|
+
## Customer identity changed
|
|
1528
1561
|
|
|
1529
|
-
|
|
1562
|
+
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
1563
|
|
|
1531
1564
|
```js
|
|
1532
|
-
customerSDK.on('
|
|
1533
|
-
|
|
1534
|
-
|
|
1565
|
+
customerSDK.on('identity_changed', ({ previousId, newId }) => {
|
|
1566
|
+
console.log('Customer identity changed', {
|
|
1567
|
+
from: previousId,
|
|
1568
|
+
to: newId,
|
|
1569
|
+
})
|
|
1570
|
+
// Clear any application-specific cached data
|
|
1571
|
+
// tied to the previous customer identity
|
|
1535
1572
|
})
|
|
1536
1573
|
```
|
|
1537
1574
|
|
|
1538
1575
|
Payload:
|
|
1539
1576
|
|
|
1540
|
-
| properties | type |
|
|
1541
|
-
| ---------- | ------ |
|
|
1542
|
-
|
|
|
1543
|
-
|
|
|
1544
|
-
| openedAt | string | Date of the last update in RFC 3339 date-time format |
|
|
1577
|
+
| properties | type | description |
|
|
1578
|
+
| ---------- | ------ | ------------------------ |
|
|
1579
|
+
| previousId | string | The previous customer ID |
|
|
1580
|
+
| newId | string | The new customer ID |
|
|
1545
1581
|
|
|
1546
1582
|
## Customer updated
|
|
1547
1583
|
|
|
@@ -1841,6 +1877,88 @@ Payload:
|
|
|
1841
1877
|
| typingIndicator.authorId | string | User ID |
|
|
1842
1878
|
| typingIndicator.isTyping | boolean | |
|
|
1843
1879
|
|
|
1880
|
+
## Incoming thinking indicator
|
|
1881
|
+
|
|
1882
|
+
Informs that an AI agent is currently thinking or processing a request.
|
|
1883
|
+
The push payload contains information about the thinking state including optional custom title and description.
|
|
1884
|
+
|
|
1885
|
+
```js
|
|
1886
|
+
customerSDK.on('incoming_thinking_indicator', payload => {
|
|
1887
|
+
console.log(`Agent ${payload.authorId} is thinking in chat ${payload.chatId}`)
|
|
1888
|
+
|
|
1889
|
+
if (payload.title) {
|
|
1890
|
+
console.log(`Thinking title: ${payload.title}`)
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
if (payload.description) {
|
|
1894
|
+
console.log(`Thinking description: ${payload.description}`)
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
if (payload.customId) {
|
|
1898
|
+
console.log(`Custom ID: ${payload.customId}`)
|
|
1899
|
+
}
|
|
1900
|
+
})
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
Payload:
|
|
1904
|
+
|
|
1905
|
+
| properties | type | description |
|
|
1906
|
+
| ----------- | ------ | ----------------------------------------------------------- |
|
|
1907
|
+
| chatId | string | Chat ID |
|
|
1908
|
+
| threadId | string | Thread ID |
|
|
1909
|
+
| authorId | string | Agent ID who is thinking |
|
|
1910
|
+
| sentAt | string | ISO timestamp when the thinking indicator was sent |
|
|
1911
|
+
| customId | string | Optional. Custom identifier for dismissing this indicator |
|
|
1912
|
+
| title | string | Optional. Custom thinking title (defaults to "Thinking...") |
|
|
1913
|
+
| description | string | Optional. Additional description text |
|
|
1914
|
+
|
|
1915
|
+
## Incoming welcome message
|
|
1916
|
+
|
|
1917
|
+
Informs about a welcome message received in response to [`requestWelcomeMessage`](#requestwelcomemessage).
|
|
1918
|
+
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.
|
|
1919
|
+
|
|
1920
|
+
```js
|
|
1921
|
+
customerSDK.on('incoming_welcome_message', payload => {
|
|
1922
|
+
const { id, event } = payload
|
|
1923
|
+
console.log('incoming_welcome_message', { id, event })
|
|
1924
|
+
})
|
|
1925
|
+
```
|
|
1926
|
+
|
|
1927
|
+
Payload:
|
|
1928
|
+
|
|
1929
|
+
| properties | type | description |
|
|
1930
|
+
| ---------- | ------ | ----------------------------- |
|
|
1931
|
+
| id | string | Welcome message ID |
|
|
1932
|
+
| event | object | Message or rich message event |
|
|
1933
|
+
|
|
1934
|
+
## Incoming event preview
|
|
1935
|
+
|
|
1936
|
+
Informs about an event preview before it's officially sent to the chat.
|
|
1937
|
+
This allows clients to display a preview of the event content.
|
|
1938
|
+
Only text events are supported for preview.
|
|
1939
|
+
|
|
1940
|
+
```js
|
|
1941
|
+
customerSDK.on('incoming_event_preview', payload => {
|
|
1942
|
+
console.log(
|
|
1943
|
+
`Event preview in chat ${payload.chatId}, thread ${payload.threadId}`,
|
|
1944
|
+
)
|
|
1945
|
+
|
|
1946
|
+
if (payload.event && payload.event.type === 'message') {
|
|
1947
|
+
console.log(`Preview text: ${payload.event.text}`)
|
|
1948
|
+
}
|
|
1949
|
+
})
|
|
1950
|
+
```
|
|
1951
|
+
|
|
1952
|
+
Payload:
|
|
1953
|
+
|
|
1954
|
+
| properties | type | description |
|
|
1955
|
+
| ---------- | ------ | --------------------------------------------- |
|
|
1956
|
+
| chatId | string | Chat ID |
|
|
1957
|
+
| threadId | string | Thread ID |
|
|
1958
|
+
| event | object | Event object (only text events are supported) |
|
|
1959
|
+
| event.type | string | Event type |
|
|
1960
|
+
| event.text | string | Event text content (for message type events) |
|
|
1961
|
+
|
|
1844
1962
|
## Queue position updated
|
|
1845
1963
|
|
|
1846
1964
|
Informs that the queue position has been updated.
|
|
@@ -1958,17 +2076,18 @@ Informs that a user was removed from a chat.
|
|
|
1958
2076
|
|
|
1959
2077
|
```js
|
|
1960
2078
|
customerSDK.on('user_removed_from_chat', payload => {
|
|
1961
|
-
const { chatId, userId } = payload
|
|
1962
|
-
console.log('user_removed_from_chat', { chatId, userId })
|
|
2079
|
+
const { chatId, userId, reason } = payload
|
|
2080
|
+
console.log('user_removed_from_chat', { chatId, userId, reason })
|
|
1963
2081
|
})
|
|
1964
2082
|
```
|
|
1965
2083
|
|
|
1966
2084
|
Payload:
|
|
1967
2085
|
|
|
1968
|
-
| properties | type | description
|
|
1969
|
-
| ---------- | ------ |
|
|
1970
|
-
| chatId | string | Chat ID
|
|
1971
|
-
| userId | string | User ID
|
|
2086
|
+
| properties | type | description |
|
|
2087
|
+
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
2088
|
+
| chatId | string | Chat ID |
|
|
2089
|
+
| userId | string | User ID |
|
|
2090
|
+
| reason | string | Reason why user was removed, one of: 'disconnected', 'signed_out', 'remotely_signed_out', 'deleted', 'chat_deactivated', 'manual', 'inactive', 'other' |
|
|
1972
2091
|
|
|
1973
2092
|
# Disconnection reasons
|
|
1974
2093
|
|
|
@@ -2008,9 +2127,12 @@ This internally destroys the current instance of Customer SDK, so it won't be po
|
|
|
2008
2127
|
|
|
2009
2128
|
## Identity mismatch
|
|
2010
2129
|
|
|
2011
|
-
|
|
2130
|
+
Customer SDK handles identity changes gracefully by:
|
|
2012
2131
|
|
|
2013
|
-
|
|
2132
|
+
- Automatically switching to the new customer identity
|
|
2133
|
+
- Clearing sensitive session data (chats, cached user data) for security
|
|
2134
|
+
- Maintaining SDK functionality without crashes
|
|
2135
|
+
- Emitting an `identity_changed` event for developer awareness
|
|
2014
2136
|
|
|
2015
2137
|
## Inactivity timeout
|
|
2016
2138
|
|
|
@@ -2134,6 +2256,30 @@ customerSDK.on('disconnected', ({ reason }) => {
|
|
|
2134
2256
|
|
|
2135
2257
|
# Changelog
|
|
2136
2258
|
|
|
2259
|
+
## [v5.0.0] - 2026-05-12
|
|
2260
|
+
|
|
2261
|
+
### Added
|
|
2262
|
+
|
|
2263
|
+
- New `reason` field to `user_removed_from_chat` event, indicating why the user was removed.
|
|
2264
|
+
- New `sendGreetingButtonClicked` method for tracking greeting button clicks.
|
|
2265
|
+
- New `requestWelcomeMessage` method for requesting welcome messages.
|
|
2266
|
+
- Support for `incoming_thinking_indicator` push event.
|
|
2267
|
+
- Support for `incoming_event_preview` push event.
|
|
2268
|
+
- Support for `incoming_welcome_message` push event.
|
|
2269
|
+
- Support for `identity_changed` event.
|
|
2270
|
+
- Support for `ecommerce` template in rich messages.
|
|
2271
|
+
- Optional `formType` field on parsed `form` and `filled_form` events, representing the custom form type assigned by the server.
|
|
2272
|
+
- Support for optional `tabId` configuration parameter, sent as `tab_id` in the login payload.
|
|
2273
|
+
|
|
2274
|
+
### Changed
|
|
2275
|
+
|
|
2276
|
+
- Switched to using Customer API 3.6.
|
|
2277
|
+
|
|
2278
|
+
### Removed
|
|
2279
|
+
|
|
2280
|
+
- Support for `customer_page_updated` push.
|
|
2281
|
+
- Support for `get_predicted_agent` request.
|
|
2282
|
+
|
|
2137
2283
|
## [v4.0.2] - 2023-11-02
|
|
2138
2284
|
|
|
2139
2285
|
### Added
|