Passing Extra Data

Push notifications designed in Responsys can contain extra data that is passed from Responsys to the mobile app. This feature can be used for custom behaviors other than deep-linking or rich push, which are handled automatically by the SDK.

Sending Custom Key-Value Pairs from Responsys

When designing the mobile app, marketers and mobile app developers must determine how to handle each key–value pair. Developers must code the mobile app to use the key-value data per the design, and marketers must know the values that the mobile app is expecting and how the mobile app will use the data.

To add a key-value pair:

  1. In the Custom key value section, click Add key value.

    The following picture shows where Marketers can enter the key-value pairs to pass when they create their push campaigns in Responsys.

  2. Type the key and the value in corresponding fields. Repeat for each key-value pair that you want to add.
  3. To remove a key-value pair, click x.

Handling Custom Key-Value Pairs

Step 1: Implement Custom Message Handler Service

  1. Create a custom message handler service which extends from FirebaseMessagingService class and will receive the incoming push notification payload.
                        public class MyFirebaseMessagingService extends FirebaseMessagingService {
    
                            @Override
                            public void onNewToken(String token) {
                                super.onNewToken(token);
                            }
    
                            @Override
                            public void onMessageReceived(RemoteMessage remoteMessage) {
                                super.onMessageReceived(remoteMessage);
                            }
                        }
                    
                        class MyFirebaseMessagingService : FirebaseMessagingService() {
    
                            override fun onNewToken(token: String) {
                                super.onNewToken(token)
                            }
    
                            override fun onMessageReceived(remoteMessage: RemoteMessage) {
                                super.onMessageReceived(remoteMessage)
                            }
                        }
                        
  2. Declare your service in the Manifest:
    <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>                 

Step 2: Intercept Push Notification Payload

  • When a new push notification is received by the device, the onMessageReceived() of your custom Service class is called.
  • The custom key-value pair sent from Responsys is available in the RemoteMessage instance. Use RemoteMessage.getData() to access the payload.
  • If you wish to let the Responsys SDK handle/display the notification, call PushIOManager.handleMessage().
                    @Override
                    public void onMessageReceived(RemoteMessage remoteMessage) {
                        super.onMessageReceived(remoteMessage);

                        Map<String,String> payload = remoteMessage.getData();
                                                
                        // Extract custom key-value pair
                        if(payload.containsKey("my_custom_key")){

                            String value = payload.get("my_custom_key");

                            // handle the value appropriately

                        }

                        // Pass the payload to Responsys SDK for handling the notification
                        PushIOManager pushIOManager = PushIOManager.getInstance(getApplicationContext());

                        if (pushIOManager.isResponsysPush(remoteMessage)) {
                            pushIOManager.handleMessage(remoteMessage);
                        } 
                    }
                
                    override fun onMessageReceived(remoteMessage: RemoteMessage) {
                        super.onMessageReceived(remoteMessage)
                        val payload = remoteMessage.data

                        // Extract custom key-value pair
                        if (payload.containsKey("my_custom_key")) {
                            val value = payload["my_custom_key"]

                            // handle the value appropriately
                        }

                        // Pass the payload to Responsys SDK for handling the notification
                        val pushIOManager = PushIOManager.getInstance(applicationContext)

                        if (pushIOManager.isResponsysPush(remoteMessage)) {
                            pushIOManager.handleMessage(remoteMessage)
                        }
                    }
                    

Important Note: We Strongly Recommend that Apps should let Responsys SDK handle Push Notification. App should not handle the Notification Payload directly as it contains several key attributes which are important for the internal functioning of the SDK.

Learn more

Android