# Changelog for Messaging Platform SDK #
# 1.19.2
<sub>Publish Date: 15th of January 2026</sub>
Changes:

* No functional changes. Version bump due to a publishing issue in the previous release.

# 1.19.1
<sub>Publish Date: 24th of November 2025</sub>
Changes:

* Security: Updated vulnerable dependencies via `npm audit fix`. No functional changes to the SDK.

# 1.19.0
<sub>Publish Date: 14th of July 2025</sub>

Changes:
* *Improve resilience by retrying on 429 (Too many requests) errors*: The SDK now includes a retry when a 429 error is 
  returned by the backend for WebSocket or REST requests. The mechanism uses a scheduled backoff strategy with the 
  following intervals between attempts: 1, 1, 1, 5, 5, 5, 10, 10, 10, 60, 120, 240 seconds, for a total  of 12 attempts.
* *Increase fetch rate for conversation not in cache*: When a conversation is not in the cache, it is being fetched from 
  the REST API. Previous to this release, a new token was generated for each conversation. This change reuses the token 
  created for the WebSocket connection, bypassing the token creation.
* *Improve logging for unknown subscriptions*: When notifications are received for a subscription unknown to the SDK,
  an error is emitted. Before this change, the error just contained the subscription id. Now, the whole event is added.

Bug fixes:
* Messages are not dropped when a sub-dialog closes and the conversation stays open. For example, after a CoBrowse session, 
  callbacks on the conversation will receive further messages. Previous to this fix, these messages were ignored. 

# 1.18.1

<sub>Publish Date: 12th of May 2025</sub>

Changes:

* *Set agents offline upon disconnect*: Added configuration flag `setAgentOfflineOnDisconnect` to control whether to 
  keep the agent ONLINE upon disconnect or not.

Bug fixes:

