Messaging

allowJavascriptInWebviews

This method allows JavaScript execution within WebView instances that are created by the SDK. The default value is false.

Note: Only for Android

Parameter

Type

Description

flag

Boolean

True if WebView Javascript execution should be allowed.

IMIconnectPlugin.allowJavascriptInWebviews(
                    function(result){
                        console.log(result);
                    }, 
                    true
            );

isMessageStarted

This method is used to verify whether ICMessaging is started or not.
Return Value: Returns a boolean value whether ICMessaging is started or not.

Note: Only for Android

IMIconnectPlugin.isMessageStarted(
                    function(result){
                        console.log(result);
                    }
            );

connect

This method is used to establish a connection to receive Real-Time Messages from the imiconnect platform. Use the below code to call the connect method.

📘

INFO

Once the In-App messaging is enabled in the app asset created on imiconnect and user registration is done, the App Developer can establish a connection between the app and imiconnect platform by calling the connect method appropriately. This enables the messages sent from imiconnect to be received on the app. When the application is running in the background, SDK is disconnected from imiconnect. While in the disconnected state, incoming In-App messages are not received, however when the application comes to foreground again, SDK will establish a connection with the imiconnect platform and allow messages to be received.

IMIconnectPlugin.connect(
                    function(result){
                    //result will be Boolean value.
                        console.log(result);
                    },
                    function(error){
                        console.log(error);
                    }
            );

disconnect

This method is used to disconnect the connection between the app and the imiconnect platform. If there is no active connection, then this method fails silently. Use the below method to call the disconnect.

IMIconnectPlugin.disconnect(
                    function(result){
                    //result will be Boolean value.
                        console.log(result);
                    },
                    function(error){
                        console.log(error);
                    }
            );

fetchTopics

To get a list of topics that are configured with imiconnect, you need to send the offset using the following javascript code.

Parameters:

Parameter

Type

Description

offset

Integer

Passes an offset value to fetch topics from that offset value.

var offset = 0;
IMIconnectPlugin.fetchTopics(function(topics, hasMoreData) {
console.log("Topics: " + topics + ", hasMoreData: " + hasMoreData);
}, function(errJsonObj) {
console.log("Error : " + JSON.stringify(errJsonObj));
}, offset);

📘

INFO

When the topic list is large, imiconnect will return a subset of the results. Use the offset parameter to fetch subsequent results.

👍

TIP

Use the 'hasMoreData' parameter to determine if there is additional data to fetch. Keep a track of your fetched record count to use as the offset to the next call.

subscribeTopic

To subscribe to the topic allowing the SDK to receive messages on that topic, you need to send the TopicId using the following javascript code.

IMIconnectPlugin.subscribeTopic(
                        function (result) { 
                            console.log(result); 
                        },
                        function (error) { 
                        console.log(error);
                        }, 
                        topicId);

unsubscribeTopic

To unsubscribe to the topic allowing the SDK to receive messages on that topic, you need to send the TopicId using the following javascript code.

IMIconnectPlugin.unsubscribeTopic(
                function (result) { 
                    console.log(result); 
                }, 
                function (error) { 
                    console.log(error); 
                },
                topicId);

connectionStatusChangedListener

This listener is used for activating the connection status change listener between SDK and imiconnect platform.

IMIconnectPlugin.connectionStatusChangedListener(
                      function(result){
                          console.log(result);
                      },
                      function(error){
                          console.log(error);
                      });

getConnectionStatus

This method is used to get the current connection status between the SDK and imiconnect platform.

Return Value: Returns the current connection status between the SDK and the imiconnect platform.

IMIconnectPlugin.getConnectionStatus(
                    function(result){
                          console.log(result);
                      });

createThread

Creates a thread within the imiconnect platform from the provided ICThread object.

var thread = new ICThread();
thread.setTitle("MyTitle");
thread.setCategory("MyCategory");
IMIconnectPlugin.createThread(function (thread) {
window.alert(thread.getTitle());}, function (error) {  console.log(error); }, thread);

updateThread

This method is used to update a thread.

Parameter

Type

Description

thread

ICThread

Update the passed Thread(Instance of ICThread).

IMIconnectPlugin.updateThread(function (thread) {
    window.alert(thread.getTitle());}, function (error) {  console.log(error);
                                                        }, thread);

closeThread

This method is used to close the thread.

Parameter

Type

Description

thread

ICThread

Close the passed Thread(Instance of ICThread).

IMIconnectPlugin.closeThread(function (thread) {
    window.alert(thread.getTitle());}, function (error) {  console.log(error); 
                                                        }, thread);

fetchThreads

This method is used to get a list of threads that are created before the date with limit passed and at least one message transaction completed.

📘

If you pass values for both thread category and type, then results will be fetched based on category.

Parameter

Type

Description

beforeDate

Date

Pass value to fetch Threads before that Date

limit

Integer

Pass value to limit the fetching thread count

category

String

