# Messaging

This module enables publication and receipt of In-app Messages and Push notifications. The usage of this module is optional.

This module has the following classes:

* [IMI.ICMessaging](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicmessaging)
* [IMI.ICMessagingReceiver ](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicmessagingreceiver)
* [IMI.ICMessage](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicmessage)
* [IMI.ICMediaFile: Deprecated](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicmediafile)
* [IMI.ICAttachment](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicattachment)
* [IMI.ICTopic](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiictopic)
* [IMI.ICThread](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicthread)
* [ICMediaFileManager](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicmediafilemanager)

## IMI.ICMessaging

The ICMessaging singleton class facilitates you to send and receive Live Chat / In-App Messaging messages and update the read status for Live Chat / In-App Messaging and Push.

| Public Methods     |                                                                                                                                                     |
| :----------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
| void               | [connect()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#connect)                                                                 |
| void               | [createThread(thread, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#createthread)                                       |
| void               | [closeThread()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#closethread)                                                         |
| void               | [disconnect()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#disconnect)                                                           |
| void               | [fetchTopics(filter, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchtopics)                                         |
| void               | [fetchThreads(offset, limit, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchthreads)                                |
| void               | [fetchMessages(threadId, sinceDate, limit, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchmessages)                 |
| ICConnectionStatus | [getConnectionStatus()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getconnectionstatus)                                         |
| ICMessaging        | [getInstance()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getinstance)                                                         |
| Boolean            | [getOutgoing](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getoutgoing)                                                           |
| Boolean            | [isConnected()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#isconnected)                                                         |
| void               | [publishMessage(message, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#publishmessage)                                  |
| void               | [setMessageAsRead( transactionId, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#setmessageasread)                       |
| void               | [setMessagesAsRead( transactionId, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#setmessagesasread)                     |
| void               | [setICMessagingReceiver(callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#seticmessagingreceiver)                           |
| void               | [subscribeTopic(topicId, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#subscribetopic)                                  |
| void               | [unsubscribeTopic(topicId, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#unsubscribetopic)                              |
| void               | [updateThread()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#updatethread)                                                       |
| void               | [publishTypingIndicator(icThread, started, callback)](https://imiconnect-apis-group.readme.io/docs/javascript-sdk-messaging#publishtypingindicator) |
| void               | [requestPushPermission()](#requestPushPermission\(\))                                                                                               |

This method is used to establish a connection to receive Real-Time Messages from the Webex Connect platform.\
When the connection is successful, the status events are notified through <code>ICMessagingReceiver.onConnectionStatusChanged</code>.

> 📘 Note
>
> It throws an <code>Exception</code> if a user is not registered with Webex Connect or if the Live Chat / In-App Messaging feature is not enabled in the policy.

> 📘 Note
>
> The Time-to-Live (TTL) limit is of 24 hours for In-App and Live Chat messages. Messages undelivered within this period will expire and will not be sent via MQTT or Web Sockets. To avoid loss of undelivered messages, app developers are recommended to implement '**[fetch threads](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchthreads)**' and '**[fetch messages](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchmessages)**' functionality to download these messages from the Server-Side Inbox.
>
> Note that, if Server-Side Inbox is disabled for your app asset, then these messages will be lost if they are not delivered to the customers device within 24 hours.

**Syntax:** `void connect()`

**Example:**

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    messaging.connect();
} catch (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.\
When the disconnection is successful, the status events are notified through <code>ICMessagingReceiver.onConnectionStatusChanged</code>.

> 📘
>
> The *disconnect* method throws an <code>Exception</code> if a user is not registered with Webex Connect or Live Chat / In-App Messaging feature is not enabled in the policy.

  **Syntax:** `void disconnect()`

  **Example:**

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    messaging.disconnect();
} catch (error) {
    console.log(error)
}
```

### 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.\
Results are reported through a callback.

  **Syntax:** `void fetchTopics(start, callback)`

  **Parameters:**

| Parameter | Type     | Description                        |
| :-------- | :------- | :--------------------------------- |
| start     | integer  | Specify starting index for results |
| callback  | JSObject | Specifies the callback object.     |

**Example:**

```javascript
var messaging = IMI.ICMessaging.getInstance();
var callback = {
    onSuccess: function(ictopicslist) {
        console.log("success");
        //Write your logic to read topics and subscribe/unsubscribe/publish on those topics. 
        if (ictopicslist) {
            for (var i = 0; i < ictopicslist.length; i++) {
                var icTopic = ictopicslist[i];
                console.log(icTopic.getName());

            }

        }
    },
    onFailure: function(errormsg) {
        console.log("failed to get topics");
    }

};
messaging.fetchTopics(IMI.ICAccessLevelFilter.All, callback);
```

### getConnectionStatus

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

  **Syntax:** `ICConnectionStatus getConnectionStatus()`

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

  **Example:**

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    var connectionStatus = messaging.getConnectionStatus();
    if (connectionStatus == IMI.ICConnectionStatus.Connected) {
        //write your logic here
    }
} catch (error) {
    console.log(error)
}
```

### getInstance

This method is used to get the <code>ICMessaging</code> singleton instance. The instance is created internally on demand.

  **Syntax:** `ICMessaging getInstance()`

  **Return Value:**\
  Returns the <code>ICMessaging</code> singleton instance.

  **Example:**

```javascript
var messaging = IMI.ICMessaging.getInstance();
```

### isConnected

This method is used to verify whether the Live Chat / In-App Messaging connection is established between SDK and  Webex Connect. This is a convenience method for <code>getConnectionStatus() == ICConnectionStatus.Connected</code>.

  **Syntax:** `boolean isConnected()`

  **Return Value:**\
  Returns *true* if the Live Chat / In-App Messaging connection is established between SDK and  Webex Connect.

  **Example:**

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    var isConnected = messaging.isConnected();
    if (isConnected) {
        //write your logic
    }
} catch (error) {
    console.log(error)
}
```

### publishMessage

This method is used to publish the passed <code>ICMessage</code> instance through Live Chat / In-App Messaging connection.\
The results of the operation are reported through a callback.

  **Syntax:** `void publishMessage(message, callback)`

  **Parameters:**

| Parameters | Type                             | Description                    |
| :--------- | :------------------------------- | :----------------------------- |
| message    | [ICMessage ](#section-icmessage) | Refer to ICMessage class.      |
| callback   | JSObject                         | Specifies the callback object. |

  **Example:**

```javascript
var callback = {
    onSuccess: function() {
        console.log("message sent");
    },
    onFailure: function(errormsg) {
        console.log("failed to send message");
    }
};
 var messaging = imi.ICMessaging.getInstance();
   var message = new imi.ICMessage();

   message.setMessage("Test message");
   var thread = new imi.ICThread();
   thread.setId("threadid <which is created using createThread()/came in Message>");
   thread.setTitle("cricket");
   thread.setStreamName("sports");
   message.setThread(thread);
   messaging.publishMessage(message, callback);
```

### setMessageAsRead

This method is used to update the status of the message identified by transactionId as *Read*.\
The results of the operation are reported through a callback.

  **Syntax:** `void setMessageAsRead(transactionId, callback)`

  **Parameters:**

| Parameter     | Type     | Description                        |
| :------------ | :------- | :--------------------------------- |
| transactionId | String   | Specifies a single transaction id. |
| callback      | JSObject | Specifies the callback.            |

  **Example:**

```javascript
//To send single message read status back to Webex Connect
var messageTransactionId = "<your message transaction id>";
var messaging = IMI.ICMessaging.getInstance();
var callback = {
    onSuccess: function() {
        console.log("success");

    },
    onFailure: function(errormsg) {
        console.log("failed ");
    }

};

messaging.setMessageAsRead(messageTransactionId, callback);
```

### setMessagesAsRead

This method is used to update the status of the message identified by transactionIds as *Read*.\
The results of the operation are reported through a callback.

  **Syntax:** `void setMessagesAsRead(transactionIds, callback)`

  **Parameters:**

| Parameter      | Type       | Description                            |
| :------------- | :--------- | :------------------------------------- |
| transactionIds | String \[] | Specifies an array of transaction ids. |
| callback       | JSObject   | Specifies the callback object.         |

  **Example:**

```javascript
//To send mutliple messages read status back to Webex Connect
var msgTransIds = ["transid1", "transid2", "transid3"];
var messaging = IMI.ICMessaging.getInstance();
var callback = {
    onSuccess: function() {
        console.log("success");

    },
    onFailure: function(errormsg) {
        console.log("failed ");
    }

};

messaging.setMessagesAsRead(msgTransIds, callback);
```

### setICMessagingReceiver

This method is used to set ICMessagingReceiver callback. It contains two methods. When a message is received, <code>ICMessagingReceiver.onMessageReceived </code> method is called. When a connection status is changed <code>ICMessagingReceiver.onConnectionStatusChanged </code> method is called.\
The results of the operation are reported through a callback.

  **Syntax:** `void icMsgReceiverCallback`

  **Parameters:**

| Parameter           | Type                | Description                                                                                                            |
| :------------------ | :------------------ | :--------------------------------------------------------------------------------------------------------------------- |
| icMessagingReceiver | ICMessagingReceiver | Refer to [ICMessagingReceiver.](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicmessagingreceiver) |

  **Example:**

```javascript
//To receive connect status changes and published messages
	var icMsgRecrCallback = new IMI.ICMessagingReceiver();
	icMsgRecrCallback.onConnectionStatusChanged = function(statuscode) {
		console.log("read the statuscode, based on the status do the operations");
		    if (statuscode == IMI.ICConnectionStatus.Connected) {
             //Connected
			 } else if (statuscode == IMI.ICConnectionStatus.Error) {
               //Error while connecting 
             }else if (statuscode == IMI.ICConnectionStatus.Refused) {
               //Connection lost
             } else {
                 //unknow error
             }
	};
	icMsgRecrCallback.onMessageReceived = function(icMessage) {
	    //icMessage is IMI.ICMessage object
		if (icMessage.getType() === imi.ICMessageType.Message) {
		   //here direct message  came from server(message sent from api)
                   
          } else if (icMessage.getType() === IMI.ICMessageType.ReadReceipt) {                       
			//here read receipt came from another application for device syncing(read sent from another device)

          } else if (icMessage.getType() === IMI.ICMessageType.Republish) {
            //here repulished message came from another application for device syncing (message send from  another device)          
          }
	}
	
	var messaging = IMI.ICMessaging.getInstance();
	messaging.setICMessagingReceiver();
```

### subscribeTopic

This method is used to subscribe to the topic that has *Read* access level, allowing the SDK to receive messages on that topic.\
The results of the operation are reported through a callback.

> 📘
>
> Incoming messages are received through <code>ICMessagingReceiver.onMessageReceived</code>.

  **Syntax:** `void subscribeTopic(topicId, callback)`

  **Parameters:**

| Parameter | Type     | Description                          |
| :-------- | :------- | :----------------------------------- |
| topicId   | String   | Specifies the topic Id to subscribe. |
| callback  | JSObject | Specifies the callback.              |

  **Example:**

```javascript
//To subscribe to a topic
try {
    var messaging = IMI.ICMessaging.getInstance();

    var callback = {
        onSuccess: function() {
            console.log("success");

        },
        onFailure: function(errormsg) {
            console.log("failed ");
        }

    };
    var topic = "<Topic Name>";

    messaging.subscribeTopic(topic, callback);

} catch (error) {
    console.log(error)
}
```

### unsubscribeTopic

This method is used to unsubscribe to the topic that has *Read* access level, preventing the SDK to receive messages on that topic. The messages may still be received until the callback has reported success.\
The results of the operation are reported through a callback.

  **Syntax:** `void unsubscribeTopic(topicId, callback)`

  **Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "topicId",
    "0-1": "String",
    "0-2": "Specifies the topic Id to unsubscribe.",
    "1-0": "callback",
    "1-1": "JSObject",
    "1-2": "Specifies the callback.  \n  \n`  callback = {\n    onSuccess: function(){\n    },\n    onFailure: function(){\n  }\n    };`"
  },
  "cols": 3,
  "rows": 2,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

  **Example:**

```javascript
//To unsubscribe to a topic
try {
    var messaging = IMI.ICMessaging.getInstance();

    var callback = {
        onSuccess: function() {
            console.log("success");

        },
        onFailure: function(errormsg) {
            console.log("failed ");
        }

    };
    var topic = "<Topic Name>";

    messaging.unsubscribeTopic(topic, callback);

} catch (error) {
    console.log(error)
}
```

### createThread

This method is used to create a Thread

  **Syntax:** `createThread(icThreadObject, createThreadCallback)`

  **Parameters:**

| Parameter            | Type   | Description                                     |
| :------------------- | :----- | :---------------------------------------------- |
| icThreadObject       | String | Instance of IMI.ICThread                        |
| createThreadCallback | String | Callback object                                 |
| callback             |        | Invokes to report operation success or failure. |

```javascript
var createThreadCallBack = {
                        onSuccess: function (thread) 
                        {
                            console.log(thread);
                        },
                        onFailure: function () 
                        {
                            console.log("failed to create thread")
                        }
                    };
                    Integermessaging.createThread(steamid, threadtitle, createThreadCallBack);
```

### updateThread()

Use this API to update a thread’s title.

**Syntax**: `updateThread(thread, updateThreadCallBack);`

**Parameters**:

| Parameter | Description                                           |
| :-------- | :---------------------------------------------------- |
| Thread    | Instance of ICThread object                           |
| callback  | JS object containing onSuccess and onFailure methods. |

**Sample**:

```javascript
var messaging = IMI.ICMessaging.getInstance();  
    messaging.updateThread(thread, updateThreadCallBack);
```

### closeThread

Use this API to close an existing thread

**Syntax**: `closeThread (icThreadObj, callback)`

**Parameters:**

| Parameter   | Description                                           |
| :---------- | :---------------------------------------------------- |
| icThreadObj | Instance of ICThread object                           |
| callback    | JS object containing onSuccess and onFailure methods. |

```text
var closeThreadCallBack = {
            onSuccess: function (threadObj) {
              debug('closeThreadCallBack onSuccess', threadObj);
            },
            onFailure: function (err) {
              debug("closeThreadCallBack onFailure", err);
            },
          };
          function closeThread() {
//thread = new IMI.ICThread();instance of ICThread object
thread.setReasonForStatusChange(reason);

            var messaging = IMI.ICMessaging.getInstance();
            messaging.closeThread(thread, closeThreadCallBack);
          }
```

### fetchThreads

This method is used to get a list of threads that are created and at least one message transaction completed. Results are reported through the callback.

  **Syntax:** `fetchThreads(offset, limit, callback)`

  **Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "offset",
    "0-1": "String (Integer)",
    "0-2": "Pass offset value to fetch threads from that offset value.  \n  \nDefault value is 0.",
    "1-0": "limit",
    "1-1": "Integer (mandatory parameter)",
    "1-2": "Specifies the maximum number of items that can be returned in threads array.  \n  \nDefault value is 100.",
    "2-0": "callback",
    "2-1": "Callback",
    "2-2": "Invokes to report if operation is a success or failure.  \n  \nSuccess callback returns an additional value, a positive value indicating more threads on the server.  \n  \n`unread_msg_count`: Each thread object returns this based upon “server_inbox_version” in policy.  \n  \n`onFetchThreadsSuccess(threads, hasMoreThreads)`"
  },
  "cols": 3,
  "rows": 3,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

```javascript Sample Code
var messaging = IMI.ICMessaging.getInstance();
    messaging.fetchThreads(offset, limit, fetchThreadsCallback);
var fetchThreadsCallback = {

onSuccess: (threads, hasMore) => {

console.log('fetchThreads:onSuccess:threads ', threads);

}

},

onFailure: (error) => {

console.log('fetchThreadsCallback: errormsg: ', error);

},

};

```

### fetchMessages

This method is used to get a list of messages from the Connect platform. All results are reported through the callback.

  **Syntax:** `fetchMessages(threadId, beforeDate, limit, callback)`

  **Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "threadId",
    "0-1": "String",
    "0-2": "Specifies the ThreadId value.",
    "1-0": "beforeDate",
    "1-1": "Date",
    "1-2": "Specifies the date since the messages must be returned. This value is optional; if nothing is passed then it is considered as current Date Time.",
    "2-0": "limit",
    "2-1": "Integer",
    "2-2": "Specifies the maximum number of items that can be returned in messages array.  \n  \nDefault value is 100",
    "3-0": "callback",
    "3-1": "Callback",
    "3-2": "Invokes to report if operation is a success or failure.  \n  \n**totalCount**: `fetchMessagesCallback` returns total number of messages for the userid/thread.  \n  \n`fetchMessagesSuccess(messages: any[], totalCount)`"
  },
  "cols": 3,
  "rows": 4,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

```javascript
var messaging = IMI.ICMessaging.getInstance();
                    var messagesCallBack = {
                        onSuccess: function (messages) {
                        },
                        onFailure: function () {
                            console.log("failed to get messages");
                        }
                    };
                    messaging.fetchMessages(threadId, beforeDate, limit, callback);
```

### fetchUnreadThreadCount

This method is used to get the count of threads that have unread messages.

  **Syntax:** `fetchUnreadThreadCount(callback)`

  **Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Decsription",
    "0-0": "callback",
    "0-1": "Callback",
    "0-2": "Invokes to report if operation is a success or failure.  \n  \n**Count**: returns the unread thread count for user  \n  \n`fetchUnreadThreadCountSuccess(count)`"
  },
  "cols": 3,
  "rows": 1,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

```javascript
var messaging = IMI.ICMessaging.getInstance();
    messaging.fetchUnreadThreadCount(callback);
```

### getSDKVersion

This method gets the SDK version being used.

  **Syntax:** `getSDKVersion()`

  **Returns:** string version of SDK

```javascript
this.sdkVersion = "v" + IMIconnectPlugin.getSDKVersion();
```

### publishTypingIndicator

Facilitates publication of typing start/stop indicator events to the Webex Connect platform.

* If Typing Indicator is triggered within the 5-second interval, SDK will suppress the event and return callback.onFailure.

**Syntax:**

```javascript
let m = IMI.ICMessaging.getInstance();

let callback = {

        onSuccess: (data) => console.log("SENT typing indicator", data),

        onFailure: (err) => console.log("ERROR sending typing indicator", err),

    };

  m.publishTypingIndicator(icThread, true, callback);
```

**Parameters**

| Parameter | Type            | Description                                                           |
| :-------- | :-------------- | :-------------------------------------------------------------------- |
| icThread  | ICThread        | The thread on which the event should occur.                           |
| started   | boolean         | Pass true to indicate a typing start event or false for a stop event. |
| callback  | Callback object | A callback object containing onSuccess and onFailure method.          |

> 🚧 Typing Indicator Throttling Notice
>
> To optimize network usage, the SDK throttles typing indicator events and will send a "typingStart" or "typingStop" event at most once every 5 seconds, even if the publishTypingIndicator() method is called more frequently.
>
> App Developers should account for this behavior and avoid relying on every call resulting in a network event. Instead, use this method as a signal to indicate intent, understanding that the SDK may suppress intermediate events to reduce traffic.

### requestPushPermission()

Requests the browser’s permission prompt to allow Push Notifications in supported browsers. The callback method gets called with the permission picked by the user. Possible values for this string are granted, denied and default.

This method needs to be called manually only if the shouldRequestNotificationPermission value is set to false in the Configuration file imi-environments.js. If shouldRequestNotificationPermission is true, this method is automatically invoked after user registration.

Browser may or may not display a prompt based upon user’s existing selection.

**Syntax:** `IMI.ICMessaging.getInstance().requestPushPermission(callback)`

**Example:**

```json JavaScript
function requestPushPermission() {
          var callback = {
            onSuccess: function (data) {
              console.log("requestPushPermission::onSuccess", data);
            }
          };	
          IMI.ICMessaging.getInstance().requestPushPermission(callback);
        }
```

**Parameters**

| Parameters | Type   | Description                                    |
| :--------- | :----- | :--------------------------------------------- |
| callback   | Object | Invoked to report the result of the operation. |

## IMI.ICMessagingReceiver

This class allows the interception of incoming messages and Live Chat / In-App Messaging connection status changes. The default class provides standard message handling. You must invoke <code>setICMessagingReceiver</code> to set <code>ICMessagingReceiver</code> callback.

[block:html]
{
  "html": "<!DOCTYPE html>\n<html>\n<head>\n<style>\ntable, th, td {\n    border: 1px solid #ccc;\n    border-collapse: collapse;\n}\nth, td {\n    padding: 5px;\n    text-align: left;\n}\nth{\nbackground-color:#ccc;\n}\n</style>\n</head>\n<body>\n\n\n<table style=\"width:100%\">\n  <tr>\n    <th colspan=\"2\">Public Methods</th>\n \n  </tr>\n    <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-on-connection-status-changed\">onConnectionStatusChanged(status)</a></td>\n  </tr>\n      <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-on-message-received\">onMessageReceived(message)</a></td>\n  </tr>  \n</table>\n\n</body>\n</html>\n\n"
}
[/block]

### onConnectionStatusChanged

This method is invoked whenever there is a change to the Live Chat / In-App Messaging connection status.

  **Syntax:** `void onConnectionStatusChanged(status)`

  **Parameters:**

| Parameter | Type                                                                                                     | Description                        |
| :-------- | :------------------------------------------------------------------------------------------------------- | :--------------------------------- |
| status    | [ICConnectionStatus](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getconnectionstatus) | Refer to ICConnectionStatus class. |

### onMessageReceived

This method is invoked whenever a new Live Chat / In-App Messaging message is received.

  **Syntax:** `void onMessageReceived(message)`

  **Parameters:**

| Parameter | Type                                           | Description               |
| :-------- | :--------------------------------------------- | :------------------------ |
| message   | [ICMessage](https://developers.webexconnect.io/imiconnect-apis/docs/messaging-1#section-icmessage) | Refer to ICMessage class. |

## IMI.ICMediaFile

This class is **deprecated**.\
This class exposes data relating to media file attachments that are received through Live Chat / In-App Messaging and used to attach media files to outgoing messages.

[block:html]
{
  "html": "<!DOCTYPE html>\n<html>\n<head>\n<style>\ntable, th, td {\n    border: 1px solid #ccc;\n    border-collapse: collapse;\n}\nth, td {\n    padding: 5px;\n    text-align: left;\n}\nth{\nbackground-color:#ccc;\n}\n</style>\n</head>\n<body>\n\n\n<table style=\"width:100%\">\n  <tr>\n    <th colspan=\"2\">Public Methods</th>\n \n  </tr>\n  <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-content-type\">getContentType()</a></td>\n  </tr>\n    <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-duration\">getDuration()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-latitude\">getLatitude()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-longitude\">getLongitude()</a></td>\n  </tr>\n        <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-preview\">getPreview()</a></td>\n  </tr>\n        <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-size\">getSize()</a></td>\n  </tr>\n          <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-url\">getURL()</a></td>\n  </tr>\n          <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-content-type\">setContentType(icContentType)</a></td>\n  </tr>\n            <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-duration\">setDuration(duration)</a></td>\n  </tr>\n          <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-latitude\">setLatitude(latitude)</a></td>\n  </tr>\n            <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-longitude\">setLongitude(longitude)</a></td>\n  </tr>\n              <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-preview\">setPreview(preview)</a></td>\n  </tr>\n              <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-size\">setSize(size)</a></td>\n  </tr>\n              <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-url\">setURL(url)</a></td>\n  </tr>\n</table>\n\n</body>\n</html>\n\n"
}
[/block]

### getContentType

This method is used to get the content type such as image/jpeg.

  **Syntax:** `String getContentType()`

  **Return Value:**\
  Returns the content type such as image or jpg.

### getDuration

This method is used to get the duration of the applicable audio and video files.

  **Syntax:** `long getDuration()`

  **Return Value:**\
  Returns the duration of the audio and video files.

### getLatitude

This method is used to get the latitude of the location passed in a message.

  **Syntax:** `double getLatitude()`

  **Return Value:**\
  Returns the latitude of the location.

### getLongitude

This method is used to get the longitude of the location passed in a message.

  **Syntax:** `double getLongitude()`

  **Return Value:**\
  Returns the longitude of the location.

### getPreview

This method is used to get the preview thumbnail as a string.

  **Syntax:** `String getPreview()`

  **Return Value:**\
  Returns the preview thumbnail as a string.

### getSize

This method is used to get the file size in bytes.

  **Syntax:** `long getSize()`

  **Return Value:**\
  Returns the file size in bytes.

### getURL

This method is used to get the URL of the media file.

  **Syntax:** `String getURL()`

**Return Value**: This method returns the URL.

### setContentType

This method is used to set the content type as [IMI.ICContentType](https://developers.imiconnect.io/docs/enumerations#imiiccontenttype). The method should be called when creating new ICAttachment object.

**Syntax:** `void setContentType(icContentType)`

**Parameters:**

| Parameter     | Type              | Description                 |
| :------------ | :---------------- | :-------------------------- |
| icContentType | IMI.ICContentType | Specifies the content type. |

### setDuration

This method is used to set the duration of the audio and video files.

  **Syntax:** `void setDuration(duration)`

  **Parameters:**

| Parameter | Type | Description                             |
| :-------- | :--- | :-------------------------------------- |
| duration  | long | Specifies the duration in milliseconds. |

### setLatitude

This method is used to set the latitude of the location passed in a message.

  **Syntax:** `void setLatitude(latitude)`

  **Parameters:**

| Parameter | Type   | Description                             |
| :-------- | :----- | :-------------------------------------- |
| latitude  | double | Specifies the latitude of the location. |

### setLongitude

This method is used to set the longitude of the location passed in a message.

  **Syntax:** `void setLongitude(longitude)`

  **Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| longitude | double | Specifies the longitude of the location. |

### setPreview

This method is used to set the preview of the media file.

  **Syntax:** `void setPreview(preview)`

  **Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| preview   | String | Specifies the preview of the media file. |

### setSize

This method is used to set the size of the file in bytes.

  **Syntax:** `void setSize(size)`

  **Parameters:**

| Parameter | Type | Description                              |
| :-------- | :--- | :--------------------------------------- |
| size      | long | Specifies the size of the file in bytes. |

### setURL

This method is used to set the URL of the media file.

  **Syntax:** `void setURL(url)`

  **Parameters:**

| Parameter | Type   | Description                      |
| :-------- | :----- | :------------------------------- |
| url       | String | Specifies the URL for the media. |

## IMI.ICAttachment

This class exposes data relating to media file attachments that are received through Live Chat / In-App Messaging and used to attach media files to outgoing messages.

[block:html]
{
  "html": "<!DOCTYPE html>\n<html>\n<head>\n<style>\ntable, th, td {\n    border: 1px solid #ccc;\n    border-collapse: collapse;\n}\nth, td {\n    padding: 5px;\n    text-align: left;\n}\nth{\nbackground-color:#ccc;\n}\n</style>\n</head>\n<body>\n\n\n<table style=\"width:100%\">\n  <tr>\n    <th colspan=\"2\">Public Methods</th>\n \n  </tr>\n  <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-content-type\">getContentType()</a></td>\n  </tr>\n    <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-duration\">getDuration()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-latitude\">getLatitude()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-longitude\">getLongitude()</a></td>\n  </tr>\n        <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-longitude\">getPreview()</a></td>\n  </tr>\n        <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-size\">getSize()</a></td>\n  </tr>\n          <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-url\">getURL()</a></td>\n  </tr>\n          <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-content-type\">setContentType(contentType)</a></td>\n  </tr>\n            <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-duration\">setDuration(duration)</a></td>\n  </tr>\n          <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-duration\">setLatitude(latitude)</a></td>\n  </tr>\n            <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-longitude\">setLongitude(longitude)</a></td>\n  </tr>\n              <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-preview\">setPreview(preview)</a></td>\n  </tr>\n              <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-size\">setSize(size)</a></td>\n  </tr>\n              <tr>\n    <td>void</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-url\">setURL(url)</a></td>\n  </tr>\n</table>\n\n</body>\n</html>\n\n"
}
[/block]

### getContentType

This method is used to get the content type such as image/jpeg.

  **Syntax:** `String getContentType()`

  **Return Value:**\
  Returns the content type such as image or jpg.

### getDuration

This method is used to get the duration of the applicable audio and video files.

  **Syntax:** `long getDuration()`

  **Return Value:**\
  Returns the duration of the audio and video files.

### getLatitude

This method is used to get the latitude of the location passed in a message.

  **Syntax:** `double getLatitude()`

  **Return Value:**\
  Returns the latitude of the location.

### getLongitude

This method is used to get the longitude of the location passed in a message.

  **Syntax:** `double getLongitude()`

  **Return Value:**\
  Returns the longitude of the location.

### getPreview

This method is used to get the preview thumbnail as a string.

  **Syntax:** `String getPreview()`

  **Return Value:**\
  Returns the preview thumbnail as a string.

### getSize

This method is used to get the file size in bytes.

  **Syntax:** `long getSize()`

  **Return Value:**\
  Returns the file size in bytes.

### getURL

This method is used to get the URL of the media file.

  **Syntax:** `String getURL()`

  **Return Value:**\
  This method returns the URL.

### setContentType

This method is used to set the content type such as image/jpeg.

  **Syntax:** `void setContentType(contentType)`

  **Parameters:**

| Parameter   | Type   | Description                 |
| :---------- | :----- | :-------------------------- |
| contentType | String | Specifies the content type. |

### setDuration

This method is used to set the duration of the audio and video files.

  **Syntax:** `void setDuration(duration)`

  **Parameters:**

| Parameter | Type | Description                             |
| :-------- | :--- | :-------------------------------------- |
| duration  | long | Specifies the duration in milliseconds. |

### setLatitude

This method is used to set the latitude of the location passed in a message.

  **Syntax:** `void setLatitude(latitude)`

  **Parameters:**

| Parameter | Type   | Description                             |
| :-------- | :----- | :-------------------------------------- |
| latitude  | double | Specifies the latitude of the location. |

### setLongitude

This method is used to set the longitude of the location passed in a message.

  **Syntax:** `void setLongitude(longitude)`

  **Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| longitude | double | Specifies the longitude of the location. |

### setPreview

This method is used to set the preview of the media file.

  **Syntax:** `void setPreview(preview)`

  **Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| preview   | String | Specifies the preview of the media file. |

### setSize

This method is used to set the size of the file in bytes.

  **Syntax:** `void setSize(size)`

  **Parameters:**

| Parameter | Type | Description                              |
| :-------- | :--- | :--------------------------------------- |
| size      | long | Specifies the size of the file in bytes. |

### setURL

This method is used to set the URL of the media file.

  **Syntax:** `void setURL(url)`

  **Parameters:**

| Parameter | Type   | Description                      |
| :-------- | :----- | :------------------------------- |
| url       | String | Specifies the URL for the media. |

## IMI.ICThread

This class exposes the thread data from the Live Chat / In-App Messaging channel in a generalized form. It is also used to send Live Chat / In-App Messaging from an app to the Webex Connect platform.

| Public Methods                 |                                                                                                                       |
| :----------------------------- | :-------------------------------------------------------------------------------------------------------------------- |
| String                         | [getId](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getid)                                         |
| String                         | [getTitle](https://developers.imiconnect.io/docs/javascript-sdk-messaging#gettitle)                                   |
| String                         | [getStreamName](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getstreamname)                         |
| Date                           | [getCreatedAt](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getcreatedat)                           |
| Date                           | [getUpdatedAt](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getupdatedat)                           |
| ICThread-reasonForStatusChange | [getReasonForStatusChange()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getreasonforstatuschange) |
|                                | [setReasonForStatusChange()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#setreasonforstatuschange) |

### getId

This method is used to get thread ID information.

  **Syntax:** `String getId()`

  **Return Value:** Returns the thread ID information.

### getTitle

This method is used to get the thread title.

  **Syntax:** `String getTitle()`

  **Return Value:** Returns the thread title.

### getStreamName

This method is used to get the stream name to communicate to the Connect platform.

  **Syntax:** `String getStreamName()`

  **Return Value:** Returns the stream name.

### getCreatedAt

This method is used to get the thread created date on the Connect platform.

  **Syntax:** `Date getCreatedAt()`

  **Return Value:** Returns the thread created date on the Connect platform.

### getUpdatedAt

This method is used to get the thread updated date on the Connect platform.

  **Syntax:** `Date getUpdatedAt()`

  **Return Value:** Returns the thread updated date on the Connect platform.

## IMI.ICMediaFileManager

## uploadFile

This method is used to check the status of the file upload.

**Syntax:**`uploadFile(file, file.type, callback)`

**Return Value:** `Returns the file upload status.`

## onFileUploadComplete

This method is used to execute the callback method after the file upload is complete.

**Syntax:**`onFileUploadComplete: function(file, mediaId, error, resp)`

```Text Sample code
onFileUploadComplete: function(file, mediaId, error, resp){
      if(error){
             console.log(error);
       } else{
             $("#mediaid").val(mediaId);
             $('#imgPreviewThumb').src("data:image/png;base64," + resp.preview);
       }
}
```

## Messaging

This module enables publication and receipt of In-app Messages and Push notifications. The usage of this module is optional.

This module has the following classes:

* [IMI.ICMessaging](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#imiicmessaging)
* [IMI.ICMessagingReceiver ](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#imiicmessagingreceiver)
* [IMI.ICMediaFile: Deprecated](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#imiicmediafile)
* [IMI.ICAttachment](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#imiicattachment)
* [IMI.ICTopic](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#imiictopic)
* [IMI.ICThread](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#imiicthread)

## IMI.ICMessaging

The ICMessaging singleton class facilitates you to send and receive Live Chat / In-App Messaging messages and update the read status for Live Chat / In-App Messaging and Push.

| Public Methods     |                                                                                                                                                                     |
| :----------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|                    | [connect()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#section-connect)                                                                     |
|                    | [disconnect()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#disconnect)                                                                       |
|                    | [fetchTopics(filter, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchtopics)                                                         |
| ICConnectionStatus | [getConnectionStatus()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-connection-status)                                               |
| ICMessaging        | [getInstance()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference)                                                                                 |
| boolean            | [isConnected()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#isconnected)                                                                         |
|                    | [publishMessage(message, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#publishmessage)                                                  |
|                    | [setMessageAsRead( transactionId, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#setmessageasread)                                       |
|                    | [setMessagesAsRead( transactionId, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#setmessagesasread)                                     |
|                    | [setICMessagingReceiver( callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#seticmessagingreceiver)                                          |
|                    | [subscribeTopic(topic, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#subscribetopic)                                                    |
|                    | [unsubscribeTopic(topic, callback)](https://developers.imiconnect.io/docs/javascript-sdk-messaging#unsubscribetopic)                                                |
|                    | [createThread](https://developers.imiconnect.io/docs/javascript-sdk-messaging#createthread)                                                                         |
|                    | [fetchThreads](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchthreads)                                                                         |
|                    | [fetchMessages](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchmessages)                                                                       |
| Boolean            | [getOutgoing](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getoutgoing)                                                                           |
|                    | [setOutgoing](https://developers.imiconnect.io/docs/javascript-sdk-messaging#setoutgoing)                                                                           |
|                    | [fetchStreams](https://developers.imiconnect.io/docs/javascript-sdk-messaging#fetchstreams)                                                                         |
|                    | [sendClickedEvent(messageTransactionId, icButton, callback)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#sendclickedevent)                   |
|                    | [createPostbackMessage(icMessage, icButton)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#createpostbackmessage-function-icmessage-icbutton-) |

## deleteMessage

Use this method to delete the given message transaction id from the Webex Connect platform

| Parameter            | Description                      |
| :------------------- | :------------------------------- |
| messageTransactionId | Tid of the message to be deleted |

**Syntax:** `deleteMessage(messageTransactionId, callback);`

```javascript
var callback = {
    onSuccess: function (tid) {
      debug("message deleted", tid);
    },
    onFailure: function (error) {
      debug("failed", error);
    },
  };
  
  
  var messaging = IMI.ICMessaging.getInstance();
    messaging.deleteMessage(tid, callback);
```

## connect

This method is used to establish a connection to receive Real-Time Messages from the Webex Connect platform.\
When the connection is successful, the status events are notified through <code>ICMessagingReceiver.onConnectionStatusChanged</code>.

> 📘
>
> It throws an <code>Exception</code> if a user is not registered with Webex Connect or if the RTM feature is not enabled in the policy.

**Syntax:** `connect()`

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    messaging.connect();
} catch (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.\
When the disconnection is successful, the status events are notified through <code>ICMessagingReceiver.onConnectionStatusChanged</code>.

> 📘
>
> The *disconnect* method throws an <code>Exception</code> if a user is not registered with Webex Connect or RTM feature is not enabled in the policy.

**Syntax:** `disconnect()`

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    messaging.disconnect();
} catch (error) {
    console.log(error)
}
```

## 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.

Results are reported through a callback.

**Syntax:** `fetchTopics(start, callback)`

**Parameters:**

| Parameter | Type     | Description                         |
| :-------- | :------- | :---------------------------------- |
| start     | Integer  | Refer to ICAccessLevelFilter class. |
| callback  | JSObject | Specifies the callback object.      |

```javascript
var messaging = IMI.ICMessaging.getInstance();
var callback = {
    onSuccess: function(ictopicslist) {
        console.log("success");
        //Write your logic to read topics and subscribe/unsubscribe/publish on those topics. 
        if (ictopicslist) {
            for (var i = 0; i < ictopicslist.length; i++) {
                var icTopic = ictopicslist[i];
                console.log(icTopic.getName());

            }

        }
    },
    onFailure: function(errormsg) {
        console.log("failed to get topics");
    }

};
messaging.fetchTopics(start, callback);
```

## getConnectionStatus

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

**Syntax:** `ICConnectionStatus getConnectionStatus()`

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

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    var connectionStatus = messaging.getConnectionStatus();
    if (connectionStatus == IMI.ICConnectionStatus.Connected) {
        //write your logic here
    }
} catch (error) {
    console.log(error)
}
```

## getInstance

This method is used to get the <code>ICMessaging</code> singleton instance. The instance is created internally on demand.

**Syntax:** `ICMessaging getInstance()`

**Return Value:** Returns the <code>ICMessaging</code> singleton instance.

```javascript
var messaging = IMI.ICMessaging.getInstance();
```

## isConnected

This method is used to verify whether the RTM connection is established between SDK and  Webex Connect. This is a convenience method for <code>getConnectionStatus() == ICConnectionStatus.Connected</code>.

**Syntax:** `boolean isConnected()`

**Return Value:** Returns *true* if the RTM connection is established between SDK and  Webex Connect.

```javascript
var messaging = IMI.ICMessaging.getInstance();
try {
    var isConnected = messaging.isConnected();
    if (isConnected) {
        //write your logic
    }
} catch (error) {
    console.log(error)
}
```

## publishMessage

This method is used to publish the passed <code>ICMessage</code> instance through Live Chat / In-App Messaging connection.\
The results of the operation are reported through a callback.

**Syntax:** `publishMessage(message, callback)`

**Parameters:**

| Parameters | Type                             | Description                    |
| :--------- | :------------------------------- | :----------------------------- |
| message    | [ICMessage ](#section-icmessage) | Refer to ICMessage class.      |
| callback   | JSObject                         | Specifies the callback object. |

```javascript
var callback = {
    onSuccess: function() {
        console.log("message sent");
    },
    onFailure: function(errormsg) {
        console.log("failed to send message");
    }
};
 var messaging = IMI.ICMessaging.getInstance();
   var message = new IMI.ICMessage();

   message.setMessage("Test message");
   var thread = new IMI.ICThread();
   thread.setId("threadid <which is created using createThread()/came in Message>");
   thread.setTitle("cricket");
   thread.setStreamName("sports");
   message.setThread(thread);
   messaging.publishMessage(message, callback);
```

## setMessageAsRead

This method is used to update the status of the message identified by transactionId as *Read*. The results of the operation are reported through a callback.

**Syntax:** `setMessageAsRead(transactionId, callback)`

**Parameters:**

| Parameter     | Type     | Description                        |
| :------------ | :------- | :--------------------------------- |
| transactionId | string   | Specifies a single transaction id. |
| callback      | JSObject | Specifies the callback.            |

```javascript
//To send single message read status back to Webex Connect
var messageTransactionId = "<your message transaction id>";
var messaging = IMI.ICMessaging.getInstance();
var callback = {
    onSuccess: function() {
        console.log("success");

    },
    onFailure: function(errormsg) {
        console.log("failed ");
    }

};

messaging.setMessageAsRead(messageTransactionId, callback);
```

## setMessagesAsRead

This method is used to update the status of the message identified by transactionIds as *Read*. The results of the operation are reported through a callback.

**Syntax:** `setMessagesAsRead(transactionIds, callback)`

**Parameters:**

| Parameter      | Type       | Description                            |
| :------------- | :--------- | :------------------------------------- |
| transactionIds | string \[] | Specifies an array of transaction ids. |
| callback       | JSObject   | Specifies the callback object.         |

```javascript
//To send mutliple messages read status back to Webex Connect
var msgTransIds = ["transid1", "transid2", "transid3"];
var messaging = IMI.ICMessaging.getInstance();
var callback = {
    onSuccess: function() {
        console.log("success");

    },
    onFailure: function(errormsg) {
        console.log("failed ");
    }

};

messaging.setMessagesAsRead(msgTransIds, callback);
```

## setICMessagingReceiver

This method is used to set ICMessagingReceiver callback. It contains two methods. When a message is received, <code>ICMessagingReceiver.onMessageReceived </code> method is called. When a connection status is changed <code>ICMessagingReceiver.onConnectionStatusChanged </code> method is called.\
The results of the operation are reported through a callback.

**Syntax:** `setICMessagingReceiver(callback)`

**Parameters:**

| Parameter | Type                | Description                   |
| :-------- | :------------------ | :---------------------------- |
| callback  | ICMessagingReceiver | Refer to ICMessagingReceiver. |

```javascript
//To receive connect status changes and published messages
	var icMsgRecrCallback = new IMI.ICMessagingReceiver();
	icMsgRecrCallback.onConnectionStatusChanged = function(statuscode) {
		console.log("read the statuscode, based on the status do the operations");
		    if (statuscode == IMI.ICConnectionStatus.Connected) {
             //Connected
			 } else if (statuscode == IMI.ICConnectionStatus.Error) {
               //Error while connecting 
             }else if (statuscode == IMI.ICConnectionStatus.Refused) {
               //Connection lost
             } else {
                 //unknow error
             }
	};
	icMsgRecrCallback.onMessageReceived = function(icMessage) {
	    //icMessage is IMI.ICMessage object
		if (icMessage.getType() === IMI.ICMessageType.Message) {
		   //here direct message  came from server(message sent from api)
                   
          } else if (icMessage.getType() === IMI.ICMessageType.ReadReceipt) {                       
			//here read receipt came from another application for device syncing(read sent from another device)

          } else if (icMessage.getType() === IMI.ICMessageType.Republish) {
            //here repulished message came from another application for device syncing (message send from  another device)          
          }
	}
	
	var messaging = IMI.ICMessaging.getInstance();
	messaging.setICMessagingReceiver(icMsgRecrCallback);
```

## subscribeTopic

This method is used to subscribe to the topic that has *Read* access level, allowing the SDK to receive messages on that topic.\
The results of the operation are reported through a callback.

> 📘
>
> Incoming messages are received through <code>ICMessagingReceiver.onMessageReceived</code>.

**Syntax:** `subscribeTopic(topic, callback)`

**Parameters:**

| Parameter | Type     | Description                            |
| :-------- | :------- | :------------------------------------- |
| topic     | string   | Specifies the topic name to subscribe. |
| callback  | JSObject | Specifies the callback.                |

```javascript
//To subscribe to a topic
try {
    var messaging = IMI.ICMessaging.getInstance();

    var callback = {
        onSuccess: function() {
            console.log("success");

        },
        onFailure: function(errormsg) {
            console.log("failed ");
        }

    };
    var topic = "<Topic Name>";

    messaging.subscribeTopic(topic, callback);

} catch (error) {
    console.log(error)
}
```

## unsubscribeTopic

This method is used to unsubscribe to the topic that has *Read* access level, preventing the SDK to receive messages on that topic. The messages may still be received until the callback has reported success.\
The results of the operation are reported through a callback.

**Syntax:** `unsubscribeTopic(topic, callback)`

**Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "topic",
    "0-1": "string",
    "0-2": "Specifies the topic name to unsubscribe.",
    "1-0": "callback",
    "1-1": "JSObject",
    "1-2": "Specifies the callback.  \n  \n`  callback = {\n    onSuccess: function(){\n    },\n    onFailure: function(){\n  }\n    };`"
  },
  "cols": 3,
  "rows": 2,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

```javascript
//To unsubscribe to a topic
try {
    var messaging = IMI.ICMessaging.getInstance();

    var callback = {
        onSuccess: function() {
            console.log("success");

        },
        onFailure: function(errormsg) {
            console.log("failed ");
        }

    };
    var topic = "<Topic Name>";

    messaging.unsubscribeTopic(topic, callback);

} catch (error) {
    console.log(error)
}
```

## createThread

This method is used to create a thread based on <code>streamId</code> and <code>threadTitle</code> and send the result in a callback.

**Syntax:** `createThread(streamId, threadtitle, createThreadCallBack)`

**Parameters:**

| Parameter   | Type   | Description                                     |
| :---------- | :----- | :---------------------------------------------- |
| streamId    | string | Identity of the stream.                         |
| threadTitle | string | Title of the thread.                            |
| callback    |        | Invokes to report operation success or failure. |

```javascript
var createThreadCallBack = {
                        onSuccess: function (thread) 
                        {
                            console.log(thread);
                        },
                        onFailure: function () 
                        {
                            console.log("failed to create thread")
                        }
                    };
                    messaging.createThread(steamid, threadtitle, createThreadCallBack);
```

## fetchThreads

This method is used to get a list of threads that are created and at least one message transaction completed. Results are reported through the callback.

**Syntax:** `fetchThreads(offset, limit, callback)`

**Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "offset",
    "0-1": "string (mandatory parameter)",
    "0-2": "Pass offset value to fetch threads from that offset value.  \n  \nDefault value is 0.",
    "1-0": "limit",
    "1-1": "Integrer (mandatory parameter)",
    "1-2": "Specifies the maximum number of items that can be returned in threads array.  \n  \nDefault value is 100.",
    "2-0": "callback",
    "2-1": "Callback",
    "2-2": "Invokes to report if operation is a success or failure.  \n  \nSuccess callback returns an additional value, a positive value indicating more threads on the server.  \n  \n`unread_msg_count`: Each thread object returns this based upon “server_inbox_version” in policy.  \n  \n`onFetchThreadsSuccess(threads, hasMoreThreads)`"
  },
  "cols": 3,
  "rows": 3,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

```javascript
var messaging = IMI.ICMessaging.getInstance();
    messaging.fetchThreads(offset, limit, callback);
```

## fetchThread

This method is used to retrieve a particular thread by threadId. Results are reported through the callback

**Syntax**:  `messaging.fetchThread(threadId,  fetchThreadCallback);`

**Parameters:**

| Parameter | Type     | Description                                                                                                                                             |
| :-------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ |
| threadId  | string   | Specify threadId to retrieve                                                                                                                            |
| callback  | Callback | Callback object containing onSuccess and onFailure methods. Returns thread object if found else returns null in onSuccess. Returns onFailure otherwise. |

**Sample Code**:

```javascript
fetchThreadCallback = {
          onSuccess: (thread) => {
            console.log('fetchThread:onSuccess', thread);
            if (thread) {
              console.log(thread);
            }
            else
              console.log("No thread found with ID: ", document.querySelector('#txtThreadIdForFetchThread').value);
          },
          onFailure: (error) => {
            console.log('fetchThread: errormsg: ', error);
          },
        };

var messaging = IMI.ICMessaging.getInstance();
          messaging.fetchThread(threadId, fetchThreadCallback);

```

## fetchMessages

This method is used to get a list of messages from the Webex Connect platform. All results are reported through the callback.

**Syntax:** `fetchMessages(threadId, beforeDate, limit, callback)`

**Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "threadId",
    "0-1": "string",
    "0-2": "Specifies the ThreadId value.",
    "1-0": "beforeDate",
    "1-1": "Date",
    "1-2": "Specifies the date since the messages must be returned. This value is optional; if nothing is passed then it is considered as current Date Time.",
    "2-0": "limit",
    "2-1": "Integer",
    "2-2": "Specifies the maximum number of items that can be returned in messages array.  \n  \nDefault value is 100",
    "3-0": "calback",
    "3-1": "Callback",
    "3-2": "Invokes to report if operation is a success or failure.  \n  \n**totalCount**: `fetchMessagesCallback` returns total number of messages for the userid/thread.  \n  \n`fetchMessagesSuccess(messages: any[], totalCount)`",
    "4-0": "isOutgoing",
    "4-1": "Boolean",
    "4-2": "Indicates if the message is mobile originated if the value is true."
  },
  "cols": 3,
  "rows": 5,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

```javascript
var messaging = IMI.ICMessaging.getInstance();
                    var messagesCallBack = {
                        onSuccess: function (messages) {
                        },
                        onFailure: function () {
                            console.log("failed to get messages");
                        }
                    };
                    messaging.fetchMessages(threadId, beforeDate, limit, callback);
```

## fetchUnreadThreadCount

This method is used to get the count of threads that have unread messages.

**Syntax:** `fetchUnreadThreadCount(callback)`

**Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Decsription",
    "0-0": "callback",
    "0-1": "Callback",
    "0-2": "Invokes to report if operation is a success or failure.  \n  \n**Count**: returns the unread thread count for user  \n  \n`fetchUnreadThreadCountSuccess(count)`"
  },
  "cols": 3,
  "rows": 1,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

```javascript
var messaging = IMI.ICMessaging.getInstance();
    messaging.fetchUnreadThreadCount(callback);
```

## getSDKVersion

This method gets the SDK version being used.

**Syntax:** `getSDKVersion()`

**Returns:** string version of SDK

```javascript
this.sdkVersion = "v" + IMI.getSDKVersion();
```

## sendClickedEvent()

Use this method to send Clicked Event to Webex Connect platform

| Parameter            | Description                                               |
| :------------------- | :-------------------------------------------------------- |
| messageTransactionId | transactionId of the original message                     |
| icButton             | The ICButton instance that triggered this call            |
| callback             | The callback sample code is provided in the below example |

**Sample Code**:

```javascript
var submitClickPostbackCallback = {
        onSuccess: (icButton) => {
            console.log(`"${icButton.getTitle()}" clicked!`);
        },
        onFailure: (errormsg) => {
            console.log(errormsg);
        },	
    };
messaging.sendClickedEvent(message.getTransactionId(), icButton, this.submitClickPostbackCallback
```

## createPostbackMessage()

Creates ICMessage instance for Incoming message Interactive/Quick Replies button

| Parameter | Description                                    |
| :-------- | :--------------------------------------------- |
| icMessage | Original Message object                        |
| icButton  | The ICButton instance that triggered this call |

**Sample Code**:

```javascript
var publishMessageCallback = 
    { onSuccess: (message) => { 
      //do something 
    }, 
     onFailure: (errormsg) => { 
       //do something 
     }, 
    }; 
let postbackQuickReplyMO = IMI.ICMessaging.getInstance().createPostbackMessage(message, icButton) 
messaging.publishMessage(postbackQuickReplyMO, 
                         publishMessageCallback);
```

## IMI.ICMessagingReceiver

This class allows the interception of incoming messages and RTM connection status changes. The default class provides standard message handling. You must invoke <code>setICMessagingReceiver</code> to set <code>ICMessagingReceiver</code> callback.

| Public Methods |                                                                                                                                   |
| :------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
|                | [onConnectionStatusChanged(status)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#onconnectionstatuschanged) |
|                | [onMessageReceived(message)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#onmessagereceived)                |

## onConnectionStatusChanged

This method is invoked whenever there is a change to the RTM connection status.

**Syntax:** `onConnectionStatusChanged(status)`

**Parameters:**

| Parameter | Type                                                                                                          | Description                        |
| :-------- | :------------------------------------------------------------------------------------------------------------ | :--------------------------------- |
| status    | [ICConnectionStatus](https://developers.imiconnect.io/docs/javascript-sdk-enumerations#imiicconnectionstatus) | Refer to ICConnectionStatus class. |

## onMessageReceived

This method is invoked whenever a new RTM message is received.

**Syntax:** `onMessageReceived(message)`

**Parameters:**

| Parameter | Type                                                         | Description               |
| :-------- | :----------------------------------------------------------- | :------------------------ |
| message   | [ICMessage](https://developers.imiconnect.io/docs/icmessage) | Refer to ICMessage class. |

## IMI.ICMessage

This class exposes message data from RTM and Push channels in a generalized form and is also used to send Real-Time Messages from an app to the Webex Connect platform.

**Parameters**:

| Public Methods       |                                                                                                                         |
| :------------------- | :---------------------------------------------------------------------------------------------------------------------- |
|                      | [getAttachments()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getattachments)                   |
| string               | [getCategory()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getcategory)                         |
| string               | [getChannel()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getchannel)                           |
| JSObject             | [getCustomTags()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getcustomtags)                     |
|                      | [getDeliveredAt()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getdelivered)                     |
| JSObject             | [getExtras()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getextras)                             |
| IMI.ICMediaFile\[]   | [getMedia()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getmedia)                               |
| string               | [getMessage()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getmessage)                           |
| IMI.ICQuickReplyData | [getQuickReplyData()](#getQuickReplyData)                                                                               |
| boolean              | [getReadAt()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getreadat)                             |
| string               | [getReplyTo()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getreplyto)                           |
| boolean              | [getReadAt()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getreadat)                             |
|                      | [getRelatedTransactionId()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getrelatedtransactionid) |
|                      | [getInteractiveData()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getinteractivedata)           |
| string               | [getSenderId()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getsenderid)                         |
|                      | [getSubmittedAt()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getsubmitted)                     |
|                      | [getThread()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getthread)                             |
| string               | [getTopic()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#gettopic)                               |
| string               | [getTransactionId()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#gettransactionid)               |
|                      | [getType()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#gettype)                                 |
| string               | [getUserId()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#getuserid-1)                           |
|                      | [setAttachments()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#setattachments)                   |
|                      | [setCustomTags(tags)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#setcustomtags)                 |
|                      | [setMedia(files)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#setmedia)                          |
|                      | [setMessage(message)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#setmessage)                    |
|                      | [setRelatedTransactionId()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#setrelatedtransactionid) |
|                      | [setSenderId(senderId)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#setsenderid)                 |
|                      | [setQuickReplyData(icQuickReplyData)](#setQuickReplyData\(icQuickReplyData\))                                           |
| string               | [setTopic(topic)](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#settopic)                          |
|                      | [setThread()](https://developers.imiconnect.io/docs/javascript-sdk-api-reference#setthread)                             |
| string               | [getTemporaryId()](#getTemporaryId\(\))                                                                                 |

## getCategory

This method is used to get the category of the interactive message.

**Syntax:** `String getCategory()`

**Return Value:** Returns the category of the message.

## getChannel

This method is used to get the channel on which the message was received.

**Syntax:** `String getChannel()`

**Return Value:** Returns the channel.

## getCustomTags

This method is used to get the custom or developer specified data that was sent as part of the message payload.

**Syntax:** `JSObject getCustomTags()`

**Return Value:** Returns the custom tags sent along with the message payload.

## getExtras

This method is used to get the supplementary data that was sent as part of the message payload. The format of this data is controlled by the Webex Connect platform.

**Syntax:** `JSObject getExtras()`

**Return Value:** Returns the supplementary data that was sent along with the message payload.

## getMedia

This method is used to get the media files that are attached to the message.

**Syntax:** `IMI.ICMediaFile[] getMedia()`

**Return Value:** Returns the media files that ware attached to the message.

## getMessage

This method is used to get the content of the message that is displayed to the end-users.

**Syntax:** `String getMessage()`

**Return Value:** Returns the text message that is displayed to the end-users.

## getQuickReplyData

This method is used to return ICQuickReplyData instance that was sent as part of the message.

**Syntax:**  icMessage.getQuickReplyData()

**Return Value:** IMI.ICQuickReplyData instance.

## getReplyTo

This method is used to get the topic to which the reply should be sent. This method is not applicable to Push messaging.

**Syntax:** `String getReplyTo()`

**Return Value:** Returns the topic to which reply should be sent.

## getSenderId

This method is used to get the senderId an arbitrary identifier that is set by the sender of the message. This method is not applicable to Push messaging.

**Syntax:** `String getSenderId()`

**Return Value:** Returns the senderid of the message.

## getTopic

This method is used to get the topic on which the message was received. This method is not applicable to Push messaging.

**Syntax:** `String getTopic()`

**Return Value:** Returns the topic on which the message was received.

## getTransactionId

This method is used to get the transaction id that uniquely identifies the message transaction within the Webex Connect platform.

**Syntax:** `String getTransactionId()`

**Return Value:** Returns the transaction id that identifies the message transaction.

## getUserId

This method is used to get the user id from which the message is originated. This method is not applicable to Push messaging.

**Syntax:** `String getUserId()`

**Return Value:** Returns the user id from which the message is originated.

## setCustomTags

This method is used to set the custom tags object to be sent with an outgoing RTM. This method is not applicable to Push messaging.

**Syntax:** `setCustomTags(tags)`

**Parameters:**

| Parameter | Type     | Description             |
| :-------- | :------- | :---------------------- |
| tags      | JSObject | Specifies the JSObject. |

## setMedia

This method is used to set the media file attachments to be sent with an outgoing RTM. This method is not applicable to Push messaging.

**Syntax:** `setMedia(files)`

**Parameters:**

| Parameter | Type                                                                                             | Description                    |
| :-------- | :----------------------------------------------------------------------------------------------- | :----------------------------- |
| files     | [IMI.ICMediaFile](https://developers.imiconnect.io/docs/javascript-sdk-messaging#imiicmediafile) | Refer to IMI.ICMediaFile class |

## setMessage

This method is used to set the content of the text message to be sent with an outgoing RTM. This method is not applicable to Push messaging.

**Syntax:** `setMessage(message)`

**Parameters:**

| Parameter | Type   | Description                                |
| :-------- | :----- | :----------------------------------------- |
| message   | string | Specifies the content of the text message. |

## setSenderId

This method is used to set the senderid to be sent with an outgoing RTM. This is arbitrary information such as a simple tag. This method is not applicable to Push messaging.

**Syntax:** `setSenderId(senderId)`

**Parameters:**

| Parameter | Type   | Description              |
| :-------- | :----- | :----------------------- |
| senderId  | string | Specifies the sender id. |

## setQuickReplyData(icQuickReplyData)

This method is used to set the value of ICQuickReplyData that needs to be sent as part of the message.

**Syntax:**  icMessage.setQuickReplyData(icQuickReplyData)

**Parameter:** ICQuickReplyData instance

## setTopic

This method is used to set the topic on which the message should be published. This method is not applicable to Push messaging.

**Syntax:** `String setTopic(topic)`

**Parameters:**

| Parameter | Type   | Description          |
| :-------- | :----- | :------------------- |
| topic     | string | Specifies the topic. |

## getAttachments

This method is used to get the attachment files that are attached to the message.

**Syntax:** `ICAttachment[] getAttachments()`

**Return Type:** Returns the attachment files attached to the message.

## getThread

This method is used to get the thread details specified in the message.

**Syntax:** `ICThread getThread()`

**Return Type:** Returns the thread details that were specified in the message.

## getSubmitted

This method is used to get the message submitted date to the Webex Connect platform.

**Syntax:** `Date getSubmittedAt()`

**Return Type:** Returns the message submitted date to the Webex Connect platform.

## getDelivered

This method is used to get the message delivered date to the device.

**Syntax:** `Date getDeliveredAt()`

**Return Type:** Returns the message delivered date to the device.

## getReadAt

This method is used to get the message read date at the device.

**Syntax:** `Date getReadAt()`

**Return Type:** Returns the message read date at the device.

## getType

This method is used to get the message type.

**Syntax:** `ICMessageType getType()`

**Return Type:** Returns the message type.

## setAttachments

This method is used to set the media file attachments to be sent with an outgoing RTM. This method is not applicable to Push messaging.

**Syntax:** `setAttachments(final ICAttachment[] attachments)`

**Parameters:**

| Parameter   | Type | Description                  |
| :---------- | :--- | :--------------------------- |
| attachments |      | Refer to ICAttachment class. |

## setThread

This method is used to set the thread details that need to be specified in the message.

**Syntax:** `setThread(final ICThread thread)`

**Parameters:**

| Parameter | Type | Description              |
| :-------- | :--- | :----------------------- |
| thread    |      | Refer to ICThread class. |

## setRelatedTransactionId

Use the property to set related transaction ID while submitting a form response.

**Syntax:**  `ICMessage.setRelatedTransactionId(relatedTransactioId)`

```javascript
message.setThread(this.thread);    
message.setRelatedTransactionId(formMT.getTransactionId());
```

## getRelatedTransactionId

This method returns a relatedTransactionID which can be used to identify original Form MO.

**Syntax:** `ICMessage. getRelatedTransactionId()`

**Returns:** `String`

## getInteractiveData()

This method returns details about the form-response.

> 📘 Note
>
> This does not return the actual form response details.

**Syntax:**  `ICMessage.getInteractiveData()`

**Returns:**  `ICInteractiveData object`

## getTemporaryId()

This method is used to get TemporaryId of an ICMessage instance. A TemporaryId is generated only for locally republished messages with status ICMessageStatus.NotSent.

Syntax:  `let id = icMessageInstance.getTemporaryId()`

Return Value:  A string representing the temporary ID of the message.

## IMI.ICMediaFile

This class is **deprecated**.\
This class exposes data relating to media file attachments that are received through RTM and used to attach media files to outgoing messages.

[block:html]
{
  "html": "<!DOCTYPE html>\n<html>\n<head>\n<style>\ntable, th, td {\n    border: 1px solid #ccc;\n    border-collapse: collapse;\n}\nth, td {\n    padding: 5px;\n    text-align: left;\n}\nth{\nbackground-color:#ccc;\n}\n</style>\n</head>\n<body>\n\n\n<table style=\"width:100%\">\n  <tr>\n    <th colspan=\"2\">Public Methods</th>\n \n  </tr>\n  <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-content-type\">getContentType()</a></td>\n  </tr>\n    <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-duration\">getDuration()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-latitude\">getLatitude()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-longitude\">getLongitude()</a></td>\n  </tr>\n        <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-preview\">getPreview()</a></td>\n  </tr>\n        <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-size\">getSize()</a></td>\n  </tr>\n          <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-url\">getURL()</a></td>\n  </tr>\n          <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-content-type\">setContentType(contentType)</a></td>\n  </tr>\n            <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-duration\">setDuration(duration)</a></td>\n  </tr>\n          <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-latitude\">setLatitude(latitude)</a></td>\n  </tr>\n            <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-longitude\">setLongitude(longitude)</a></td>\n  </tr>\n              <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-preview\">setPreview(preview)</a></td>\n  </tr>\n              <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-size\">setSize(size)</a></td>\n  </tr>\n              <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-url\">setURL(url)</a></td>\n  </tr>\n</table>\n\n</body>\n</html>\n\n"
}
[/block]

## getContentType()

This method is used to get the content type such as image/jpeg.

**Syntax:** `String getContentType()`

**Return Value:** Returns the content type such as image or jpg.

## getDuration()

This method is used to get the duration of the applicable audio and video files.

**Syntax:** `long getDuration()`

**Return Value:** Returns the duration of the audio and video files.

## getLatitude()

This method is used to get the latitude of the location passed in a message.

**Syntax:** `double getLatitude()`

**Return Value:** Returns the latitude of the location.

## getLongitude()

This method is used to get the longitude of the location passed in a message.

**Syntax:** `double getLongitude()`

**Return Value:** Returns the longitude of the location.

## getPreview()

This method is used to get the preview thumbnail as a string.

**Syntax:** `String getPreview()`

**Return Value:** Returns the preview thumbnail as a string.

## getSize()

This method is used to get the file size in bytes.

**Syntax:** `long getSize()`

**Return Value:** Returns the file size in bytes.

## getURL()

This method is used to get the URL of the media file.

**Syntax:** `String getURL()`

**Return Value:** This method returns the URL.

## setContentType()

This method is used to set the content type such as image/jpeg.

**Syntax:** `setContentType(contentType)`

**Parameters:**

| Parameter   | Type   | Description                 |
| :---------- | :----- | :-------------------------- |
| contentType | string | Specifies the content type. |

## setDuration()

This method is used to set the duration of the audio and video files.

**Syntax:** `setDuration(duration)`

**Parameters:**

| Parameter | Type | Description                             |
| :-------- | :--- | :-------------------------------------- |
| duration  | long | Specifies the duration in milliseconds. |

## setLatitude()

This method is used to set the latitude of the location passed in a message.

**Syntax:** `setLatitude(latitude)`

**Parameters:**

| Parameter | Type   | Description                             |
| :-------- | :----- | :-------------------------------------- |
| latitude  | double | Specifies the latitude of the location. |

## setLongitude()

This method is used to set the longitude of the location passed in a message.

**Syntax:** `setLongitude(longitude)`

**Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| longitude | double | Specifies the longitude of the location. |

## setPreview()

This method is used to set the preview of the media file.

**Syntax:** `setPreview(preview)`

**Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| preview   | string | Specifies the preview of the media file. |

## setSize()

This method is used to set the size of the file in bytes.

**Syntax:** `setSize(size)`

**Parameters:**

| Parameter | Type | Description                              |
| :-------- | :--- | :--------------------------------------- |
| size      | long | Specifies the size of the file in bytes. |

## setURL()

This method is used to set the URL of the media file.

**Syntax:** `setURL(url)`

**Parameters:**

| Parameter | Type   | Description                      |
| :-------- | :----- | :------------------------------- |
| url       | string | Specifies the URL for the media. |

## IMI.ICAttachment

This class exposes data relating to media file attachments that are received through RTM and used to attach media files to outgoing messages.

[block:html]
{
  "html": "<!DOCTYPE html>\n<html>\n<head>\n<style>\ntable, th, td {\n    border: 1px solid #ccc;\n    border-collapse: collapse;\n}\nth, td {\n    padding: 5px;\n    text-align: left;\n}\nth{\nbackground-color:#ccc;\n}\n</style>\n</head>\n<body>\n\n\n<table style=\"width:100%\">\n  <tr>\n    <th colspan=\"2\">Public Methods</th>\n \n  </tr>\n  <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-content-type\">getContentType()</a></td>\n  </tr>\n    <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-duration\">getDuration()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-latitude\">getLatitude()</a></td>\n  </tr>\n      <tr>\n    <td>double</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-longitude\">getLongitude()</a></td>\n  </tr>\n        <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-longitude\">getPreview()</a></td>\n  </tr>\n        <tr>\n    <td>long</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-size\">getSize()</a></td>\n  </tr>\n          <tr>\n    <td>String</td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-get-url\">getURL()</a></td>\n  </tr>\n          <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-content-type\">setContentType(contentType)</a></td>\n  </tr>\n            <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-duration\">setDuration(duration)</a></td>\n  </tr>\n          <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-duration\">setLatitude(latitude)</a></td>\n  </tr>\n            <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-longitude\">setLongitude(longitude)</a></td>\n  </tr>\n              <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-preview\">setPreview(preview)</a></td>\n  </tr>\n              <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-size\">setSize(size)</a></td>\n  </tr>\n              <tr>\n    <td></td>\n    <td><a href=\"https://developers.imiconnect.io/docs/javascript-sdk-messaging#section-set-url\">setURL(url)</a></td>\n  </tr>\n</table>\n\n</body>\n</html>\n\n"
}
[/block]

## getContentType

This method is used to get the content type such as image/jpeg.

**Syntax:** `String getContentType()`

**Return Value:** Returns the content type such as image or jpg.

## getDuration

This method is used to get the duration of the applicable audio and video files.

**Syntax:** `long getDuration()`

**Return Value:** Returns the duration of the audio and video files.

## getLatitude

This method is used to get the latitude of the location passed in a message.

**Syntax:** `double getLatitude()`

**Return Value:** Returns the latitude of the location.

## getLongitude

This method is used to get the longitude of the location passed in a message.

**Syntax:** `double getLongitude()`

**Return Value:** Returns the longitude of the location.

## getPreview

This method is used to get the preview thumbnail as a string.

**Syntax:** `String getPreview()`

**Return Value:** Returns the preview thumbnail as a string.

## getSize

This method is used to get the file size in bytes.

**Syntax:** `long getSize()`

**Return Value:** Returns the file size in bytes.

## getURL

This method is used to get the URL of the media file.

**Syntax:** `String getURL()`

**Return Value:** This method returns the URL.

## setContentType

This method is used to set the content type such as image/jpeg.

**Syntax:** `setContentType(contentType)`

**Parameters:**

| Parameter   | Type   | Description                 |
| :---------- | :----- | :-------------------------- |
| contentType | string | Specifies the content type. |

## setDuration

This method is used to set the duration of the audio and video files.

**Syntax:** `setDuration(duration)`

**Parameters:**

| Parameter | Type | Description                             |
| :-------- | :--- | :-------------------------------------- |
| duration  | long | Specifies the duration in milliseconds. |

## setLatitude

This method is used to set the latitude of the location passed in a message.

**Syntax:** `setLatitude(latitude)`

**Parameters:**

| Parameter | Type   | Description                             |
| :-------- | :----- | :-------------------------------------- |
| latitude  | double | Specifies the latitude of the location. |

## setLongitude

This method is used to set the longitude of the location passed in a message.

**Syntax:** `setLongitude(longitude)`

**Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| longitude | double | Specifies the longitude of the location. |

## setPreview

This method is used to set the preview of the media file.

**Syntax:** `setPreview(preview)`

**Parameters:**

| Parameter | Type   | Description                              |
| :-------- | :----- | :--------------------------------------- |
| preview   | string | Specifies the preview of the media file. |

## setSize

This method is used to set the size of the file in bytes.

**Syntax:** `setSize(size)`

**Parameters:**

| Parameter | Type | Description                              |
| :-------- | :--- | :--------------------------------------- |
| size      | long | Specifies the size of the file in bytes. |

## setURL

This method is used to set the URL of the media file.

**Syntax:** `setURL(url)`

**Parameters:**

| Parameter | Type   | Description                      |
| :-------- | :----- | :------------------------------- |
| url       | string | Specifies the URL for the media. |

## IMI.ICTopic

This class exposes Real Time Messaging topic data that is used to publish outgoing messages or subscribe to receive incoming messages.

| Public Methods |                                                                                                     |
| :------------- | :-------------------------------------------------------------------------------------------------- |
| ICAccessLevel  | [getAccessLevel()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getaccesslevel-1) |
| string         | [getCreatedBy()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getcreatedby-1)     |
| Date           | [getCreatedDate()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getcreateddate-1) |
| string         | [getName()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getname)                 |
| Date           | [getUpdatedDate()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#getupdateddate)   |
| boolean        | [isSubscribed()](https://developers.imiconnect.io/docs/javascript-sdk-messaging#issubscribed)       |

## getAccessLevel

This method is used to get the access level assigned to the topic.

**Syntax:** `IMI.ICAccessLevel getAccessLevel(level)`

**Return Value:** Returns the access level assigned to the topic.

## getCreatedBy

This method is used to get name who created the topic.

**Syntax:** `String getCreatedBy()`

**Return Value:** Returns the name who created the topic.

## getCreatedDate

This method is used to get the date on which the topic is created.

**Syntax:** `Date getCreatedDate()`

**Return Value:** Returns the date on which the topic is created.

## getName

This method is used to get the topic name.

**Syntax:** `String getName()`

**Return Value:** Returns the topic name.

## getUpdatedDate

This method is used to get the date on which the topic was last updated.

**Syntax:** `Date getUpdatedDate()`

\*\*Return Value:\*\*Returns the date on which the topic was last updated.

## isSubscribed

This method is used to verify whether the current user is subscribed to the topic.

\*Syntax:\*\* `Boolean isSubscribed()`

**Return Value:** Returns true if the current user is subscribed to the topic.

## IMI.ICThread

This class exposes the thread data from the In-app channel in a generalized form. It is also used to send In-app from an app to the Webex Connect platform.

[block:html]
{
  "html": "<!DOCTYPE html>\n<html>\n<head>\n<style>\ntable, th, td {\n    border: 1px solid #ccc;\n    border-collapse: collapse;\n}\nth, td {\n    padding: 5px;\n    text-align: left;\n}\nth{\nbackground-color:#ccc;\n}\n</style>\n</head>\n<body>\n<table style=\"width:100%\">\n  <tr>\n    <th colspan=\"2\">Public Methods</th>\n \n  </tr>\n    <tr>\n    <td>String</td>\n    <td><a href=\"#section-get-id\">getId</a></td>\n  </tr>\n      <tr>\n    <td>String</td>\n    <td><a href=\"#section-get-title\">getTitle</a></td>\n  </tr>\n      <tr>\n    <td>boolean</td>\n    <td><a href=\"#section-is-writable\">isWritable</a></td>\n  </tr>\n        <tr>\n    <td>String</td>\n    <td><a href=\"#section-get-stream-name\">getStreamName</a></td>\n  </tr>\n        <tr>\n    <td>Date</td>\n    <td><a href=\"#section-get-created-at\">getCreatedAt</a></td>\n  </tr>\n   <tr>\n    <td>Date</td>\n    <td><a href=\"#section-get-updated-at\">getUpdatedAt</a></td>\n  </tr>\n   <tr>\n    <td>JSON</td>\n    <td><a href=\"#section-set-extras\">setExtras</a></td>\n  </tr>\n  <tr>\n    <td>JSON</td>\n    <td><a href=\"#section-get-extras\">getExtras</a></td>\n  </tr>\n<tr>\n    <td>Number</td>\n    <td><a href=\"#section-get-unread-message-count\">getUnreadMessageCount</a></td>\n  </tr>\n  </table>\n</body>\n</html>"
}
[/block]

## getId

This method is used to get thread ID information.

**Syntax:** `String getId()`

**Return Value:** Returns the thread ID information.

## getTitle

This method is used to get the thread title.

**Syntax:** `String getTitle()`

**Return Value:** Returns the thread title.

## isWritable

This method is used to validate if a thread is writable or not. A thread is writable for Conversation thread, else (for announcement) thread it is not writable.

**Syntax:** `boolean isWritable()`

**Return Value:** Returns whether the thread is writable or not.

## getStreamName

This method is used to get the stream name to communicate to the Webex Connect platform.

**Syntax:** `String getStreamName()`

**Return Value:** Returns the stream name.

## getCreatedAt

This method is used to get the thread created date on the Webex Connect platform.

**Syntax:** `Date getCreatedAt()`

**Return Value:** Returns the thread created date on the Webex Connect platform.

## getUpdatedAt

This method is used to get the thread updated date on the Webex Connect platform.

**Syntax:** `Date getUpdatedAt()`

**Return Value:** Returns the thread updated date on the Webex Connect platform.

## setExtras

This method is used to set extra data to be associated with the thread.

**Syntax:** `JSON setExtras(extras)` //accepts any JSON object

## getExtras

This method is used to get the thread updated date on the Webex Connect platform.

**Syntax:** `JSON getExtras()`

**Return Value:** Returns the extra data associated with the thread.

## getUnreadMessageCount

This method returns the count of unread messages.

**Syntax:** `getUnreadMessageCount()`

**Return Value:** Returns the count of unread messages.

## setReasonForStatusChange

Provide reason for changing status.

**Syntax:** `ICThread.setReasonForStatusChange(reason);`

| Parameters | Description |
| :--------- | :---------- |
| reason     | string      |

## getReasonForStatusChange()

Returns reason if provided while changing status of the ICThread object.

**Syntax:** `ICThread.getReasonForStatusChange()`

```javascript
thread.setReasonForStatusChange(reason);
  messaging.closeThread(thread, closeThreadCallBack);
```