Unity App Inbox

App Inbox

The CleverTap Unity SDK provides the capability to create App Inbox notifications for your users.
You can use the App Inbox provided by CleverTap or create your own.
You can design App Inbox notifications right from the dashboard.

πŸ“˜

Note

If you are using Unity SDK v3.0.0, use Clevertap instead of ClevertapBindings method.

Android

On the Android side, add the following inbox dependencies in your app's build.gradle.

//MANDATORY for App Inbox

implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.viewpager:viewpager:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'

//Optional ExoPlayer Libraries for Audio/Video Inbox Messages. Audio/Video messages will be dropped without these dependencies

implementation 'com.google.android.exoplayer:exoplayer:2.17.1'
implementation 'com.google.android.exoplayer:exoplayer-hls:2.17.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.17.1'

Unity/C#

Initializing the Inbox provides a callback to two methods inboxDidInitialize() and inboxMessagesDidUpdate()

CleverTapBinding.InitializeInbox();

Configure styling and show the inbox by following the steps below:

  1. Customize the config object and call the Inbox in the inboxDidInitialize() method
  2. Call this method on the button click which opens the CleverTap Inbox for your App
//returns callback for InitializeInbox
void CleverTapInboxDidInitializeCallback()
{
    Dictionary<string, object> StyleConfig = new Dictionary<string, object>();
		StyleConfig.Add("navBarTitle", "My App Inbox");
		StyleConfig.Add("navBarTitleColor", "#FF0000");
		StyleConfig.Add("navBarColor", "#FFFFFF");
		StyleConfig.Add("inboxBackgroundColor", "#AED6F1");
		StyleConfig.Add("backButtonColor", "#00FF00");
		StyleConfig.Add("unselectedTabColor", "#0000FF");
		StyleConfig.Add("selectedTabColor", "#FF0000");
		StyleConfig.Add("noMessageText", "No message(s)");
		StyleConfig.Add("noMessageTextColor", "#FF0000");

		//Convert the Dictionary parameters to a string and pass it to `ShowAppInbox()`
		string jsonStr = JsonConvert.SerializeObject(StyleConfig, Formatting.Indented);
		CleverTapBinding.ShowAppInbox(jsonStr);
}

πŸ“˜

Note

In the above code snippet, a custom parser(Custom JSON parser) has been used to convert the dictionary object to a string which is required to pass as parameter to CleverTapBinding.ShowAppInbox()

When a new inbox message arrives, the SDK provides the inboxMessagesDidUpdate() callback

void CleverTapInboxMessagesDidUpdateCallback()
{
    Debug.Log("unity received inbox messages updated");
}

CleverTapInboxItemClicked callback to receive data when an inbox item message is clicked.

void CleverTapInboxItemClicked(string message)
{
    Debug.Log("unity received inbox message clicked callback: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

Create your own App Inbox

You can choose to create your own App Inbox by calling the following APIs:

Initialize App Inbox

CleverTapBinding.InitializeInbox();

Show App Inbox

Use the below snippet to show default CleverTap's Inbox
CleverTapBinding.ShowAppInbox("");

Use the below snippet to show custom CleverTap's Inbox

Dictionary<string, object> StyleConfig = new Dictionary<string, object>();
StyleConfig.Add("navBarTitle", "My App Inbox");
StyleConfig.Add("navBarTitleColor", "#FF0000");
StyleConfig.Add("navBarColor", "#FFFFFF");
StyleConfig.Add("inboxBackgroundColor", "#AED6F1");
StyleConfig.Add("backButtonColor", "#00FF00");
StyleConfig.Add("unselectedTabColor", "#0000FF");
StyleConfig.Add("selectedTabColor", "#FF0000");
StyleConfig.Add("noMessageText", "No message(s)");
StyleConfig.Add("noMessageTextColor", "#FF0000");

//Convert the Dictionary parameters to a string and pass it to `ShowAppInbox()`
string jsonStr = JsonConvert.SerializeObject(StyleConfig, Formatting.Indented);
CleverTapBinding.ShowAppInbox(jsonStr);

πŸ“˜

Note

In the above code snippet, a custom parser(Custom JSON parser) has been used to convert the dictionary object to a string which is required to pass as parameter to CleverTapBinding.ShowAppInbox()

Dismiss App Inbox
To dismiss the App Inbox, add the following snippet.

CleverTapBinding.DismissAppInbox();

Get Total Inbox Message Count

CleverTapBinding.GetInboxMessageCount();

Get Total Inbox Unread Count

CleverTapBinding.GetInboxMessageUnreadCount();

Get All Inbox Messages

CleverTapBinding.GetAllInboxMessages();

Get All Inbox Unread Messages

CleverTapBinding.GetInboxMessageUnreadCount();

Get Inbox Message for the given message-id

CleverTapBinding.GetInboxMessageForId("messageId");

Delete Message for the given Single Message ID

To delete a single App Inbox message by passing a single message ID.

CleverTapBinding.DeleteInboxMessageForID("messageId");

Delete Message for the given Multiple Message IDs

To delete multiple App Inbox messages by passing a collection of message IDs.

Note: This is available only for iOS.

string[] arr = {"1608798445_1676289520","1548315289_1676289520","1608798445_1676289268", "1548315289_1676289268"};
CleverTapBinding.DeleteInboxMessagesForIDs(arr);

Mark Message as Read for the given message-id

To mark an App Inbox message read by passing a message ID.

CleverTapBinding.MarkReadInboxMessageForID("messageId");

Raise Notification Viewed event for Inbox Message
Message-id must be a string value.

CleverTapBinding.RecordInboxNotificationViewedEventForID("messageId");

Raise Notification Clicked event for Inbox Message
Message-id must be a string value.

CleverTapBinding.RecordInboxNotificationViewedEventForID("messageId");