Thread category

type

String

Thread type (Announcement/Conversation)

var beforeDate = new Date();
var limit = 30;
IMIconnectPlugin.fetchThreads(function(threads, hasMoreData) {
     var log = "[";
     for (var i = 0; i < threads.length; i++) {
         log += threads[i].getTitle() + ", ";
     }
     log += "]";
     console.log("Threads: " + log + ", hasMoreData: " + hasMoreData);
}, function(errJsonObj) {
    console.log("Error: " + JSON.stringify(errJsonObj));
}, beforeDate, limit);

fetchTopics

This method is used to get a list of topics that are configured with the imiconnect app. Use the filter parameter to control the type of topics that are returned.

IMIconnectPlugin.fetchTopics(function (topics) {
                             var text = "";
                             for (var i = 0; i < topics.length; i++) {
                             text += topics[i].getName() + "<br>";
                             }
                             window.alert(text)
                             
                             }, function (error) {  console.log(error); },{ "offset": 0 });

publishMessage

This method is used to publish the passed ICMessage instance through RTM connection.

Parameter

Type

Description

message

ICMessage

Refer to ICMessage JS class.

var message = new ICMessage();
        message.setMessage("Test Message");
        message.setThread(thread);
IMIconnectPlugin.publishMessage(function (icMessage) {
                                    console.log(JSON.stringify(icMessage.toJSON()));
                                     }, function (error) {  console.log(error); }, message);

MessageListener

Interface for listening to incoming messages

IMIconnectPlugin.messageListener(

function(messages) {
var text = "";
for (var i = 0; i < messages.length; i++) {
text += messages[i].getMessage() + "<br>";
}
console.log(text);
});

DeepLinkListener

Interface for listening deep link actions.

IMIconnectPlugin.deeplinkListener(function(resultJson) {
console.log('deeplinkListener  : ' + JSON.stringify(resultJson));
});

fetchMessages

This method is used to get a list of messages from the Connect platform.

Parameter

Type

Description

beforeDate

Date

Specifies the date before the messages needs to returned.

limit

Integer

Pass value to limit the fetching message count.

threadId

string

Specifies the value of ThreadId.

var threadId = "Thread ID";
var beforeDate = new Date();
var limit = 30;
IMIconnectPlugin.fetchMessages(function(messages, hasMoreData) {
var log = "[";
for (var i = 0; i < messages.length; i++) {
log += messages[i].getMessage() + ", ";
}
log += "]";
console.log("messages: " + log + ", hasMoreData: " + hasMoreData);
}, function(errJsonObj) {
console.log("Error: " + JSON.stringify(errJsonObj));
}, beforeDate, limit, threadId);

setMessageAsRead

This method is used to update the status of the message identified by transactionId as Read.

Parameter

Type

Description

transactionIds

String

Specifies a single transaction id.

To set a single message as reading pass single messageId

IMIconnectPlugin.setMessageAsRead(
function(result){
console.log(result);
},
function(error){
console.log(error);
}, 
transactionId
);

setMessagesAsRead

This method is used to set multiple messages as read pass array of transactionIds. To set multiple messages as read pass array of transactionIds separated by comma (,):

Parameter

Type

Description

transactionIds

String []

Specifies an array of transaction ids.

var transactionIds = [“transactionId_1”, “transactionId_2”];
IMIconnectPlugin.setMessagesAsRead(function(result) {
        console.log("setMessagesAsRead: " + JSON.stringify(result));
    }, function(error) {
        console.log("setMessagesAsRead: " + JSON.stringify(error));
    },
    transactionIds
);

deleteMessage

This method to delete the given message transaction id from the imiconnect platform.

Parameter

Type

Description

transactionId

String

The transaction id of the message.

IMIconnectPlugin.deleteMessage(function (result) {
console.log("deleteMessage : " + result);
}, function (error) {
console.log("deleteMessage : " + JSON.stringify(error));
}, transactionId);

uploadFile

This method is used to upload a file to connect the platform.

Parameter

Type

Description

filePath

String

local file path to be uploaded

IMIconnectPlugin.uploadFile(
  function (resultJSObject) { console.log(resultJSObject);  },
  function (error) {  console.log(error); },
  filePath);

isFileUploading

This method is used to check if the manager is currently uploading a file.

Parameters

Type

Description

filePath

String

The local file to be checked.

Return Value: True if the file is currently being uploaded.

IMIconnectPlugin.isFileUploading(
                            function (status) { console.log(status);  },
                            filePath);

downloadFile

This method is used to download a file from a URL.

Parameters

Type

Description

fileUrl

String

The URL of the file to be downloaded.

IMIconnectPlugin.downloadFile(
  function (resultJSObject) { console.log(resultJSObject);  },
  function (error) {  console.log(error); },
  fileUrl);

isFileDownloading

This method is used to check if the manager is currently downloading a file at a URL.

Parameters

Type

Description

fileUrl

String

