Send a Message

To send the message to the user, use the below methods. Different messages such as text, image, audio, video & document type messages can be sent using the below methods.

Note: When you call the methods listed below, the messageListener callback will trigger based on the method you are calling.

Text Message#

await SDK.sendTextMessage(`TO_USER_JID`, `MESSAGE_BODY`, `MESSAGE_ID`, `REPLY_TO`);

Request Param#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To User. username + "@" + xmppSocketHostJID Stringtrue
MESSAGE_BODYText Message BodyStringtrue
MESSAGE_IDText Message IdStringtrue
REPLY_TOSpecifies the Message ID of replied message (Optional)Stringfalse

Response Format:#

{
"message": "",// String - Success/Error Message
"statusCode": "" // Number - status code
}

Location Message#

await SDK.sendLocationMessage(`TO_USER_JID`, `LATITUDE`, `LONGITUDE`,`MESSAGE_ID`, `REPLY_TO` );

Request Param#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To User. username + "@" + xmppSocketHostJID Stringtrue
LATITUDElocation latitude which needs to be sentNumbertrue
LONGITUDElocation longitude which needs to be sentNumbertrue
MESSAGE_IDLocation Message IdStringfalse
REPLY_TOSpecifies the Message ID of replied message (Optional)Stringfalse

Response Format:#

{
"message": "",// String - Success/Error Message
"statusCode": "" // Number - status code
}

Contact Message#

const contacts = [
{
name: 'John Doe',// String duration
phone_number: ['9988776655', '9900884455'] // Array of String
active_status: [ 0, 1] // Array of Number (0 or 1)
msgId: '' // String (Optional)
}
];
await SDK.sendContactMessage(`TO_USER_JID`, `CONTACTS`, `REPLY_TO` );

Request Param#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To User. username + "@" + xmppSocketHostJID Stringtrue
CONTACTSlist of numbers in that contactArray of Objecttrue
REPLY_TOSpecifies the Message ID of replied message (Optional)Stringfalse

Response Format:#

{
"message": "",// String - Success/Error Message
"statusCode": "" // Number - status code
}

Media Message#

Download media service files
Download

Media Service setup in Android#

Step 1: Download the Android file from the link above,

  1. Locate the necessary Android files, and copy them into the android/app/src/main/java/com directory. Then, follow the steps below.

  2. Locate the necessary jni folder, and copy them into the android/app/ directory. Then, follow the steps below.

Step 2: open your app-level build.gradle file located at: android/app/build.gradle, add the following dependencies:

android {
ndkVersion "21.4.7075529" // must use this version only
externalNativeBuild {
cmake {
path 'jni/CMakeLists.txt'
}
}
...
}
allprojects {
repositories {
...
maven { url "https://repo.mirrorfly.com/snapshot" }
...
}
}
dependencies {
...
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
configurations {
all {
exclude group: 'org.json', module: 'json'
exclude group: 'xpp3', module: 'xpp3'
}
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'com.mirrorfly.sdk:mirrorfly-utilities:0.0.1'
...
}

Step 3: Navigate to your Android project directory: android/app/src/main/java/com/yourpackage/, Create a new Kotlin file named MFModule.kt in this directory. Add the following code snippet to the file:

Note: Please ignore this if you already have MFModule.java or MFModule.kt. Otherwise, add the following line to the existing modules: MediaService(reactContext)

package com.YOURPACKAGE
import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager
class MFModule : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
val modules: MutableList<NativeModule> = ArrayList()
modules.add(MediaService(reactContext))
return modules
}
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return emptyList()
}
}

Step 4: Download the above zip file and extract. Copy all the files inside the extracted folder and paste it inside project/android/app/src/main/java/com/[packageName]. After pasted all the files add the MFModule in MainApplication.kt file as mentioned in the below code snippet.

Note: Please ignore this if you already have.

class MainApplication : Application(), ReactApplication {
...
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
add(MFModule()) // <- Add this line
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
companion object {
private var instance: MainApplication? = null
fun getInstance(): MainApplication? {
return instance
}
}
override fun onCreate() {
...
instance = this
NativeLoader.initNativeLibs(applicationContext)
...
}
...
}

Note: Once it's all done please verify this file AnimatedFileDrawable faced as below image, please follow the video

alt text

Media Service setup in iOS#

Step 1: Modify the Podfile: Open your Podfile located in the ios folder, and inside the target YOUR_TARGET do block, add the following dependency:

target 'YOUR_TARGET' do
# Add dependency
pod 'IDZSwiftCommonCrypto', '~> 0.13.0'
end

Step 2: Download the files from the link above, locate the necessary iOS files, and add them using Add Files to [Your Project] in Xcode. Then, follow the steps below

