@livechat/customer-sdk 4.0.1 → 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 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/1520/125).
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
 
@@ -89,6 +89,11 @@ Other optional configuration parameters are also available:
89
89
  | redirectUri | string | | Optional; should only be used inside ReactNative, this is the URI which your webview is redirected to after authorization. |
90
90
  | 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. |
91
91
  | 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. |
92
+ | page | object | | Optional; customer page information. |
93
+ | page.url | string | | Optional; customer page url. |
94
+ | page.title | string | | Optional; customer page title. |
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. |
92
97
 
93
98
  CustomerData:
94
99
 
@@ -363,7 +368,7 @@ Starts the connection process to our servers. It is needed when:
363
368
 
364
369
  ```js
365
370
  const customerSDK = CustomerSDK.init({
366
- licenseId: LICENSE_ID,
371
+ organizationId: ORGANIZATION_ID,
367
372
  clientId: CLIENT_ID,
368
373
  autoConnect: false,
369
374
  })
@@ -677,44 +682,6 @@ Returned value:
677
682
  | form.id | string | |
678
683
  | form.fields | object[] | |
679
684
 
680
- ## getPredictedAgent
681
-
682
- ```js
683
- customerSDK
684
- .getPredictedAgent({
685
- groupId: 0,
686
- })
687
- .then(agent => {
688
- console.log(agent)
689
- })
690
- .catch(error => {
691
- console.log(error)
692
- })
693
- ```
694
-
695
- Parameters:
696
-
697
- | parameters | type | description |
698
- | ---------- | ------ | ----------- |
699
- | groupId | number | Optional |
700
-
701
- Returned value:
702
-
703
- | properties | type | description |
704
- | -------------- | ------- | ------------------------------------------------------------- |
705
- | agent | object | |
706
- | agent.id | string | |
707
- | agent.name | string | |
708
- | agent.jobTitle | string | |
709
- | agent.type | 'agent' | |
710
- | agent.isBot | boolean | |
711
- | queue | boolean | True when the current group has reached concurrent chat limit |
712
-
713
- ### Errors
714
-
715
- - `GROUP_OFFLINE` - the requested group is offline, and it was not possible to return a predicted Agent for it.
716
- - `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.
717
-
718
685
  ## getUrlInfo
719
686
 
720
687
  It returns the info on a given URL.
@@ -966,6 +933,49 @@ Returned value:
966
933
 
967
934
  - `MISSING_CHAT_THREAD` - the targeted chat cannot be rated because it has no threads.
968
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
+
969
979
  ## resumeChat
970
980
 
971
981
  Resumes an archived chat.
@@ -994,6 +1004,7 @@ Parameters:
994
1004
  | --------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
995
1005
  | data.active | boolean | Optional; defaults to `true` but can be used to create threads that are immediately inactive |
996
1006
  | data.continuous | boolean | Optional |
1007
+ | data.welcomeMessageId | string | Optional; ID of a previously received welcome message |
997
1008
  | data.chat.id | string | |
998
1009
  | data.chat.access | Access | Optional |
999
1010
  | data.chat.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
@@ -1071,6 +1082,31 @@ Parameters:
1071
1082
  | postback.id | string | | Postback button ID |
1072
1083
  | postback.toggled | boolean | true | Postback toggled |
1073
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
+
1074
1110
  ## setCustomerSessionFields
1075
1111
 
1076
1112
  Sends the request to set customer's session fields. They are available for the duration of the session.
@@ -1137,6 +1173,7 @@ Parameters:
1137
1173
  | ---------------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
1138
1174
  | active | boolean | Optional, defaults to `true` but can be used to create threads that are immediately inactive |
1139
1175
  | continuous | boolean | Optional |
1176
+ | welcomeMessageId | string | Optional; ID of a previously received welcome message |
1140
1177
  | chat.access | access | Optional |
1141
1178
  | chat.properties | object | Optional, [Default properties docs](https://developers.livechat.com/docs/messaging/references/default-properties) |
1142
1179
  | chat.thread.events | event[] | Optional; initial events that will immediately become a part of the created thread. |
@@ -1520,24 +1557,27 @@ Payload:
1520
1557
  | -------- | ------ |
1521
1558
  | id | string |
1522
1559
 
1523
- ## Customer page updated
1560
+ ## Customer identity changed
1524
1561
 
1525
- The Customer moved to another page, for example by following a link on your website.
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.
1526
1563
 
1527
1564
  ```js
1528
- customerSDK.on('customer_page_updated', payload => {
1529
- const { url, title, openedAt } = payload
1530
- console.log('customer_page_updated', { url, title, openedAt })
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
1531
1572
  })
1532
1573
  ```
1533
1574
 
1534
1575
  Payload:
1535
1576
 
1536
- | properties | type | |
1537
- | ---------- | ------ | ---------------------------------------------------- |
1538
- | url | string | URL of the Customer current website |
1539
- | title | string | Title of the Customer current website |
1540
- | 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 |
1541
1581
 
1542
1582
  ## Customer updated
1543
1583
 
@@ -1837,6 +1877,88 @@ Payload:
1837
1877
  | typingIndicator.authorId | string | User ID |
1838
1878
  | typingIndicator.isTyping | boolean | |
1839
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
+
1840
1962
  ## Queue position updated
1841
1963
 
1842
1964
  Informs that the queue position has been updated.
@@ -1954,17 +2076,18 @@ Informs that a user was removed from a chat.
1954
2076
 
1955
2077
  ```js
1956
2078
  customerSDK.on('user_removed_from_chat', payload => {
1957
- const { chatId, userId } = payload
1958
- console.log('user_removed_from_chat', { chatId, userId })
2079
+ const { chatId, userId, reason } = payload
2080
+ console.log('user_removed_from_chat', { chatId, userId, reason })
1959
2081
  })
1960
2082
  ```
1961
2083
 
1962
2084
  Payload:
1963
2085
 
1964
- | properties | type | description |
1965
- | ---------- | ------ | ----------- |
1966
- | chatId | string | Chat ID |
1967
- | 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' |
1968
2091
 
1969
2092
  # Disconnection reasons
1970
2093
 
@@ -2004,9 +2127,12 @@ This internally destroys the current instance of Customer SDK, so it won't be po
2004
2127
 
2005
2128
  ## Identity mismatch
2006
2129
 
2007
- The identity of the Customer has changed between reconnects. This might happen if cookies can't be persisted in the browser.
2130
+ Customer SDK handles identity changes gracefully by:
2008
2131
 
2009
- This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
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
2010
2136
 
2011
2137
  ## Inactivity timeout
2012
2138
 
@@ -2130,7 +2256,37 @@ customerSDK.on('disconnected', ({ reason }) => {
2130
2256
 
2131
2257
  # Changelog
2132
2258
 
2133
- ## [v4.0.0] - 2023-09-19
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
+
2283
+ ## [v4.0.2] - 2023-11-02
2284
+
2285
+ ### Added
2286
+
2287
+ - Extend init function types with page and referrer.
2288
+
2289
+ ## [v4.0.1] - 2023-09-19
2134
2290
 
2135
2291
  ### Added
2136
2292