Push Notifications

You can use push notifications with the Chat SDK to notify your users every time the agent sends a new message to the conversation.

Setting up the push notifications in Zendesk Chat dashboard

To set up push notifications in your dashboard, follow the guidelines in Zendesk help. After setting up pushes in the Chat dashboard, integrators will need the chat account key and the appID. These are passed into the chat initialization code:

//BaseApplication.javaChat.INSTANCE.init(applicationContext, "Your account key", "Your app identifier");

Enabling push notifications for your app

Set up Firebase

We recommend following Google's guide for setting up and configuring your Firebase app instance. See Set up a Firebase Cloud Messaging client app on Android on the Firebase website. Ensure you're set up to receive push notifications by reviewing the Handling messages section as well.

Registering your push token

If you followed the Google tutorial linked above, you should be able to access your device's Firebase token. You can pass this token to the Chat SDK by calling the registerPushToken method of the PushNotificationsProvider:

PushNotificationsProvider pushProvider = Chat.INSTANCE.providers().pushNotificationsProvider();
if (pushProvider != null) {    pushProvider.registerPushToken("YOUR FIREBASE TOKEN");}

Parsing the push notification

In your FirebaseMessagingService class, override onMessageReceived and pass the result of remoteMessage.getData() into the processPushNotification method. This will return a parsed PushData object containing the message type, title, message contents, author, and timestamp of the push notification.

class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override    onMessageReceived(RemoteMessage remoteMessage) {    super.onMessageReceived(remoteMessage);
    PushData pushData = pushNotificationsProvider.processPushNotification(remoteMessage.getData());}

Types of push notifications

The Chat SDK supports two types of push notifications:

  • New chat message notification
  • Chat has ended notification
New chat message notification
{  "aps" : {    "alert" : {      "title" : "{agent name}",      "body" : "{agent message}",    }  },  "data": {    "type" : "zd.chat.msg",    "ts" : "{millisecond timestamp (long)}"  }}
Chat has ended notification
{  "aps" : {    "alert" : {      "title-loc-key" : "ios.ZDCChat.pushChatEndedTitle",      "loc-key" : "ios.ZDCChat.pushChatEndedBody",      "loc-args" : [ "{agent name}" ]    }  },  "data": {    "type" : "zd.chat.end",    "ts" : "{millisecond timestamp (long)}"  }}

You can identify the type of a push notification by calling pushData.getType().

Note: If your account is using Agent Workspace, you will not receive a notification for the end of the Chat session. This is due to the termination of the session being different. We recommend your agent send a message before closing the chat to avoid uninformed termination.

Displaying a push notification

You can display an Android push notification by following Google's official guidelines. See Create a Notification in the Android dev docs.