### Install and Import MirrorFly SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Demonstrates how to add the MirrorFly SDK to a project using the NPM package manager and import it into the application source code. ```bash npm i mirrorfly-sdk ``` ```javascript import * as SDK from "mirrorfly-sdk"; ``` -------------------------------- ### Example Request for Group JID using JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/groupchat/overview This is an example demonstrating how to call the `getGroupJid` method with a sample Group ID. The output is a JSON object containing the status code, message, and the generated user JID for the group. ```javascript SDK.getGroupJid(`0f617991-08d0-4474-ae6c-f070dc63bb1a`); ``` -------------------------------- ### Initialize MirrorFly Chat SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Initializes the chat SDK by providing the required license key and callback listeners. This step is mandatory before performing any chat operations. ```javascript const initializeObj = { licenseKey: "LICENSE_KEY", callbackListeners: {}, }; await SDK.initializeSDK(initializeObj); ``` -------------------------------- ### Connect to MirrorFly Server API Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Establish a connection to the MirrorFly server using the credentials obtained during user registration. ```APIDOC ## POST /connect ### Description Connects to the MirrorFly server using provided username and password. Successful connection returns a status code of 200. ### Method POST ### Endpoint /connect ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **USERNAME** (String) - Required - Username obtained from registration. - **PASSWORD** (String) - Required - Password obtained from registration. ### Request Example ```javascript await SDK.connect('USERNAME', 'PASSWORD'); ``` ### Response #### Success Response (200) - **message** (String) - Success/Error Message - **statusCode** (Number) - Status Code #### Response Example ```json { "message": "Login Success", "statusCode": 200 } ``` ##### Note To learn more about all possible logins and profile related setup, go to Profile Section. ``` -------------------------------- ### Include MirrorFly SDK via Script Tag Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Shows the alternative method of integrating the SDK by manually downloading the files and including them in the project's HTML file. ```html ``` -------------------------------- ### User Registration API Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Register a new user with the MirrorFly server. This API allows for optional metadata and force registration to handle multiple sessions. ```APIDOC ## POST /register ### Description Registers a new user with the MirrorFly server. You can optionally provide metadata and control session behavior. ### Method POST ### Endpoint /register ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **USER_IDENTIFIER** (String) - Required - Unique Id to Register the User. User identifier can only contain lowercase alphanumeric characters, hyphens (-), and underscores (_). - **FORCE_REGISTER** (Boolean) - Optional - `default value true`. Provide `true` to force the old session logged out when the registered user has reached the maximum number of multiple-sessions or provide `false` to allow registration till the maximum no of multiple-sessions reached. - **registerMetaData** (Object) - Optional - `registerMetaData` is an optional parameter to provide MetaData of user. `Maximum size is 3`. - **key** (String) - Name of the Key - **value** (String or Boolean or Number) - Name of the value ### Request Example ```json { "USER_IDENTIFIER": "unique_user_id", "FORCE_REGISTER": true, "registerMetaData": { "key1": "value1", "key2": true } } ``` ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message - **data** (Object) - Username, Password, isProfileUpdated, isSandbox, userJid - **username** (String) - **password** (String) - **isProfileUpdated** (Boolean) - **isSandbox** (Boolean) - **userJid** (String) #### Response Example ```json { "statusCode": 200, "message": "Success", "data": { "username": "123456789", "password": "987654321", "isProfileUpdated": true, "isSandbox": true, "userJid": "1234567890@xmppdomain" } } ``` ##### Caution If `FORCE_REGISTER` is false and if it reached the maximum no of multiple-sessions, then registration will not success and it will throw a 405 exception. Either `FORCE_REGISTER` should be true or one of the existing session need to be logged out to continue registration. ##### Note If you want to use your own Id, you can use the `userJid` in the registration response. ``` -------------------------------- ### Register a New User Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Registers a new user with the MirrorFly server using a unique identifier. Successful registration provides credentials for connection. ```javascript await SDK.register("USER_IDENTIFIER"); ``` -------------------------------- ### Initialize MirrorFly SDK with Callback Listeners Source: https://www.mirrorfly.com/docs/chat/javascript/v2/callback-listeners Demonstrates how to define individual callback listener functions and register them within the SDK initialization object. This setup ensures the application can respond to various events like message reception, connection changes, and profile updates. ```JavaScript const connectionListener = (res) => {}; const presenceListener = (res) => {}; const friendsListListener = (res) => {}; const userProfileListener = (res) => {}; const messageListener = (res) => {}; const editMessageListener = (res) => {}; const replyMessageListener = (res) => {}; const favouriteMessageListener = (res) => {}; const groupProfileListener = (res) => {}; const groupMsgInfoListener = (res) => {}; const mediaUploadListener = (res) => {}; const mediaDownloadListener = (res) => {}; const blockUserListener = (res) => {}; const singleMessageDataListener = (res) => {}; const muteChatListener = (res) => {}; const archiveChatListener = (res) => {}; const userDeletedListener = (res) => {}; const adminBlockListener = (res) => {}; const initializeObj = { licenseKey: "XXXXXXXXXXXXXXXXX", callbackListeners: { connectionListener, presenceListener, friendsListListener, userProfileListener, messageListener, editMessageListener, replyMessageListener, favouriteMessageListener, groupProfileListener, groupMsgInfoListener, mediaUploadListener, mediaDownloadListener, blockUserListener, singleMessageDataListener, muteChatListener, archiveChatListener, userDeletedListener, adminBlockListener } }; await SDK.initializeSDK(initializeObj); ``` -------------------------------- ### Get User JID API Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Generates a unique JID for a user based on their username. ```APIDOC ## GET /getJid ### Description Generates a JID (Jabber ID) for a given username. ### Method GET ### Endpoint /getJid ### Parameters #### Path Parameters None #### Query Parameters - **USER_NAME** (String) - Required - The unique username obtained from the registration response. ### Request Example ```javascript const userJid = SDK.getJid('unique_user_id'); ``` ### Response #### Success Response (200) - **userJid** (String) - The generated JID for the user. #### Response Example ```json { "userJid": "unique_user_id@xmppdomain" } ``` ``` -------------------------------- ### Message Listener Callback Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Implement the messageListener callback function to receive incoming messages and related events. ```APIDOC ## Event Listener ### Description This function is triggered whenever a new message or related event is received in one-to-one or group chats. It should be implemented during the SDK initialization process. ### Method Callback Function ### Endpoint N/A ### Parameters None ### Request Example ```javascript function messageListener(response) { console.log("Message Listener", response); // Process the incoming message or event here } // Initialize SDK with the callback // SDK.initialize(..., messageListener); ``` ### Response #### Success Response The `response` object contains details of the incoming message or event. #### Response Example ```json { "message": "Incoming message data...", "fromUserJid": "sender_user_jid", "messageText": "Hello from the other side!" // ... other message properties } ``` ``` -------------------------------- ### Reply Message Listener Source: https://www.mirrorfly.com/docs/chat/javascript/v2/callback-listeners Handles Reply Message IQs triggered when the Get Reply Message method is called. ```APIDOC ## [EVENT] Reply Message Listener ### Description Triggered when Get Reply Message method is called. Receives an array of reply objects. ### Response - **chatType** (String) - Chat Type - **oldMsgId** (String) - Original Message Id - **replyMsgContent** (String) - Reply Message Content - **replyMsgId** (String) - Reply Message Id ### Response Example [ { "chatType": "chat", "oldMsgId": "msg_001", "replyMsgContent": "This is a reply", "replyMsgId": "reply_999" } ] ``` -------------------------------- ### Get Users I Blocked Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves a list of all users that the current user has blocked. ```APIDOC ## GET /users/blocked ### Description Retrieves a list of all users that the current user has blocked. ### Method GET ### Endpoint /users/blocked ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message - **data** (Array) - Blocked User List #### Response Example ```json { "statusCode": 200, "message": "Blocked users retrieved successfully.", "data": [ { "jid": "user1@domain.com", "name": "User One" } ] } ``` ``` -------------------------------- ### Send Media and File Messages using SDK v2 Source: https://www.mirrorfly.com/docs/chat/javascript/v2/migration-guide Consolidates multiple media-specific methods into a single sendFileMessage method. The method accepts a messageType and a fileMessageParams object to handle images, videos, audio, and documents. ```javascript await SDK.sendFileMessage({ toJid: "", messageType: "image", fileMessageParams: { file: {}, thumbImage: "", fileSize: 0, fileName: "", caption: "" }, replyMessageId: "", mentionedUsersIds: [], topicId: "", metaData: {} }); ``` -------------------------------- ### Connect to MirrorFly Server Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Establishes a connection to the MirrorFly server using provided username and password credentials obtained during registration. Successful connection returns a status code of 200. Connection status can also be monitored via a connectionListener callback. ```javascript await SDK.connect("USERNAME", "PASSWORD"); ``` -------------------------------- ### Get User Token Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Generates and retrieves a new user token required for API access, using provided username and password. ```APIDOC ## POST /auth/token/generate ### Description Generates and retrieves a new user token required for API access, using provided username and password. ### Method POST ### Endpoint /auth/token/generate ### Parameters #### Request Body - **USERNAME** (String) - Required - Username - **PASSWORD** (String) - Required - Password ### Request Example ```javascript await SDK.getUserToken("my_username", "my_password"); ``` ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message - **userToken** (String) - User Token #### Response Example ```json { "statusCode": 200, "message": "User token generated successfully.", "userToken": "generated_user_token_string" } ``` ``` -------------------------------- ### Handle Typing/Gone Status Event Source: https://www.mirrorfly.com/docs/chat/javascript/v2/callback-listeners Represents the composing or gone status events received when a user starts or stops typing. It identifies the sender and the associated group if applicable. ```json { "msgType": "", "fromUserId": "", "groupId": null } ``` -------------------------------- ### Prepare User JID Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Generates a unique JID (Jabber Identifier) for a user. This JID is essential for identifying users within the MirrorFly network for communication purposes. It requires the user's unique username obtained from the registration response. ```javascript const userJid = SDK.getJid("USER_NAME"); ``` -------------------------------- ### Retrieve Media Messages using SDK v2 Source: https://www.mirrorfly.com/docs/chat/javascript/v2/migration-guide Updates the media message retrieval method to use an object parameter. This replaces the previous positional arguments to fetch media messages associated with a specific JID and message ID. ```javascript await SDK.getMediaMessages({ toJid: "", lastMsgId: "", topicId: "" }); ``` -------------------------------- ### Register User with MirrorFly SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Registers a new user with the MirrorFly server. It requires a unique USER_IDENTIFIER and optionally accepts FORCE_REGISTER and registerMetaData. FORCE_REGISTER defaults to true, controlling session logout behavior. registerMetaData allows for custom user data with a limit of 3 key-value pairs. ```javascript await SDK.register( "USER_IDENTIFIER", true, // FORCE_REGISTER (optional, defaults to true) [ { key: "customKey", value: "customValue" } // registerMetaData (optional) ] ); ``` -------------------------------- ### Get Group Media Messages with JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/groupchat/retrieve-group Retrieves media messages for a specific group. Initially fetches three media, and subsequent requests with a last message ID fetch ten more. Requires the group JID. Returns a list of media messages or an error. ```javascript await SDK.getMediaMessages(`TO_GROUP_JID`); ``` ```javascript await SDK.getMediaMessages(`TO_GROUP_JID`, `LAST_MESSAGE_ID`); ``` -------------------------------- ### Handle Group Message Information (JavaScript) Source: https://www.mirrorfly.com/docs/chat/javascript/v2/callback-listeners This listener is triggered when the 'get group message info' method is called. It provides specific details about messages within a group, which can be used for displaying message status, read receipts, or other group message-related metadata. The response object contains message-specific information. ```javascript function groupMsgInfoListener(response) { console.log("Group Message Info Listener", response); } ``` -------------------------------- ### Initialize MirrorFly SDK with Callbacks (JavaScript) Source: https://www.mirrorfly.com/docs/chat/javascript/v2/initialization Initializes the MirrorFly SDK using a license key and an object containing various callback listeners for different events. Ensure the license key is valid and all listener functions are correctly defined. ```javascript const connectionListener = (res) => {}; const presenceListener = (res) => {}; const friendsListListener = (res) => {}; const userProfileListener = (res) => {}; const messageListener = (res) => {}; const replyMessageListener = (res) => {}; const favouriteMessageListener = (res) => {}; const groupProfileListener = (res) => {}; const groupMsgInfoListener = (res) => {}; const mediaUploadListener = (res) => {}; const blockUserListener = (res) => {}; const singleMessageDataListener = (res) => {}; const muteChatListener = (res) => {}; const archiveChatListener = (res) => {}; const userDeletedListener = (res) => {}; const adminBlockListener = (res) => {}; const initializeObj = { licenseKey: "XXXXXXXXXXXXXXXXX", callbackListeners: { connectionListener, presenceListener, friendsListListener, userProfileListener, messageListener, replyMessageListener, favouriteMessageListener, groupProfileListener, groupMsgInfoListener, mediaUploadListener, blockUserListener, singleMessageDataListener, muteChatListener, archiveChatListener, userDeletedListener, adminBlockListener }, }; await SDK.initializeSDK(initializeObj); ``` -------------------------------- ### GET /getGroupJid Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat Generates a full GroupJID using a unique GroupID. ```APIDOC ## GET /getGroupJid ### Description Retrieves the full JID for a group based on its ID. ### Method GET ### Parameters #### Query Parameters - **GROUP_ID** (String) - Required - The unique ID of the group ### Response #### Success Response (200) - **groupJid** (String) - The full JID of the group ### Response Example { "statusCode": 200, "message": "Success", "groupJid": "0f617991-08d0-4474-ae6c-f070dc63bb1a@mix.xmppdomain" } ``` -------------------------------- ### Get Users Who Blocked Me Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves a list of users who have blocked the current user. ```APIDOC ## GET /users/blocked_by_me ### Description Retrieves a list of users who have blocked the current user. ### Method GET ### Endpoint /users/blocked_by_me ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message - **data** (Array) - Blocked User List #### Response Example ```json { "statusCode": 200, "message": "Users who blocked me retrieved successfully.", "data": [ { "jid": "user2@domain.com", "name": "User Two" } ] } ``` ``` -------------------------------- ### Connect to Server with Username and Password Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Establishes a connection to the server using the username and password obtained from the registration response. Successful connection returns a status code of 200. Connection status and errors are handled via a callback listener. ```javascript await SDK.connect(`USERNAME`, `PASSWORD`); ``` -------------------------------- ### Get User Profile API Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves the profile details of a specified user. ```APIDOC ## GET /api/users/profile/{TO_USER_JID} ### Description Fetches the profile details of a specified user. ### Method GET ### Endpoint `/api/users/profile/{TO_USER_JID}` ### Parameters #### Path Parameters - **TO_USER_JID** (String) - Required - The JID of the user whose profile details are to be retrieved. #### Query Parameters None #### Request Body None ### Request Example ```javascript await SDK.getUserProfile('user_jid_to_fetch'); ``` ### Response #### Success Response (200) - **statusCode** (Number) - Status code of the response. - **message** (String) - Success or error message. - **data** (Object) - Contains the profile details of the user. (Refer to the documentation for the exact structure of the profile details object). #### Response Example ```json { "statusCode": 200, "message": "Success", "data": { "name": "John Doe", "status": "Available", "imageUrl": "http://example.com/image.jpg", "mobileNumber": "1234567890", "email": "john.doe@example.com" } } ``` ##### Note The `userProfileListener` will also be triggered with the same response. ``` -------------------------------- ### GET /getChatsByTopicId Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/topic-based-chat Retrieves a list of recent chats filtered by a specific topic ID. ```APIDOC ## GET /getChatsByTopicId ### Description Fetches recent chats associated with a specific topic ID, supporting pagination. ### Method GET ### Parameters #### Query Parameters - **topicId** (String) - Optional - AlphaNumeric ID for the topic - **messageTime** (String) - Optional - Last message time for pagination - **limit** (Number) - Optional - Pagination limit ### Response #### Success Response (200) - **data** (Array) - List of chat objects containing message details, status, and metadata ``` -------------------------------- ### Register a New User Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Registers a new user with the provided user identifier. If a trial license key is used during initialization, the user will be registered in trial mode. The response contains username and password for subsequent connection. ```javascript await SDK.register(`USER_IDENTIFIER`); ``` -------------------------------- ### Send Text Message API Source: https://www.mirrorfly.com/docs/chat/javascript/v2/quick-start Sends a text message to another user on the MirrorFly platform. ```APIDOC ## POST /sendMessage ### Description Sends a text message to a specified recipient. ### Method POST ### Endpoint /sendMessage ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **toJid** (String) - Required - JID of the recipient user (username + "@" + xmppSocketHost). - **messageText** (String) - Required - The content of the text message. ### Request Example ```javascript await SDK.sendTextMessage({ toJid: "recipient_user_jid", messageText: "Hello, this is a test message!" }); ``` ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message - **data** (Object) - Details about the sent message. - **chatType** (String) - Chat Type - "chat" - **createdAt** (String) - Message Created Time - **deleteStatus** (Number) - Delete Status - **favouriteBy** (String) - Favourited By - User - **favouriteStatus** (Number) - Favourite status - **fromUserId** (String) - From User Id - **fromUserJid** (String) - From User Jid - **metaData** (Object) - Meta data for the message - **msgBody** (Object) - **mentionedUsersIds** (Array) - Array of mentioned users - **message** (String) - Message Body - **message_type** (String) - Message Type - **nickname** (String) - Nick name - **msgId** (String) - Unique Message Id - **msgType** (String) - Message Type - **publisherId** (String) - User Id - **timestamp** (Number) - TimeStamp - Milliseconds - **toUserId** (String) - toUser Id - **toUserJid** (String) - toUser Jid - **topicId** (String) - Topic id for the message #### Response Example ```json { "statusCode": "200", "message": "Message sent successfully", "data": { "chatType": "chat", "createdAt": "2023-04-10T10:00:00.000Z", "deleteStatus": 0, "favouriteBy": "", "favouriteStatus": 0, "fromUserId": "sender_user_id", "fromUserJid": "sender_user_jid", "metaData": {}, "msgBody": { "mentionedUsersIds": [], "message": "Hello, this is a test message!", "message_type": "text", "nickname": "" }, "msgId": "unique_message_id", "msgType": "text", "publisherId": "sender_user_id", "timestamp": 1681185232000, "toUserId": "recipient_user_id", "toUserJid": "recipient_user_jid", "topicId": "" } } ``` ``` -------------------------------- ### GET /getChatMessages Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat Retrieves the chat history for a specific group. Supports both standard retrieval and paginated results. ```APIDOC ## GET /getChatMessages ### Description Fetches chat history for a selected group. Can be used with or without pagination parameters. ### Method GET ### Endpoint SDK.getChatMessages(GROUP_JID, POSITION, LAST_ROW_ID, LIMIT) ### Parameters #### Path Parameters - **GROUP_JID** (JID String) - Required - JID of the target group. #### Query Parameters - **POSITION** (String) - Optional - Pagination direction ("up" or "down"). - **LAST_ROW_ID** (String) - Optional - The ID of the last message retrieved. - **LIMIT** (Number) - Optional - Maximum number of messages to return. ### Request Example await SDK.getChatMessages("91XXXXXXXXXX@mix.domain.com", "down", "12345", 10); ### Response #### Success Response (200) - **statusCode** (Number) - Status code of the request. - **message** (String) - Success or error message. - **data** (Array) - List of chat message objects. #### Response Example { "statusCode": 200, "message": "Success", "data": [] } ``` -------------------------------- ### POST /createGroup Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat Creates a new group with a specified name, initial participants, and an optional profile image. ```APIDOC ## POST /createGroup ### Description Creates a new group. Triggers a groupProfileListener callback upon success. ### Method POST ### Parameters #### Request Body - **GROUP_NAME** (String) - Required - Group Name - **USER_JID** (Array) - Required - Array of User JID - **GROUP_IMAGE** (File/String) - Optional - Profile Image URL or file ### Request Example { "GROUP_NAME": "Developers", "USER_JID": ["user1@xmpp.com", "user2@xmpp.com"], "GROUP_IMAGE": "url_to_image" } ``` -------------------------------- ### POST /set-media-encryption Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Configures media encryption settings for storage server uploads. ```APIDOC ## POST /set-media-encryption ### Description Enables or disables media encryption for files stored on the server. By default, encryption is disabled. ### Method POST ### Parameters #### Request Body - **REASON** (Boolean) - Required - true to enable media encryption, false to disable it. ### Request Example await SDK.setMediaEncryption(true); ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message ``` -------------------------------- ### Get Current User JID Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Fetches the unique JID (Jabber ID) of the currently logged-in user. ```APIDOC ## GET /users/me/jid ### Description Fetches the unique JID (Jabber ID) of the currently logged-in user. ### Method GET ### Endpoint /users/me/jid ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message - **userJid** (JID String) - JID of the User #### Response Example ```json { "statusCode": 200, "message": "User JID retrieved successfully.", "userJid": "current_user@domain.com" } ``` ``` -------------------------------- ### Get User's Last Seen Time Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves the last seen timestamp for a specified user. ```APIDOC ## GET /users/lastseen ### Description Retrieves the last seen timestamp for a specified user. ### Method GET ### Endpoint /users/lastseen ### Parameters #### Query Parameters - **TO_USER_JID** (JID String) - Required - JID of the To User ### Request Example ```javascript await SDK.getLastSeen(`TO_USER_JID`); ``` ### Response #### Success Response (200) - **statusCode** (Number) - Status Code - **message** (String) - Success/Error Message - **data** (Object) - Last Seen Details Object #### Response Example ```json { "statusCode": 200, "message": "Last seen retrieved successfully.", "data": { "lastSeen": "2023-10-27T10:00:00Z" } } ``` ``` -------------------------------- ### Create Group using MirrorFly SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat Initializes a new group chat with a specified name, list of participants, and an optional profile image. Triggers a groupProfileListener callback upon successful creation. ```javascript await SDK.createGroup("GROUP_NAME", ["USER_JID"], "GROUP_IMAGE"); ``` -------------------------------- ### Implement Presence, Friends, Profile, and Message Listeners Source: https://www.mirrorfly.com/docs/chat/javascript/v2/callback-listeners Standard listener implementations for tracking user presence, contact lists, profile details, and incoming chat messages. These functions receive specific response objects containing relevant data for UI updates. ```JavaScript function presenceListener(response) { console.log("Presence Listener", response); } function friendsListListener(response) { console.log("Friends List", response); } function userProfileListener(response) { console.log("User Profile Details Listener", response); } function messageListener(response) { console.log("Message Listener", response); } ``` -------------------------------- ### User Connection API Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Establishes a connection to the server using the username and password obtained from the registration response. Emits connection status and errors via a callback. ```APIDOC ## POST /api/users/connect ### Description Connects to the server using provided username and password. Emits connection status and errors through the `connectionListener` callback. ### Method POST ### Endpoint `/api/users/connect` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **USERNAME** (String) - Required - The username obtained from the registration response. - **PASSWORD** (String) - Required - The password obtained from the registration response. ### Request Example ```javascript await SDK.connect('USERNAME', 'PASSWORD'); ``` ### Response #### Success Response (200) - **statusCode** (Number) - Status code indicating successful connection. - **message** (String) - Message indicating login success. #### Response Example ```json { "message": "Login Success", "statusCode": 200 } ``` ``` -------------------------------- ### Manage User Settings Source: https://www.mirrorfly.com/docs/chat/javascript/v2/responses Methods to retrieve and update user-specific configurations, such as enabling or disabling permanent chat archiving. ```javascript await SDK.getUserSettings(); await SDK.updateUserSettings(true); ``` -------------------------------- ### Download Profile Image Source: https://www.mirrorfly.com/docs/chat/javascript/v2/groupchat/retrieve-group Obtains the media file URL for a profile image. It requires a file token and optionally accepts a file key, returning a blob URL and blob information. ```javascript await SDK.getMediaURL("9178680804311682318992048B1cCBm6F6WIVI38s9r1a.jpg", "AllRgIXOXZAHxAzxxggTTQvapoxpzEfx"); ``` -------------------------------- ### Send Audio Message using MirrorFly JavaScript SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat This snippet demonstrates how to send an audio message. It requires the recipient's JID, message type, and file parameters. The file can be a local file or a URL. Optional parameters include caption, duration, file size, file name, reply message ID, and mentioned users. If the audio attachment feature is unavailable, a 403 error will be thrown. ```javascript await SDK.sendFileMessage({ toJid: "", messageType: "audio", fileMessageParams: { file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.) caption: "", }, replyMessageId: "", mentionedUsersIds: [] }); ``` -------------------------------- ### Send Video Message using MirrorFly JavaScript SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat This snippet demonstrates how to send a video message. It requires the recipient's JID, message type, and file parameters. The file can be a local file or a URL. Optional parameters include caption, duration, file size, file name, reply message ID, and mentioned users. If the video attachment feature is unavailable, a 403 error will be thrown. ```javascript await SDK.sendFileMessage({ toJid: "", messageType: "video", fileMessageParams: { file: FILE, // Or .fileUrl = FILE_URL caption: "", }, replyMessageId: "", mentionedUsersIds: [] }); ``` -------------------------------- ### Handle Media Download Progress in JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/callback-listeners Tracks the progress of media message downloads. The listener is activated when a media message is being downloaded and returns the message ID and download progress percentage. ```javascript function mediaDownloadListener(response) { console.log("Media Download Listener", response); } ``` -------------------------------- ### Get List of Users I Have Blocked Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves a list of all users that the current user has blocked. Returns status code, message, and an array of blocked user details. ```javascript await SDK.getUsersIBlocked(); ``` -------------------------------- ### Resume Media Download in JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/managing-message Resumes a paused media download using the SDK.downloadMedia method with appropriate callback handlers for status updates. ```javascript await SDK.downloadMedia(msgId, onResuming((msgId) => { // ... }), .onSuccess((response) => { // ... }), .onError((error) => { // ... }) ); ``` -------------------------------- ### Set User Profile with Image URL or File Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Sets the user's profile information including nickname, profile image (either as a URL or a file), status, mobile number, and email. Requires all parameters to be provided. ```javascript await SDK.setUserProfile("Name", "https://domain/path/image.png", "status", "1111111111", "email@domain"); ``` ```javascript await SDK.setUserProfile("Name", FILE, "status", "1111111111", "email@domain"); ``` -------------------------------- ### Get List of Users Who Have Blocked Me Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves a list of users who have blocked the current user. Returns status code, message, and an array of users who have blocked the current user. ```javascript await SDK.getUsersWhoBlockedMe(); ``` -------------------------------- ### Download Media Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/send-a-message This method allows downloading media files. It takes the message ID and callback functions for pending, success, and error states. ```APIDOC ## Download Media ### Description Used to get the media file URL for downloading. It utilizes callback functions to handle different stages of the download process. ### Method `await SDK.downloadMedia(msgId, onPending, onSuccess, onError)` ### Parameters #### Path Parameters - **msgId** (String) - Required - msgId for the download message - **onPending** (function) - Required - Pending call back - **onSuccess** (function) - Required - Download Message success call back - **onError** (function) - Required - Download Message error call back #### onSuccess Response ```json { "msgId": "" , // String "blobUrl": "", // String - blobUrl "blob": { "size" : "", // Number - size "type" : "" // String } } ``` ``` -------------------------------- ### Get Messages by Message ID Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/retrieve-messages Retrieves a specific message using its unique message ID and the chat JID. This is useful for fetching message details after receiving a message ID. ```APIDOC ## GET /messages/{messageId} ### Description Retrieves message details using the message ID. ### Method GET ### Endpoint `/messages/{messageId}` ### Parameters #### Path Parameters - **messageId** (String) - Required - The unique identifier of the message to retrieve. #### Query Parameters - **chatJid** (String) - Required - The JID of the chat the message belongs to. ### Request Example ```javascript SDK.getMessageById(`815f37b5-1f8f-4a39-8237-247c44b1b521`,`91XXXXXXXXXX@domain.com`); ``` ### Response #### Success Response (200) - **statusCode** (Number) - The status code of the response. - **message** (String) - The status message. - **data** (Object) - Contains the message details: - **chatType** (String) - Type of chat ('chat' for single, 'groupchat' for group). - **createdAt** (String) - Timestamp when the message was created. - **deleteStatus** (Number) - Indicates if the message is deleted. - **deletedBy** (String) - User ID of the person who deleted the message. - **fromUserId** (String) - ID of the user who sent the message. - **fromUserJid** (String) - JID of the sender. - **msgBody** (Object) - Contains the message content: - **message** (String) - The actual message text. - **message_type** (String) - Type of message (text, image, video, audio, file). - **mentionedUsersIds** (Array) - List of user IDs mentioned in the message (for group chats). - **nickName** (String) - Nickname of the sender. - **metaData** (Object) - Additional metadata for the message. - **topicId** (String) - ID of the topic the message belongs to. - **msgId** (String) - Unique message ID. - **msgStatus** (Number) - Status of the message. - **msgType** (String) - Type of message. - **profileUpdatedStatus** (String) - Status related to profile updates. - **publisherJid** (String) - JID of the publisher. - **publisherId** (String) - ID of the publisher. - **timestamp** (Number) - Timestamp in milliseconds. - **userId** (String) - User ID. - **userJid** (String) - User JID. - **editedStatus** (Number) - Indicates if the message has been edited. - **editMessageId** (String) - ID of the edited message. #### Response Example ```json { "statusCode": 200, "message": "Success", "data": { "chatType": "chat", "createdAt": "2023-04-11 09:23:52", "deleteStatus": 0, "deletedBy": "0", "fromUserId": "", "fromUserJid": "", "msgBody": { "message": "Hello!", "message_type": "text", "mentionedUsersIds": [], "nickName": "User" }, "metaData": {}, "topicId": "", "msgId": "815f37b5-1f8f-4a39-8237-247c44b1b521", "msgStatus": 2, "msgType": "", "profileUpdatedStatus": "", "publisherJid": "sender@domain.com", "publisherId": "sender_id", "timestamp": 1681185232000, "userId": "user_id", "userJid": "recipient@domain.com", "editedStatus": 0, "editMessageId": "" } } ``` ``` -------------------------------- ### Manage Typing Status via MirrorFly SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat Notifies group participants of a user's typing activity. Use sendTypingStatus when the user starts typing and sendTypingGoneStatus when they stop. ```javascript // Start typing await SDK.sendTypingStatus(`TO_GROUP_JID`); // Stop typing await SDK.sendTypingGoneStatus(`TO_GROUP_JID`); ``` -------------------------------- ### Create Meet Link (JavaScript) Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/message-by-meta-data Creates a meet link using the SDK. This is a prerequisite for sending a meet message. Returns a response object containing the meet link data. ```javascript SDK.createMeetLink(); ``` -------------------------------- ### Get Current User's JID Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Fetches the unique JID (Jabber ID) of the currently logged-in user. Returns status code, message, and the user's JID. ```javascript await SDK.getCurrentUserJid(); ``` -------------------------------- ### Retrieve User Metadata via SDK Source: https://www.mirrorfly.com/docs/chat/javascript/v2/responses Demonstrates the method to fetch the current user's metadata from the MirrorFly SDK. Returns a promise resolving to an object containing status code, message, and metadata fields. ```javascript await SDK.getMetaData(); ``` -------------------------------- ### Get Topics Details in JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/topic-based-chat Retrieves details for specified topics using their IDs. Accepts an array of topic IDs and returns a list of topic objects, including their metadata, ID, and name. ```javascript await SDK.getTopics(`TOPIC_IDS`); ``` -------------------------------- ### Handle Admin Block/Unblock Status for Users/Groups in JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/callback-listeners Provides the admin block status for users and groups. This allows checking the availability status of users or groups for communication. It returns the target user/group JID, ID, block status ('1' for blocked, '0' for unblocked), and chat type. ```javascript function adminBlockListener(response) { console.log("Archive Chat Listener", response); } ``` -------------------------------- ### Get User Token for API Access Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Generates and retrieves a new user token required for accessing the API. Requires username and password for authentication. Returns status code, message, and the user token. ```javascript await SDK.getUserToken(`USERNAME`, `PASSWORD`); ``` -------------------------------- ### POST /addParticipants Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat Adds one or more participants to an existing group. ```APIDOC ## POST /addParticipants ### Description Adds multiple participants to an existing group. Triggers groupProfileListener for all members. ### Method POST ### Parameters #### Request Body - **GROUP_JID** (String) - Required - Group JID - **GROUP_NAME** (String) - Required - Group Name - **USER_JID** (Array) - Required - Array of User JIDs to add ### Request Example { "GROUP_JID": "group123@mix.xmppdomain", "GROUP_NAME": "Developers", "USER_JID": ["user3@xmpp.com"] } ``` -------------------------------- ### Send Meet Message Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/send-a-message This section explains how to send a meet message. It requires creating a meet link first using `createMeetLink` and then using `sendMeetMessage` with details like recipient JID, link, scheduled time, and title. ```APIDOC ## Send Meet Message ### Description Allows sending a meet message after creating a meet link using `createMeetLink`. Includes details for the meeting such as title, link, and scheduled time. ### Caution If Group call feature is unavailable for your plan, then it will throw a 403 exception. ### Method `SDK.createMeetLink()` ### Method `await SDK.sendMeetMessage({ toJid, link, scheduledDateTime, title, mentionedUsersIds, topicId, metaData }) ` ### Parameters #### Path Parameters - **toJid** (JID String) - Required - JID of the To User/GROUP - **link** (String) - Required - Meet Link which we need to share - **scheduledDateTime** (Number (Timestamp)) - Required - Scheduled Date and Time - **title** (String) - Optional - Meet Title which we need to share - **mentionedUsersIds** (Array of String) - Optional - Array of Group Mentioned UsersIds - **topicId** (String) - Optional - Topic Id for the Message - **metaData** (String) - Optional - MetaData for the Message #### Response Format ```json { "statusCode": `STATUS_CODE`, "message": `ERROR|SUCCESS message`, "data": "ehl-niyc-wcc" } ``` #### Success Response (200) ```json { "statusCode": 200, // Number - status code "message": "", // String - Success/Error Message "data": { "chatType": "", // String - Chat Type - "chat" "createdAt": "", // String - Message Created Time "deleteStatus": "", // Number - Delete Status "favouriteBy": "", // String - Favourited By - User "favouriteStatus": "", // Number - Favourite status "fromUserId": "", // String - From User Id "fromUserJid": "", // String - From User Jid "metaData": {}, // Object - Meta data for the message "msgBody": { "meet": { "link": "ehl-niyc-wcc", // String - Link "scheduledDateTime": 1695202750020, // Number - Timestamp - Milliseconds "title": "" // String - Title }, "mentionedUsersIds": [], // Array of mentioned users "message_type": "meet", // String - Message Type "nickName": "" // String - nick name }, "msgId": "", // String - Unique Message Id "msgType": "", // String - Message Type "publisherId": "", // String - user Id "timestamp": 1681185232000, // Number - TimeStamp - Milliseconds "toUserId": "", // String - toUser Jid "toUserJid": "", // String - toUser Jid "topicId": "" // String - Topic id for the message } } ``` ``` -------------------------------- ### Get User's Last Seen Time Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves the last seen timestamp for a specified user. Requires the JID of the target user as input. Returns status code, message, and last seen details. ```javascript await SDK.getLastSeen(`TO_USER_JID`); ``` -------------------------------- ### Get Group Media Messages (No Pagination) Source: https://www.mirrorfly.com/docs/chat/javascript/v2/group-chat Fetches media messages for a specific group chat. This method is used for the initial request and retrieves a set of media messages. A caution is noted for plans where this feature might be unavailable. ```javascript await SDK.getMediaMessages(`TO_GROUP_JID`); ``` -------------------------------- ### Resume Media Upload in JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/managing-message Resumes a previously paused media upload using the SDK.resumeMediaUpload method. It requires the message ID and callback functions for progress, success, and error handling. ```javascript await SDK.resumeMediaUpload( msgId , onResuming((msgId) => { // ... }), .onSuccess((response) => { // ... }), .onError((error) => { // ... }) ); ``` -------------------------------- ### Get Group Message Info with JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/groupchat/retrieve-group Retrieves information about a specific message within a group, including how many members have received and seen it. Requires the group JID and message ID. A callback is triggered with the response data. ```javascript await SDK.getGroupMsgInfo(`GROUP_JID`, `MESSAGE_ID`); ``` -------------------------------- ### Create Topic in JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/message/topic-based-chat Creates a new topic for organizing chat conversations. Requires a topic name and optionally accepts metadata. Returns a unique topic ID upon successful creation. ```javascript await SDK.createTopic({ topicName: "", metaData: {} // Optional }); ``` -------------------------------- ### Example Response for Group JID using JavaScript Source: https://www.mirrorfly.com/docs/chat/javascript/v2/groupchat/overview This JSON object represents a successful response after requesting a Group JID. It includes a status code of 200, a success message, and the generated `userJid` which is the Group JID. ```json { "statusCode": 200, "message": "Success", "userJid": "0f617991-08d0-4474-ae6c-f070dc63bb1a@mix.xmppdomain" } ``` -------------------------------- ### Get User Profile Details Source: https://www.mirrorfly.com/docs/chat/javascript/v2/profile Retrieves the profile details of a specified user using their JID. The response includes status code, message, and the profile details object. This function also triggers a user profile listener. ```javascript await SDK.getUserProfile(`TO_USER_JID`); ```