Topic Based Messaging

Topic based messaging allow push and in-app messages to be sent to all subscribers of a topic, this is useful where there is a need to broadcast the same message to many users.
Our SDK supports fetching the pre-configured topic listing, which could be used to populate a UI, and managing the users active subscriptions.

  1. Fetching topics
  2. Subscribing to topics
  3. Unsubscribing from topics
  4. Sending messages

a. Fetching Topics

Use the fetchTopics method to retrieve the list of topics configured for your application. Topics are configured using our Topic APIs.

ICMessaging.getInstance().fetchTopics(0, new ICFetchTopicsCallback()
{
  @Override
  public void onFetchTopicsComplete(final ICTopic[] topics, final boolean hasMoreData, final ICException exception)
  {
    if (exception != null)
    {
      Log.e("fetchTopics", "fetchTopics failed! Reason:" + exception.toString());
      return;
    }
    
    Log.e("fetchTopics", "fetchTopics success:");
  }
});

b. Subscribing to Topics

Subscribing to topics is performed by invoking the subscribe method with the topic id.

String topicId = "TEST";	//Topic id can be obtained from an ICTopic instance fetched using the fetchTopics method

ICMessaging.getInstance().subscribeTopic(topicId, new ICSubscribeTopicCallback() 
{
	@Override
	public void onSubscribeTopicComplete(final String topicId, final ICException exception) 
	{
		if (exception != null) 
		{
			Log.e("SubscribeTopic", exception.toString());
		} 
		else 
		{
			Log.d("SubscribeTopic", "Subscribed Successfully");
		}
	}
});

c. Unsubscribe from a Topic

To unsubscribe from a topic invoke the unsubscribeTopic method.

String topicId = "TEST";

ICMessaging.getInstance().unsubscribeTopic(topicId, new ICUnsubscribeTopicCallback() 
{
  @Override
  public void onUnsubscribeTopicComplete(final String topicId, final ICException exception) 
  {
    if (exception != null) 
    {
      Log.e("UnsubscribeTopic", exception.toString());
    } 
    else 
    {
      Log.d("UnsubscribeTopic", "Unsubscribed Successfully");
    }
  }
});

d. Sending messages

Sending messages to users who are subscribed to topics is easy, when using the Push node from a flow simply use the Topic option and supply the Topic name.

1123

Alternatively, supply the topic within the destinations array of the Messaging API:

"destination": [
    {
      "topic": "offers"
    }
  ]