{"_id":"@avaya/axp-omni-sdk-messaging","_rev":"16-ff5c5d9c71454762df3411b2505b71f8","name":"@avaya/axp-omni-sdk-messaging","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@avaya/axp-omni-sdk-messaging","version":"1.0.0","license":"SEE LICENSE IN LICENSE.txt","_id":"@avaya/axp-omni-sdk-messaging@1.0.0","maintainers":[{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},{"name":"kahagerman","email":"kahagerman@avaya.com"},{"name":"amarasescu","email":"amarasescu@avaya.com"},{"name":"digitalpipeline","email":"bvishwakarma@avaya.com"},{"name":"enrique-prado","email":"enriquep@avaya.com"},{"name":"jonathanavaya","email":"jonathanr@avaya.com"},{"name":"yangatavaya","email":"chungguangy@avaya.com"},{"name":"joe-s-avaya","email":"joe.sebast.avaya@gmail.com"},{"name":"mrazian","email":"mrazian@avaya.com"},{"name":"cpaas.devops","email":"cpaasops@avaya.com"},{"name":"bvazmer","email":"bvazmer@avaya.com"}],"dist":{"shasum":"0ebf54c4eccc49b886f700fe275b6c0258ec62bb","tarball":"https://registry.npmjs.org/@avaya/axp-omni-sdk-messaging/-/axp-omni-sdk-messaging-1.0.0.tgz","fileCount":5,"integrity":"sha512-b3v+S32blACYJL4dCk1x0R0BnbTEvKNruA/7VpK7AnFBAmygSiozffqaTDb2n2C0MFA7RN4V+s6rQq74CZpNCA==","signatures":[{"sig":"MEQCIB5n3YmCrDnQCyj3a8FsEXJGfKdtimlb/XK20ftJNqC8AiB7qdLTN65cvQT0LhxeiBNpqS49M6glbSTUKzN2F8ATyg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":107433},"type":"module","_from":"file:candidate/avaya-axp-omni-sdk-messaging-1.0.0.tgz","exports":{".":{"types":"./lib/axp-omni-sdk-messaging-types.d.ts","import":"./lib/axp-omni-sdk-messaging.js"}},"_npmUser":{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},"_resolved":"/home/runner/work/sdk/sdk/candidate/avaya-axp-omni-sdk-messaging-1.0.0.tgz","_integrity":"sha512-b3v+S32blACYJL4dCk1x0R0BnbTEvKNruA/7VpK7AnFBAmygSiozffqaTDb2n2C0MFA7RN4V+s6rQq74CZpNCA==","_npmVersion":"10.7.0","description":"Web messaging","directories":{},"_nodeVersion":"20.15.1","dependencies":{"@avaya/axp-omni-sdk-core":"^1.0.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/axp-omni-sdk-messaging_1.0.0_1722296819342_0.3418650815502937","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@avaya/axp-omni-sdk-messaging","version":"1.1.0","license":"SEE LICENSE IN LICENSE.txt","_id":"@avaya/axp-omni-sdk-messaging@1.1.0","maintainers":[{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},{"name":"kahagerman","email":"kahagerman@avaya.com"},{"name":"amarasescu","email":"amarasescu@avaya.com"},{"name":"digitalpipeline","email":"bvishwakarma@avaya.com"},{"name":"enrique-prado","email":"enriquep@avaya.com"},{"name":"jonathanavaya","email":"jonathanr@avaya.com"},{"name":"yangatavaya","email":"chungguangy@avaya.com"},{"name":"joe-s-avaya","email":"joe.sebast.avaya@gmail.com"},{"name":"mrazian","email":"mrazian@avaya.com"},{"name":"cpaas.devops","email":"cpaasops@avaya.com"},{"name":"bvazmer","email":"bvazmer@avaya.com"}],"dist":{"shasum":"2798599e9ed14b8db138e7b9d1a4652ac26de07e","tarball":"https://registry.npmjs.org/@avaya/axp-omni-sdk-messaging/-/axp-omni-sdk-messaging-1.1.0.tgz","fileCount":5,"integrity":"sha512-YK+uH9BpStykWZI9ybxhQ1evctimboP3pCHUXZmU1dyIFkFW5VDDJbayxJTeaHTV9pE+UXCQqStYE5ZCBwKfXQ==","signatures":[{"sig":"MEYCIQCL06XMHnbPhk0NAjNjRBZlN9f0nPTgtjjwuqrqBvKPewIhAPW52kWlKAzTFMxYdODjsINUBEuzeJtIrVozrH8oJCgt","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":132369},"type":"module","_from":"file:candidate/avaya-axp-omni-sdk-messaging-1.1.0.tgz","exports":{".":{"types":"./lib/axp-omni-sdk-messaging-types.d.ts","import":"./lib/axp-omni-sdk-messaging.js"}},"_npmUser":{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},"_resolved":"/home/runner/work/sdk/sdk/candidate/avaya-axp-omni-sdk-messaging-1.1.0.tgz","_integrity":"sha512-YK+uH9BpStykWZI9ybxhQ1evctimboP3pCHUXZmU1dyIFkFW5VDDJbayxJTeaHTV9pE+UXCQqStYE5ZCBwKfXQ==","_npmVersion":"10.8.2","description":"Web messaging","directories":{},"_nodeVersion":"20.17.0","dependencies":{"@avaya/axp-omni-sdk-core":"^1.1.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/axp-omni-sdk-messaging_1.1.0_1728419021512_0.9827042303839852","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-07-29T23:46:59.202Z","modified":"2026-02-04T12:58:18.938Z","0.0.0":"2024-07-25T21:15:35.115Z","1.0.0":"2024-07-29T23:46:59.749Z","1.1.0":"2024-10-08T20:23:41.695Z"},"license":"SEE LICENSE IN LICENSE.txt","description":"Web messaging","maintainers":[{"email":"mrazian@avaya.com","name":"mrazian"},{"email":"cpaasops@avaya.com","name":"cpaas.devops"},{"email":"bvazmer@avaya.com","name":"bvazmer"},{"email":"gaffara@avaya.com","name":"gaffara"},{"email":"amarasescu@avaya.com","name":"amarasescu"},{"email":"bvishwakarma@avaya.com","name":"digitalpipeline"},{"email":"kahagerman@avaya.com","name":"kahagerman"},{"email":"axp-sdk-automation@avaya.com","name":"axp-sdk-automation"},{"email":"raziandev@gmail.com","name":"raziandev"},{"email":"ptognini@avaya.com","name":"ptognini77"},{"email":"kamau3@avaya.com","name":"kamau3"},{"email":"lancecramlet@avaya.com","name":"lcramlet-avaya"},{"email":"jmidd@avaya.com","name":"jmiddd"},{"email":"ggoulet@avaya.com","name":"ggoulet_avaya"},{"email":"peter.c.schuelke@gmail.com","name":"shulkdog"}],"readme":"# AXP Messaging\n\nThe AXP Messaging SDK module provides enables asynchronous communication, allowing end users to resume conversation threads at any time and view all previous messages exchanged as part of the conversation. This is unlike a session-based chat, where the chat is closed after the participants disconnect the dialog. The AXP Messaging module extends base Conversation with Messaging capabilities.\n\nThe AXP Messaging module depends on the AXP Core module. Please refer to the [AXP Core documentation](https://github.com/AvayaExperiencePlatform/omni-sdk-js/blob/v1.1.0/core.md) before using the Messaging module.\n\n## Main features\n\n1. **Message History**: The AXP Messaging module provides a message history feature that allows users to view all messages exchanged in a conversation thread.\n2. **Resume Conversation**: The AXP Messaging module allows users to resume a messaging conversation thread at any time. This includes auto resuming the conversation initiated from another session of the same user, to converse simultaneously from multiple devices. Auto resuming might take a minute to detect an active conversation on another session.\n3. **Send Message**: The AXP Messaging module allows users to send messages to other participants in a conversation thread.\n4. **Receive Message**: The AXP Messaging module allows users to receive messages from other participants in a conversation thread.\n5. **Send rich media messages**: The AXP Messaging module allows users to send rich media messages like Post back, replies and location to other participants in a conversation thread.\n6. **Receive rich media messages**: The AXP Messaging module allows users to receive rich media messages like Post back, Replies and Location Request, Carousel etc, from other participants in a conversation thread.\n7. **Send and receive attachments**: The AXP Messaging module allows users to send and receive attachments like images, videos, audio, documents etc, to other participants in a conversation thread.\n8. **Typing indicators**: The AXP Messaging module enables sending typing indicator of the user and receiving typing indicator(s) of other participants in the conversation.\n\n## Installation\n\nAXP Messaging module requires the AXP Core module.\n\nTo install the AXP Messaging module, run the following command:\n\n```bash\nnpm install --save @avaya/axp-omni-sdk-messaging\n```\n\nThis will install both AXP Core and AXP Messaging.\n\n## Usage\n\nThe AXP Messaging module provides the `AxpMessagingConversation` [mixin](https://www.typescriptlang.org/docs/handbook/mixins.html) that extends the Base Conversation of the AXP Core module. To use the Messaging module, you need to import the `AxpMessagingConversation` mixin function and apply it. Check out more details about additional functionalities in the `Using additional functionality` section of The [AXP Core's documentation](https://github.com/AvayaExperiencePlatform/omni-sdk-js/blob/v1.1.0/core.md).\n\nExample of how to use AXP Messaging module:\n\n```ts\n// Note: Here ... (dot dot dot) indicates the rest of the code, which is excluded for brevity.\n\nimport { AxpOmniSdk } from '@avaya/axp-omni-sdk-core';\nimport { AxpMessagingConversation } from '@avaya/axp-omni-sdk-messaging';\n\nconst EnhancedConversationClass = AxpMessagingConversation();\n\nconst userSession = await AxpOmniSdk.init({...}, EnhancedConversationClass);\n\nconst defaultConversation = userSession.conversations[0];\n\n// The `defaultConversation` object has methods of both AXP Core and Messaging modules.\ndefaultConversation.addParticipantAddedListener(...) // <-- AXP Core method\ndefaultConversation.sendMessage(...); // <-- AXP Messaging method\n```\n\n## Messaging Conversation\n\nMessaging Conversation provides APIs to send and receive rich media and attachment messages, get conversation history and listen to message events. For more details on the APIs exposed on the Messaging Conversation, refer to the `AxpMessagingConversationTrait` interface.\n\n### Getting conversation history\n\nTo get the conversation history, use the `getMessages()` method on the Conversation. The `getMessages()` method returns a `PageIterator` object that can be used to iterate over the messages in the conversation. The `getMessages()` API takes an optional parameter `pageSize` which specifies the number of messages to fetch in a single page. The default value of `pageSize` is 10 and maximum page size is 50.\n\nNote: The iterator can only be used to get messages conversed in the conversation from start up until the point the iterator was created. For newer messages please listen to the message events. Do not use the `getMessages()` API to get new messages.\n\nEach Page of the iterator contains a list of messages. As the page number increases, the messages are older. The iterator can be used to get messages in both directions (forward and backward).\n\nThe `PageIterator.previous()` and `PageIterator.next()` are async methods, when called they fetch the previous and next page of messages respectively and each resolves with an Array of `Message`. The `PageIterator.hasNext()` and `PageIterator.hasPrevious()` methods check if there are more messages in the next and previous pages, respectively.\n\nAt any point `PageIterator.items` can be used to get the messages on the current page.\n\n```ts\nfunction showMessagesOnUI(messages) {\n\t// Logic to show messages on UI.\n\t// ...\n}\n\nconst iterator = await conversation.getMessages(15);\n\nshowMessagesOnUI(iterator.items);\n\nconst loadMore = document.getElementById(\"load-more-button\");\n\nloadMore.onclick = function () {\n\tif (iterator.hasPrevious()) {\n\t\tconst previousPage = await iterator.previous();\n\t\tshowMessagesOnUI(previousPage);\n\t}\n};\n```\n\n### Sending messages\n\nThe AXP Messaging module supports sending various types of messages, including:\n\n- Text(Plain text, Emoji's, Links)\n- Postback\n- Reply\n- Attachment\n- Location\n\nTo send a message, use the `sendMessage()` method on the Conversation. The `sendMessage()` method takes a `SendMessageRequest` object as a parameter. Based on the type of message you want to send, you can use one of the following implementations of `SendMessageRequest` to construct your message:\n\n- `SendTextMessage`: To send a plain text message.\n- `SendMessagePostBackAction`: To send a post back message.\n- `SendMessageReplyAction`: To send a reply message.\n- `SendMessageAttachment`: To send an attachment message.\n- `SendMessageLocation`: To send a location message.\n\n#### Sending plaintext messages\n\nTo send a plain text message, use the `SendTextMessage` class to build your message. The `SendTextMessage` class constructor takes a `text` and an optional `parentMessageId` parameter. The `parentMessageId` is the messageId of the message to which the current message is a reply.\n\n```ts\nconst message = new SendTextMessage(\"Hi\");\nconversation.sendMessage(message);\n```\n\n#### Sending rich media reply messages\n\nTo send a rich media reply message, use the `SendMessageReplyAction` class to build your message. The `SendMessageReplyAction` class constructor takes in the action `payload` of the selected action from the list of actions in the message received from Agent. Along with `payload`, you can also pass optional arguments `actionText`, `iconUrl` and the `parentMessageId` parameter. Here the `parentMessageId` can be used to specify the Agent's reply request rich media message to which this current message is a reply.\n\n```ts\nconst message = new SendMessageReplyAction(\n\t\"CUSTOMER_HAPPY\",\n\t\"Happy\",\n\t\"https://example.com/happy.png\",\n\t\"acbc012d-1b73-4e1b-98c9-fe64e7ab2b41\",\n);\nconversation.sendMessage(message);\n```\n\n#### Sending rich media postback messages\n\nTo send a rich media postback message, use the `SendMessagePostBackAction` class to build your message. The `SendMessagePostBackAction` class constructor takes in the action `payload` of the selected action from the list of actions in the message received from Agent. Along with `payload`, you can also pass optional arguments `actionText` and the `parentMessageId` parameter. Here the `parentMessageId` can be used to specify the Agent's post back request rich media message to which this current message is a reply.\n\n```ts\nconst message = new SendMessagePostBackAction(\"SHIP_TO_HOME\", \"Ship to home\", \"acbc012d-1b73-4e1b-98c9-fe64e7ab2b41\");\nconversation.sendMessage(message);\n```\n\n#### Sending location messages\n\nTo send a location message, use the `SendMessageLocation` class to build your message. The `SendMessageLocation` class constructor takes in the `latitude`, `longitude`, and optional arguments `name` and `address`, `parentMessageId`. The `parentMessageId` is the messageId of the message to which the current message is a reply.\n\nThe `name` and `address` are optional parameters that can be used to provide additional information about the location.\n\n```ts\nconst message = new SendMessageLocation(0, 0, \"North Pole of the Earth\", \"North Pole\");\nconversation.sendMessage(message);\n```\n\n#### Sending attachment messages\n\nTo send an attachment message, use the `SendMessageAttachment` class to build your message. The `SendMessageAttachment` class constructor takes in the `File` object and optional arguments `text` (optional text to send along side the file), `parentMessageId`. The `parentMessageId` is the messageId of the message to which the current message is a reply. The `SendMessageAttachment` class can be used to send images as well.\n\n```ts\nconst fileInput = document.getElementById(\"file-input\");\nlet selectedFile;\n\nfileInput.onchange = function () {\n\tselected = fileInput.files[0];\n};\n\nconst sendAttachmentButton = document.getElementById(\"send-attachment-button\");\n\nsendAttachmentButton.onclick = function () {\n\tconst message = new SendMessageAttachment(\n\t\tselectedFile,\n\t\t\"Here is the invoice\",\n\t\t\"acbc012d-1b73-4e1b-98c9-fe64e7ab2b41\",\n\t);\n\tconversation.sendMessage(message);\n};\n```\n\n### Waiting for message to be sent\n\nThe `sendMessage()` API returns a `Promise` that resolves with the `Message` object corresponding to the message that sent. This object contains unique `messageId` of this message and other details.\n\n### Message delivery\n\nThe Client must listen to the the Message Delivered event to be notified when the messages that were sent by the User are delivered to the AXP. To do so the Client use the `addMessageDeliveredListener()` method on the Conversation object to register the Message Delivered event listener. The `addMessageDeliveredListener()` method the listener function as the argument. The listener will be called with the Message object corresponding to the message that sent. The Message object contains unique `messageId` of this message and other details.\n\n```ts\nfunction showTickOnUI(message) {\n\t// Logic to show tick on UI.\n\t// ...\n}\n\nconversation.addMessageDeliveredListener((message) => {\n\tshowTickOnUI(message);\n});\n```\n\n### Receiving messages\n\nThe Client must listen to the the Message Arrived event to be notified when the messages are received from the Agent. To do so the Client use the `addMessageArrivedListener()` method on the Conversation object to register the Message Arrived event listener. The `addMessageArrivedListener()` method the listener function as the argument. The listener will be called with the Message object corresponding to the message that received. The Message object contains the unique `messageId` and body of the message sent by the Agent.\n\n```ts\nfunction showMessagesOnUI(message) {\n\t// Logic to show messages on UI.\n\t// ...\n}\n\nconversation.addMessageArrivedListener((message) => {\n\tshowMessagesOnUI(message);\n});\n```\n\n### Sending typing indicators\n\nThe AXP Messaging module supports sending typing indicators to notify other participants in the conversation that the user is typing. To achieve this, the client should use the `notifyUserTyping()` method on the Conversation object.\n\nThis method essentially acts like a beacon. Call this method while the user is typing to notify the Contact Center about the user's typing activity. For example, call this method on every input change or key down events.\n\nExample:\n\n```ts\nconst inputField = document.getElementById(\"input-field\");\n\ninputField.addEventListener(\"keydown\", () => {\n\tconversation.notifyUserTyping();\n});\n```\n\n### Receiving typing indicators\n\nTo show typing indicators when other participants in the conversation are typing, the Client must listen to the typing started and stopped events. To do so, the Client can use the `addTypingStartedListener()` and `addTypingStoppedListener()` methods on the Conversation object to register the typing started and typing stopped event listeners. The `addTypingStartedListener()` and `addTypingStoppedListener()` methods take the listener function as the argument. The listeners will be called with the `TypingStarted` and `TypingStopped` object corresponding to the respective typing events, which contain details of the participant who started or stopped typing.\n\nExample:\n\n```ts\nfunction showTypingIndicatorOnUi(participant) {\n\t// Logic to show typing indicator for the given participant on UI.\n\t// ...\n}\n\nfunction hideTypingIndicatorOnUi(participant) {\n\t// Logic to hide typing indicator for the given participant on UI.\n\t// ...\n}\n\nconversation.addTypingStartedListener((typingStartedEvent: TypingStarted) => {\n\tshowTypingIndicatorOnUi(typingStartedEvent.participant);\n});\n\nconversation.addTypingStoppedListener((typingStoppedEvent: TypingStopped) => {\n\thideTypingIndicatorOnUi(typingStoppedEvent.participant);\n});\n```\n\n## Axp Messaging Namespace\n\nThe AXP Messaging module consists of `AxpMessaging` namespace which contains a set of APIs which aren't directly coupled to the concept of Messaging Conversation. This namespace consists of APIs and Events related to the networking model used by the AXP Messaging to get messages and events from AXP.\n\nDuring the session, the state of SDK’s connection with AXP Servers can change. In all the cases the network state changes are notified in the form of events. The Client can subscribe to these events for handling the changes in network.\n\nList of Events:\n\n| Event Name              | Description                                                                                                                                                             |\n| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Event Stream Connecting | This event is raised when the SDK tries to connect with the event stream.                                                                                               |\n| Event Stream Connected  | This event is raised when the SDK’s connection attempt was successful, and the connection with AXP is established.                                                      |\n| Event Stream Failed     | This event is raised when the event stream breaks/fails due to some reason. Details like the reason for failure as well as next retry attempt is provided in the event. |\n| Event Stream Closed     | This event is raised when the SDK disconnects itself from the event stream.                                                                                             |\n\nThe Client can use `add/remove` methods exposed by the `AxpMessaging` namespace to subscribe/unsubscribe to these events.\n\nExample:\n\n```ts\nimport { AxpMessaging } from \"@avaya/axp-omni-sdk-messaging\";\n\nAxpMessaging.addEventStreamConnectingListener((eventPayload) => {\n\t// Show connecting on UI.\n});\n\nAxpMessaging.addEventStreamConnectedListener((eventPayload) => {\n\t// Show connected on UI.\n});\n\nAxpMessaging.addEventStreamFailedListener((eventPayload) => {\n\t// Show network disconnected on UI.\n\tconsole.log(\n\t\t`SDK disconnected due to ${eventPayload.reason}, next retry attempt will be made after ${eventPayload.retryAfter} seconds.`,\n\t);\n});\n\nAxpMessaging.addEventStreamClosedListener((eventPayload) => {\n\t// Show connection closed on UI.\n});\n```\n\nAfter disconnection, the SDK will try to reconnect with AXP until the reconnection window expires. The will try to make multiple attempts to reconnect with AXP. The interval between each subsequent attempt will keep on increasing till the reconnection window (5 minutes) expires. If the SDK is unable to reconnect within the reconnection window, the SDK will stop trying to reconnect.\n\nPost this, the Client can make an explicit attempt to retry connecting with AXP. To do so, the Client must call the `retryConnection()` method exposed by the `AxpMessaging` namespace.\n\n```ts\nimport { AxpMessaging } from \"@avaya/axp-omni-sdk-messaging\";\n\nAxpMessaging.retryConnection();\n```\n\nThis method is not an `async` method and a successful return of this method doesn't guarantee that the SDK has been connected with AXP yet, instead the Client should subscribe to the Event Stream Connected event. In case of failure during the manual retry attempt, the Client will be notified via the Event Stream Failed event.\n\nIf the manual retry is successful, the Client will be notified via the Event Stream Connected event and the SDK will resume its connection with AXP.\n\nCalling `retryConnection()` method when the SDK is disconnected but within the reconnection window will just reset the delay interval between the subsequent attempts and will attempt to reconnect immediately.\n\nCalling `retryConnection()` method when the SDK is not disconnected will throw an Error.\n","readmeFilename":"README.md"}