Message Metadata

Learn about message-specific metadata on Android

We can set the message data by accessing the Conversation object provided by the SDK. The conversation object provides a delegate that helps us intercept a message before it is sent, so developers can add a metadata dictionary into the message object.

First, set the conversation's delegate (MessageModifierDelegate).

private void addMessageModifierDelegate() {
   BrandMessenger.getConversation().setMessageModifierDelegate(new Conversation.MessageModifierDelegate() {
       @Override
       public Message beforeSend(Message message) {
           Map<String, Object> metadata = new HashMap<>();
           metadata.put("MetadataOS", "Android");
           metadata.put("FieldTwo", "test");
           message.setMetadata(metadata);
           return message;
       }

       @Override
       public Message beforeDisplay(Message message) {
           return null;
       }

       @Override
       public Message beforeNotification(Message message) {
           return null;
       }
   });
}

Lastly, in the Agent's Admin page, in Developer -> Metadata Visibility, add the Brand Messenger network. This will show the default fields like clients[0].platform. Add the fields from the dictionary like MetadataOS, and they should be visible under each message in the conversation under the metadata section.


Did this page help you?