Step 3: If you are already using the bridge header, you can skip this setup. Otherwise, please create a bridge header, Steps to Create a Bridging Header in Xcode

  1. Open Your Xcode Project

    In your React Native project, navigate to the ios folder and open the .xcworkspace file in Xcode.

  2. Add a New Swift File

    In Xcode, go to File โ†’ New โ†’ File.

    Select Swift File under the Source section and click Next.

    Name the file (e.g., Dummy.swift).

    Click Create.

  3. Automatic Pop-up for Bridging Header

    When you create the Swift file, a pop-up will appear asking: "Would you like to configure an Objective-C bridging header?"

    alt text

    Click "Create Bridging Header".

    Xcode will automatically generate a file named:

    YourProjectName-Bridging-Header.h

Note: Before implementing the method, confirm that all required dependencies and libraries are properly installed.

Media Compress#

Compress a local media file with adjustable quality using below methods.

SDK.compressImage({ uri, quality = 'medium' })
SDK.compressVideo({ uri, quality = 'medium' })

Request Param toJid,#

StatusDescriptionTypeRequired
uriThe string to access that fileStringtrue
qualityTo adjust the out put quality of the image / video, by default it will 'medium'Stringfalse

Note: We have certain limitations in quality adjustments, as indicated by the following options: best, high, medium, low, and uncompressed. These quality settings apply to both video and audio on iOS but only work for images on Android.

Usage Example:#

const compressedImage = await SDK.compressImage({
uri: 'LOCAL_FILE_PATH',
quality: 'medium'
});
console.log('Compressed Image URI:', compressedImage);
const compressedVideo = await SDK.compressVideo({
uri: 'LOCAL_FILE_PATH',
quality: 'medium'
});
console.log('Compressed Video URI:', compressedVideo);
const fileDetails = {
"extension": "jpg", //media Format
"type": "image/jpg", //media Type
"modificationTimestamp": 1734340598777, // number modificationTimestamp
"uri": "file:///Users/user/Library/Developer/CoreSimulator/Devices/9FA93417-BF50-47F6-A8E8-8ED3BA28B0CC/data/Media/DCIM/100APPLE/IMG_0012.JPG",//Image Uri
"fileSize": 2268348,//number File Size
"width": 5088, //number Width
"height": 3253, //number Height
"filename": "IMG_0012.JPG",//media FileName
"duration": 0 // number duration
}
const fileOptions = {
"msgId": "3cdb5781-43b8-e1a3-89e9-a9214e0c2474", // message Id (unique id for each message)
"caption": "",//Image caption
"duration": 0,//Image duration
"webWidth": 330,//Image webHeight
"webHeight": 211,//Image webWidth
"androidWidth": 250, //number androidWidth
"androidHeight": 160, //number androidHeight
"originalWidth": 5088, // Image originalHeight
"originalHeight": 3253,
"thumbImage": "" // base64 string make sure this image have upto 30 thousands characters
}
await SDK.sendMediaMessage(`TO_USER_JID`, `MESSAGE_ID`, `MESSAGE_TYPE`, `FILE_DETAILS`, 'FILE_OPTIONS', 'REPLY_TO'),

Request Param toJid,#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To User. username + "@" + xmppSocketHostJID Stringtrue
MESSAGE_IDMessage Id (unique id for each message, you have to pass fileOptions.msgId)Stringtrue
MESSAGE_TYPEMedia Message type image or video or audio or fileStringtrue
FILE_DETAILSMedia FileObjecttrue
FILE_OPTIONSMedia File ObjectObjecttrue
REPLY_TOSpecifies the Message ID of replied message (Optional)Stringtrue

Note: ALLOWED_ALL_FILE_FORMATS = [ 'jpg', 'jpeg', 'png', 'mp3', 'wav', 'aac', 'mpeg', 'mp4', 'doc', 'docx', 'pdf', 'xls', 'xlsx', 'txt', 'csv', 'ppt', 'zip', 'rar', 'pptx', 'acc', 'heic', 'heif', 'mov', ];

caution

The methods sendImageMessage, sendVideoMessage, sendAudioMessage, and sendDocumentMessage have been deprecated and will be removed in the future release. Migrate to method sendMediaMessage ensuring better maintainability and consistency across media types.

Response Format:#

{
statusCode: "", // Number - status code
message: "", // String - Success/Error Message
}

Download Media#

Use the below method to return local path for media attachment .

await SDK.downloadMedia(msgId);

Example Request#

SDK.downloadMedia(`815f37b5-1f8f-4a39-8237-247c44b1b521`);

Example Response#

{
"statusCode": 200,
"message": "File decrypted successfully",
"decryptedFilePath": "",
"decryptedFileSize": ""
};

Send Reply Message#

await SDK.sendTextMessage(`TO_USER_JID`, `MESSAGE_BODY`, `MESSAGE_ID`,`REPLY_TO`);

Request Param#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To User. username + "@" + xmppSocketHostJID Stringtrue
MESSAGE_BODYText Message BodyStringtrue
MESSAGE_IDText Message IdStringtrue
REPLY_TOMessage ID of Original MessageStringtrue