Unread messages

Unread messages #

When the customer service replies user’s message, user can receive a notification of unread messages, even if the AIHelp page is not currently displayed.

You can implements this function either by every-5-minutes’ polling or by third-party push.

Note:

This function has configuration in AIHelp backend. Please contact us before your integrating.

Implementation #

Call this method to start a polling job for the count of unread messages.

The count of unread messages is pulled every 5 minutes within the function. When a message is received or read by the user, the result will be returned to the caller through this interface callback.

This API requires the following parameters:

  • OnMessageCountArrivedCallback

    Required. Callback for the changes of unread message count.

// android demo code
AIHelpSupport.startUnreadMessageCountPolling(new OnMessageCountArrivedCallback() {
    @Override
    public void onMessageCountArrived(int msgCount) {
        // wirte your code here
    }
});

Now we use android & firebase to illustrate how the in-app notification works.

1、follow up Google Documentation to integrate Firebase in your app;

2、call the following method to inform AIHelp of the player’s push token and push platform

AIHelpSupport.setPushTokenAndPlatform("PUSH_TOKEN", PushPlatform.FIREBASE);

3、override onMessageReceived method in your custom FirebaseMessagingService.java, and alert your users when you receive a new message while your app is foreground:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    // Check if current application is foreground and visible to users
    if (isAppForeground()) {
        if (remoteMessage.getData() != null) {
            if ("yes".equals(remoteMessage.getData().get("elva"))) {
                // alert your users that he/she has received a new message
            }
        }
    }
}

4、AIHelp push data format is as follows:

{
    "to":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
        "body":"This is your new message content",
        "title":"customer service sends you a message.",
        "sound":"Enabled",
        "priority":"high",
        "uid":"..."
    },
    "data":{
        "body":"This is your new message content",
        "title":"customer service sends you a message.",
        "uid":"...",
        "elva":"yes",
        "entry_tag":"..."
    }
}