* Added CSDS support for QA accounts starting with cc.
* Do not emit an error under reconnect when OAuth 2 credentials are used.
* Updated browserify dependencies to mitigate [CVE-2024-48948](https://www.cve.org/CVERecord?id=CVE-2024-48948)

# 1.18.0

<sub>Publish Date: 31st of March 2025</sub>

Changes:

* *Conversation Not in Cache*: The SDK now handles cases where a content event is received before the corresponding 
  conversation is present in the cache. This can occur because backend systems may send events out of order. In such 
  scenarios, the SDK will first wait one second for the conversation to arrive, and if it doesn’t, it will perform an 
  API call to fetch the conversation. An error is emitted if both strategies fail.
* *ChatState Event for Unknown Participant*: The SDK now handles cases where a chat state event is received for a 
  participant unknown to the SDK. If the participant was previously removed, a warning is emitted and the event is 
  ignored. If the chat state event arrives before the corresponding conversation update, the SDK waits one second for the
  update. If the participant is still unknown after that, an error is emitted.

# 1.17.1

<sub>Publish Date: 05th of February 2025</sub>

Bug Fixes:

* Properly check if there is a conversation callback set up before delete a conversation from the cache which could cause the bot to fail.

# 1.17.0

<sub>Publish Date: 31st of January 2025</sub>

Changes:

* *Combined conversation handling*: The SDK now streamlines conversation processing by coordinating events triggered 
  either when a `conversation` event occurs or when a `ring` is accepted. This ensures that each conversation is processed 
  only once. For more details, please refer to the [documentation](https://developers.liveperson.com/messaging-platform-sdk-overview.html#combined-conversation-handling).

Bug Fixes:

* *Queue requests on SDK reconnect*: When the SDK is reconnecting, requests were not queued before this change. Now, 
  requests are queued and sent once the connection is reestablished.
* *Client-Source header for REST API calls*: A Client-source header is added as a parameter when a REST requests are 
  made. Defaults to lp-messaging-sdk-{accountId}.

# 1.16.0

<sub>Publish Date: 16th of December 2024</sub>

Changes:

* *Add message event to error when conversation is not in cache*: If a message event arrived before the conversation change 
  event, the message event will not be emitted on the conversation because the conversation does not yet exist in the SDK. 
  This `conversation not found in cache` error now carries the raw `event` and can be processed. See
  [error-handling](https://developers.liveperson.com/messaging-platform-sdk-overview.html#error-handling).
* *Added example for responding to all messages on restart or disconnect*: See 
  [respond to all messages if there is a downtime or restart/reconnect](https://developers.liveperson.com/messaging-platform-sdk-examples.html#respond-to-all-messages-on-restart-or-disconnect-with-a-downtime)
* *Added third party bot example*: One of the most common use cases for the SDK is to create a bot that accepts 
  conversations and performs actions based on those conversations. A detailed example has been added to demonstrate 
  how this can be achieved. See the [third party bot](https://developers.liveperson.com/messaging-platform-sdk-examples.html#third-party-bot)
  example for more information.

Bug Fixes:

* *Emit error in dialog#queryMessages instead of throwing one*: The dialog allows you to query its messages from the 
  backend. However, if the corresponding conversation was already closed or removed, then an error was thrown which
  causes the SDK to stop. Instead of throwing the error, it is now emitted as error on the dialog, conversation and 
  corresponding connection.

# 1.15.0

<sub>Publish Date: 25th of July 2024</sub>

Changes:

* *Adding oAuth2 authentication support*: This release offers a new brand authentication mechanism using oAuth2. For more 
  information please refer to the documentation about 
  [different authentication mechanisms](https://developers.liveperson.com/messaging-platform-sdk-overview.html#different-authentication-mechanisms).

# 1.14.1

<sub>Publish Date: 4th of July 2024</sub>

Changes:

* *Brand authentication using agent session data*: This release offers a new brand authentication mechanism using agent
  session data. For more information please refer to the documentation about
  [brand authentication with existing bearer token](https://developers.liveperson.com/messaging-platform-sdk-overview.html#brand-authentication-with-existing-bearer-token).
* *Brand Authentication using TokenMaintainer*: Authentication information can now be shared between multiple brand  
  connections. For more information please refer to the documentation about
  [brand authentication using TokenMaintainer](https://developers.liveperson.com/messaging-platform-sdk-overview.html#brand-authentication-using-tokenmaintainer).
* *Emit warning instead of error when conversation is missing during delete*: When a delete notification is received for
  an already closed conversation, a warning is  emitted instead of an error. This change was made because it is possible
  for the conversation close event to be received before the last message.

# 1.14.0

<sub>Publish Date: 11th of June 2024</sub>

Changes:
* *Detailed subscription query documentation*: All possible [query properties](https://developers.liveperson.com/messaging-platform-sdk-overview.html#query-properties)
  are now explained and examples are provided.
* *Enhance get last consumer message example*: The example does not pause execution while waiting for a conversation.
  See [get last consumer message](https://developers.liveperson.com/messaging-platform-sdk-examples.html#get-last-consumer-message)

Bug Fixes:
* *No message subscription for closed conversations*: When a closed conversation is received on a consumer connection,
  there is no open dialog. The SDK will not subscribe to any message events of any closed conversations. This fixes, the
  error when a consumer closed a conversation and a step-up is performed on a new conversation.
* *Updated dependencies*: Updated dependencies to versions which stay compatible with node version 16.

# 1.13.0

<sub>Publish Date: 4th of April 2024</sub>

Changes:

* *Consumer authentication and step up*. This release changes how consumers can establish an authenticated connection. By 
  default, consumers connections are unauthenticated and sometimes anonymous. For certain actions a brand has to verify 
  the authenticity of a consumer. This verification can be done in two ways: Establish an authenticated connection or 
  step up an unauthenticated one. For both  of these cases a JSON Web Token is necessary. For more information please 
  refer to the documentation about
  [consumer auth flow](https://developers.liveperson.com/messaging-platform-sdk-overview.html#consumer-auth-flow) and
  [consumer step up](https://developers.liveperson.com/messaging-platform-sdk-overview.html#consumer-step-up). **Note**: 
  If you have been using authenticated connections before this change, you need to adapt your implementation. The changes 
  are explained in the consumer auth flow documentation.
* *Code examples*. Starting from this release [code examples](messaging-platform-sdk-examples.html) for brand and consumer
  use cases are documented.

Bug Fixes:
* *Transfers to agents are more robust*. When a conversation is transferred to a different agent, the agent id is always 
  sent in the following format `accountId.agentId`. 

# 1.12.13
<sub>Publish Date: 28th of February 2024</sub>

Bug Fixes:
* Fixing missing messageAudience for the latest message while calling the `queryMessages` method. Instead of
  `null` the correct audience of the message will be returned.
* Adding content-type header when using uploadFile method. Previews for preview able file types, for example PNG, are now
  properly created for conversations. 

# 1.12.12
<sub>Publish Date: 7th of February 2024</sub>

Bug Fixes:
* Fixed typo when emitting a warning about outdated conversations over a certain threshold. For example, if there were 
  200 outdated conversations for account `accountId1`, the connection will emit a warning in the following way:
  ```js
  connection.on('warning', msg => {
     expect(message).toEqual('200 outdated conversations found for account accountId1, which is above the threshold of 100.');
  });
  ```


# 1.12.11
<sub>Publish Date: 5th of February 2024</sub>

Bug Fixes:
* Added configuration parameter `unsubscribeFromOutdatedConversationsOnReconnect` (defaults to true) whether to close 
  outdated conversations on reconnect or not. True is recommended, but should be set to false if issues with lost 
  messages are encountered. For example:
  ```js
  const connection = lpm.createConnection({
    appId: 'quick_start',
    accountId,
    userType: lpm.UserType.BRAND,
    authData,
    unsubscribeFromOutdatedConversationsOnReconnect: false
  });
  ```
  More information can be found in the [documentation](https://developers.liveperson.com/messaging-platform-sdk-overview.html#connection-maintenance).

# 1.12.10
<sub>Publish Date: 30th of January 2024</sub>

Bug Fixes:
* Updated URL path for all message/conversation related REST endpoints. From `/v1/conversations/` to `/messaging/v1/conversations/`.
* Fixed issue with `agentId` being null if message is sent by an agent that has been removed from the 
  conversation before the connection. The `agentId` now contains the right `agentId`.

# 1.12.9
<sub>Publish Date: 17th of January 2024</sub>

Changes:
* Adding anonymous  async function as param of the ring which could be resolved if rings need to use directly the conversation
* Adding `ringConversationTimeout` param to `createConnection` so brands can configure it.
* Adding `conversation.getLatestConsumerMessage()` to allow brand users to get latest consumer message.

Example:
* The code below showcases how a conversation can be accepted on the ring and how to retrieve the last consumer message:
  ```js
    // connect as admin for brand
    const connection = lpm.createConnection({appId: 'quick_start', userType: lpm.UserType.BRAND, accountId, authData, ringConversationTimeout: 2000});
    await connection.open();
    
    // agent state must be "ONLINE" in order to receive rings
    await connection.setAgentState({agentState: lpm.AgentState.ONLINE});
    
    // subscribe to routing tasks (rings)
    const taskRoutingSubscription = await connection.createRoutingTaskSubscription();
    
    // process the rings as they arrive
    connection.on('ring', async ring => {
    
        // ignore old rings
        if (ring.ringState !== lpm.RingState.WAITING) return;
        
        // accept the ring
        await ring.accept();
    
        // await conversation or null if waiting times out after 2000 ms
        const conversation = await ring.conversation();
        
        // Get the latest consumer message
        const latestConsumerMessage = conversation.getLatestConsumerMessage();
    });
    ```
  More information can be found in the [documentation](https://developers.liveperson.com/messaging-platform-sdk-overview.html#accepting-conversation-on-the-ring).

# 1.12.8
<sub>Publish Date: 15th of January 2024</sub>

Bug Fixes:
* Fixed issue with consumer connection not properly reflecting assigned agent change on skill transfer.
* `conversation-deleted` now emitted when `DELETE` notification is received, previously this was only emitted when a 
  conversation was removed during disconnect.

# 1.12.7
<sub>Publish Date: 9th of January 2024</sub>

Bug Fixes:
* Bumped axios version to 1.6.5 due to security vulnerabilities.

# 1.12.6
<sub>Publish Date: 12th of December 2023</sub>

Bug Fixes:
* Adding check for existing dialog before trying to transfer conversation on the `transfer` method. If there is no open
  dialog an `error` will be emitted:
  ```js
  conversation.on('error', err => expect(err.message).toEqual('Cannot transfer without open dialog present.'));
  ```

# 1.12.5
<sub>Publish Date: 7th of December 2023</sub>

Bug Fixes:
* Omit Accept-Encoding header when invoking UMS REST API

# 1.12.4
<sub>Publish Date: 6th of December 2023</sub>

Bug Fixes:
* Support additional query parameters for `getMessages` in `BrandRestConnection` 

# 1.12.3
<sub>Publish Date: 28th of November 2023</sub>

Bug Fixes:
* Fixing proxy web socket connection configuration issue

# 1.12.2
<sub>Publish Date: 22nd of November 2023</sub>

Changes:
* Adding `responseTimeout` param to `createConnection` so brands can configure it.

# 1.12.1
<sub>Publish Date: 10th of November 2023</sub>

Changes:
* Add support for proxy http request

Bug Fixes:
* Fix documenting example inside of the README about `createConversationSubscription`

# 1.11.3
* Fixing missing metadata for some messages while calling the `queryMessages` method.

# 1.11.2
* Fix a race condition when creating a new conversation which caused some conversations to have multiple conversation objects
* add `originatorId` and `originatorRole` as optional args for the rest `publishMessage`

# 1.11.1
* RoutingTaskSubscriptions are now restored upon reconnect.

# 1.11.0
* For Brand Rest Connections, getConversationById will now make a fetch call, parse the data, and return a conversation object. Previously it would only return the raw result of the HTTP request.

# 1.10.0
* Added `await connection.getMessageStatisticsForUser()` and `await connection.getMessageStatisticsForBrand()` to allow brand users to get message statistics information.
* Added `conversation.resumeConversation()` to allow brand users to resume previously closed conversation with a consumer.
* Added `connection.on('failed-to-connect')` event which will fire when moving to FAILED_TO_CONNECT state, ie when failed attempt occurs while trying to establish websocket connection.

## 1.9.6
* `connection.closeConversation(conversationId)` is now available. With this function conversations can be closed without a conversation object.

## 1.9.5
* `Conversation.assignedAgent` should return active assigned agent only. Also handled edge case where suggested agents do not have `userId`

## 1.9.4
* Fix `chatStateEvent for unknown participant undefined` error after moving message originator transformation in `1.9.2`

## 1.9.3
* Exposed `TTRType` enum
* Added `message.sentByCurrentUser` method to the Message class
* Added `getConversationById` & `getAllKnownConversations` methods to `Connection`
* Added `notificationType` of `child` for deferred notifications from child subscriptions

## 1.9.2
* Move message originator transformation from `connection` to `MessageFactory`, fixes issues where `Message` objects created from `lastContentEventNotification` and `queryMessages` did not have the correct sender

## 1.9.1
* Use `HTTPS` for the `baseURI` call to `CSDS`

## 1.9.0
* Rename `waitForFirstNotification` to `waitForReady`. `waitForFirstNotification` will still function to ensure backwards compatibility, but is now deprecated.
* Use of `notificationType` in `ConversationSubscription` to determine notification type, fixes issues around `onFirstNotification` and child subscriptions
* `userId` for brand connections is now userId uuid, rather than the un-prefixed `agentId`
* Fix `limit-break` chain for subscriptions with more than 2002 conversations

## 1.8.2
* Truncate `setAgentNote` to 5000-character limit, throw error if note cannot be added

## 1.8.1
* Don't delete lastContentEventNotification when emitting it to subscriptions
* Update participant role when they are removed and then re-added

## 1.8.0
* Add `setAgentNote` method to conversation, which deprecates `setNote`
* `BrandWebsocketConnection` now has `userProfile` parameter, available after opening the connection
* Fix to allow connection with existing unauthenticated token to step up
* Added documentation for continuing an anonymous user session between two connections 

## 1.7.2
* Add `consumer-step-up` event to the conversation

## 1.7.1
* Removed reference to a test module that was preventing code execution

## 1.7.0
* File sharing - Upload and Download for both node.js and browser
* Authenticated consumer flow
* Consumer stepup via `connection.stepUp()` function
* `participant.getUserProfile()` is now available
* `dialog.leave()` and `conversation.leave()` are now available
* Arbitrary websocket requests with `connection.send()`
* Listen to all websocket notifications via `connection.on('notification')`
* Expanded documentation

## 1.6.6
* added `conversation.consumer` getter to help get the conversation's consumer participant

## 1.6.5
* Fixed bug in 1001 conversation limit break for LP originating disconnects
* Lower default max reconnection time limit from 4 hours to 10 minutes

## 1.6.4
* Bug fixes 
  * When reconnecting, only drop conversations that have actually been closed while we were disconnected
  * When a conversation is dropped for any reason and it is later seen in a notification, re-add it to the cache

## 1.6.3
* Added `assignedAgent` getter to `Conversation` class

## 1.6.2
* Update appId with correct capitalization

## 1.6.1
* appId must be limited to alphanumeric plus special characters -_.

## 1.6.0
* **MA-238** appId is now a required argument when calling createConnection

## 1.5.7
* Handle notifications that have missing `participantsDetails`

## 1.5.5
* Add support for quickReplies, available by setting the third argument on sendMessage and sendRichText ```conversation.sendMessage('test', null, quickReplies);```

## 1.5.4
* Pass through getShiftStatus#response & getShiftStatus#error events to the connection

## 1.5.3
* TokenMaintainer fixes - prevent caching token generation errors to allow reconnections
* getToken now blocks until token generation succeeds or TokenMaintainer is stopped

## 1.5.2
* **CO-6234**: Add APIs to change TTR and ManualETTR of a conversation, which consequently emits `ttr-change` and `manual-ettr-change` events respectively
* Whitelist `dialog:close` event and bubble up to conversation & connection

## 1.5.1
* **CO-6394**: fix for conversation.sendRichText, metadata was populated with message audience
* expose ConversationContextType, add conversationContext and campaignInfo to readme

## 1.5.0
* shift-status polling now encapsulated and exposed in ```lpmsdk.ShiftStatusPoller```
* rest helper functions exposed through ```lpmsdk.rest```

## 1.4.6
* Bubble up dialog and conversation events to the connection. These will have a `conversation:` prefix to them e.g. `conversation:close`
* Minor refactor of `refreshSession` internal method

## 1.4.5
* Fix for serialization of rich content events

## 1.4.4
* `TokenMaintainer` ctor now expects an object. Also added `getAuthSessionInfo()` method and extended support for refreshing tokens when authSessionInfo is passed in ctor

## 1.4.3
* ```loadConversation(serializedConversationData)``` function on connection, which allows previously serialized conversations to be resumed by the connection.
* ```unload()``` function on conversation that allows a conversation to bemanually removed from the SDK's memory.

## 1.4.2
* Expose TokenMaintainer class

## 1.4.1
* Added a queue when processing onNotificationPart

## 1.4.0
* **CO-6062**: Create ConversationNotificationFeed, WebhooksIntake, and NullConnection classes to consume notifications from webhooks/kafka. Accessed via ```connection.processWebhooksNotification(notification)```

## 1.3.0
* Public documentation now available @ www.npmjs.com/package/lp-messaging-sdk
* Introduced TokenMaintainer class to keep bearer tokens valid
* TokenMaintainer now used in BrandWebsocketConnection & BrandRestConnection
* Bug fixes for `simple-websocket` library related to retrieving close and error codes
* **CO-6063**: Add `setCsat` function to conversation, available for consumers
* **CO-6099**: Expose `connection.getToken()` async method to obtain token from connection
* **CO-5613**: Static `deserialize` function to recreate a hydrated Conversation object from DB

## 1.2.31
* add "consumer" getter helper to dialog
* expose ParticipantChatState enum

## 1.2.30
* **CO-5950**: Always create context and attach clientProperties

## 1.2.29
* **CO-5989**: Add setNote function to conversation

## 1.2.28
* **CO-5907**: Allow campaignInfo argument on createConversation to pass through correctly
* **CO-5880**: RoutingTaskSubscriptions and Rings are now available
* Browser stand alone build is now available /web/lpm-sdk.js
* Websocket library "ws" has been replaced with "simple-websocket" for browser compatibility
* **CO-5987**: use v2.1 of the WS API to allow suggested agents
* Increased default wait to reconnect time to 2 seconds, as per UMS recommendation

## 1.2.23
* Added Conversation REST APIs under `lib/api/rest/conversation`

## 1.2.22
* Minor fix so `conversationContext` is passed in correctly when consumers create conversations

## 1.2.19
* BrandWebsocketConnection now emits `skill-entered-work-hours` and `skill-entered-off-hours` for any of its skills

## 1.2.18
* Allow access to `ParticipantRole` enum
* **CO-5713**: Added ability to attach metadata to messages in `sendMessage`, `sendPrivateMessage`, and `sendRichText`
* **CO-5612**: `serialize` method added for Conversation object to allow it to be persisted in DBs
* Added Messaging & General REST APIs under `lib/api/rest` 

## 1.2.17
* **CO-5322**: Subscriptions now have a process to get more than 1001 conversations, there is now no limit to the number 
  of conversations. This feature is enabled by default, but can be disabled by passing ```limitBreakEnabled: 
  false``` as an option to ```createConnection```
* **CO-5603**: Removed errors when receiving duplicate read or accept message notifications from UMS
* **CO-5604**: Fixed issue where onReconnect calls could be doubled up in certain scenarios

## 1.2.14
* **CO-5512**: ```maintainConnection``` is now true by default when calling ```createConnection```

## 1.2.11
* **CO-4981**: Added tracking info to WS connection URL params
* **CO-5532**: Mock stepup: automatic consumer take over
* **CO-5463**: Shift-status will now start and retrieve initial data before default subscription is created

## 1.2.10
* **CO-5436**: Skill.isInOffHours helper function

## 1.2.7
* **CO-5517**: Conversation Deleted Event

## 1.2.5
* **CO-5295**: Media Handler File upload requests
* **CO-5013**: Wait for the first MS notification

## 1.2.4
* **CO-5322**: Conversation subscriptions async .init() which must be called to create subscription

## 1.2.3
* _callShiftStatus now has a return value
* **CO-5321**: dialog.getAll() retrieves all messages

## 1.2.2
* **CO-5470**: Remove optional chaining parameter for compatibility with old versions of node.js
* **CO-5470**: add wait option to createSubscription

## 1.2.1

* **CO-4978**: dialog.setChatState function
* Shift-status poller

## 1.1.1

* **CO-4866**: Resubscribe Subscriptions on Reconnect
* **CO-5232**: Private messages
* **CO-5154**: Support for Multiple Dialogs of the same Type