The URL of the file that will be checked.

IMIconnectPlugin.isFileDownloading(
  function (status) { console.log(status);  }, 
  fileUrl);

getCachedFile

This method is used to check if a file exists for a URL.

Parameter

Type

Description

fileUrl

String

The URL of the file that will be checked.

IMIconnectPlugin.getCachedFile(
  function (filePath) { console.log(filePath);  }, 
  function (error) {  console.log(error); },
  fileUrl);

getPushToken

This method is used to get the current device push token.

IMIconnectPlugin.getPushToken(function (pushToken) {
console.log("Get Push Token: " + pushToken);             
});

processPushToken

This method is called to handle the new push registration token.

📘

Note

This method call is required only if the application developers implement their own FirebaseMessagingService and require to receive push messages from the imiconnect platform.

IMIconnectPlugin.processPushToken(function (status) {
            console.log("processPushToken Status: " + status);
        }, function (err) {
            console.log("processPushToken Failed: " + JSON.stringify(err));
        });

setPushTokenListener

IMIconnectPlugin.setPushTokenListener(function (pushToken) {
console.log('[setPushTokenListener] pushToken : ' + pushToken);                                          
});

Push token will be received by registering a setPushTokenListener implementation with IMIconnectPlugin.

processPushMesage

This method is called to handle push messages received from the imiconnect platform.

📘

Note

This method call required only if the application developers implement their own FirebaseMessagingService and require to connect SDK to process the push messages received from the imiconnect platform.

Parameter

Type

Description

pushMessage

JSON

A Push Message Payload as jsonObject

var samplePushJsonPayload = "{\"extras\":\"{\\\"sound\\\":\\\"default\\\"}\",\"priority\":\"5\",\"tid\":\"P3c383db7-ef65-460e-926e-85e58b648f52\",\"alert\":\"Message with neutral face \uD83D\uDE10\",\"title\":\"Title with neutral face \uD83D\uDE10\",\"icmessage\":\"true\"}";
         
var pushMessage = JSON.parse(samplePushJsonPayload);

IMIconnectPlugin.processPushMessage(function (a) {
                console.log("processPushMessage Success : " + a);
            }, function (err) {
                console.log("processPushMessage  : " + JSON.stringify(err));
            }, pushMessage);

isConnnectPushMessage

This helper method returns whether the message is from the imiconnect platform or not.

Parameter

Type

Description

pushMessage

String

A Push Message Payload as jsonObject

var samplePushJsonPayload = "{\"extras\":\"{\\\"sound\\\":\\\"default\\\"}\",\"priority\":\"5\",\"tid\":\"P3c383db7-ef65-460e-926e-85e58b648f52\",\"alert\":\"Message with neutral face \uD83D\uDE10\",\"title\":\"Title with neutral face \uD83D\uDE10\",\"icmessage\":\"true\"}";
         
var pushMessage = JSON.parse(samplePushJsonPayload);

IMIconnectPlugin.isConnnectPushMessage(function (status) {
            console.log("isConnnectPushMessage Status: " + status);
        }, function (err) {
            console.log("isConnnectPushMessage Failed: " + JSON.stringify(err));
        } pushMessage);

shouldAllowMessagingReceiverAutoStart (Android Only)

This method is used to allow the SDK to autostart for notification actions.

Parameter

Type

Description

allowAutoStart

Boolean

The allowAutoStart should set true to enable and false to disable autostart for notification actions.

// For Enabling Auto Start: 
IMIconnectPlugin.shouldAllowMessagingReceiverAutoStart (function(status) {
    console.log("shouldAllowMessagingReceiverAutoStart: " + status);
}, true);

// For Disabling Auto Start: 
IMIconnectPlugin.shouldAllowMessagingReceiverAutoStart (function(status) {
    console.log("shouldAllowMessagingReceiverAutoStart: " + status);
}, false);

isConnected

This method is used to check if the client is currently connected to RTM (Real Time Messaging).
Return Value: returns a boolean value whether connected or not

IMIconnectPlugin.isConnected(function (a) { 
console.log("isConnected: " + a); 
});

getHMSPushToken

This method is called to gets the current device HMS push token.

IMIconnectPlugin.getHMSPushToken(function (token) { 
    console.log("Get HMS Push Token: " + token); 
});

setHMSPushTokenListener

This method is allowed to listen for updated HMS tokens.

IMIconnectPlugin.setHMSPushTokenListener(function (token) { 
  console.log('[setHMSPushTokenListener] HMS pushToken : ' + token); 
});

regenerateMediaURL

This method is called to regenerates new media URL for given Media URL upon checking expiry. 

IMIconnectPlugin.regenerateMediaURL(function(newMediaURL) { 
    console.log("IMIconnectPlugin.regenerateMediaURL success", newMediaURL); 
}, function(err) { 
    console.log("IMIconnectPlugin.regenerateMediaURL failed", JSON.stringify(err)); 
}, mediaURL);