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 Webex Connect platform. Use the below code to call the connect method.

📘

INFO

Once the In-App messaging is enabled in the app asset created on Webex Connect and user registration is done, the App Developer can establish a connection between the app and Webex Connect platform by calling the connect method appropriately. This enables the messages sent from Webex Connect to be received on the app. When the application is running in the background, SDK is disconnected from Webex Connect. 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 Webex Connect 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 Webex Connect 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 Webex Connect, 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, Webex Connect 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 Webex Connect 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 Webex Connect platform.

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

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

createThread

Creates a thread within the Webex Connect 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 Webex Connect 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 Webex Connect 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 Webex Connect 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 Webex Connect 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 Webex Connect 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 Webex Connect 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);

RequestNotificationPermission

Requests the system notification permission prompt to enable notifications display on Android 13 devices. This permission required for apps that target Android API level 33 to allow an app to post notifications

Parameters:

Parameter

Description

openSettings

True to display a dialog to direct users to the App's notification settings if they have declined permission before.

Sample code:

IMIconnectPlugin.requestNotificationPermission(function (isGranted) { 
  console.log("Permission isGranted : " + isGranted); 
  },
  false
);

createPostbackMessage

This method Creates an instance of ICMessage based on the parameters ICMessage and ICButton and that have been passed to this method.

Parameters:

Parameter

Type

Description

message

ICMessage

The ICMessage instance

button

ICButton

The interacted ICButton for which an ICMessage is created.

Return Value: Returns the ICMessage instance which is been created with the parameters passed.

Sample Code:

IMIconnectPlugin.createPostbackMessage(function(icMessage) {

console.log("IMIconnectPlugin.createPostbackMessage success : " + JSON.stringify(icMessage.toJSON()));

}, function(error) {

console.log("IMIconnectPlugin.createPostbackMessage failed : " + JSON.stringify(error));

}, message, button);

sendClickedEvent

This method sends a click event to the messaging manager for the selected button and with the transaction id.

Parameters:

Parameter

Type

Description

transactionId

String

The transactionId of the message

button

ICButton

The interacted ICButton for which an ICMessage is created

Sample Code:

IMIconnectPlugin.sendClickedEvent(function(result) {

console.log("IMIconnectPlugin.sendClickedEvent success : " + JSON.stringify(result));

}, function(error) {

window.alert("IMIconnectPlugin.sendClickedEvent failed" + JSON.stringify(error));

}, transactionId(), button);