Notifications Android
Configure Push and In-app notifications.
Configure push notifications via Helpshift
Helpshift enables you to send notifications to your users. This is particularly useful when you have multiple users on multiple platforms like iOS and Android. Notifications are useful to tell your users when you reply to an issue that they submitted. When the app is backgrounded, the notification that is sent from Helpshift appears as a notification.
To know more about the FCM Push, refer:- Firebase Cloud Messaging
Configure Helpshift Agent Dashboard
To enable the Helpshift system to send push notifications to your users you will have to add your FCM Key and Bundle Name via the helpshift admin interface.
Enter your Google Push notifications credentials per app, via the Settings page > App listing in the left navigation > Scroll down to Push Notifications settings section for the app.
The API key can be found at your Google API Console.
Configure the Helpshift Unity SDK to handle notifications
Push notifications
Configure FCM push notification plugins {#}
- When push is not configured, Helpshift SDK shows out-of-the-box "in-app notifications" for every message sent by Agents/Bots.
You should call
HelpshiftSdk.getInstance().registerDeviceToken ()
API only after you have configured the Helpshift dashboard for push notifications. Calling theHelpshiftSdk.getInstance().registerDeviceToken ()
API without configuring the Helpshift dashboard will stop showing out-of-the-box "in-app notifications" for the end users.
Before you begin
- Integrate Helpshift Unity Android SDK as documented here: Integration Guide
- Integrate FCM Unity Android plugin as documented here: Firebase Cloud Messaging Guide
If you have already integrated push notifications, Use the HelpshiftSdk.registerDeviceToken(string deviceToken) API to register the device token with the Helpshift SDK. Helpshift can now start sending push notifications to your app.
Once this is done, you can use the HelpshiftSdk.handlePushNotification(Dictionary<string, object> pushNotificationData) API to send the payload received in the notification.
To check whether this notification is being sent from the Helpshift's push notification service, please check the origin
field of the notification. If it is "helpshift
, the notification is a Helpshift notification.
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
HelpshiftSdk.getInstance().registerDeviceToken (token.Token);
}
public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
IDictionary<string, string> pushData = e.Message.Data;
if (pushData.ContainsKey ("origin") && pushData ["origin"].Equals ("helpshift")) {
Dictionary<string, object> hsPushData = new Dictionary<string, object>();
foreach (string key in pushData.Keys) {
hsPushData.Add (key, pushData [key]);
}
HelpshiftSdk.getInstance().handlePushNotification (hsPushData);
}
}
If your application is not running and it receives a push notification then it will start the application in background (by invoking the push notification receiver registered in java). In this case, UnityEngine might not be initialized and the C# api HelpshiftSdk.handlePushNotification
might not be useful.
If you are unable to delegate the push notification payload from the Java receiver class to C# api's then, for such cases, you can use the native Java api HelpshiftUnity.handlePush(Context context, Intent intent)
to handle push notifications from Helpshift.
There is a known issue with the Helpshift Unity SDK 4.0.0, in which a NullPointerException occurs; when the application is in the stopped state and a push notification is received and handled using the HelpshiftUnity.handlePush(context, intent);
API. Please call HelpshiftUnity.install(getApplication());
before calling HelpshiftUnity.handlePush(context, intent);
to resolve this issue.
In Java implementation of the receiver for push notifications, you can use this api as in the following example.
public class HelpshiftCustomFCMService extends ListenerService {
private static final String TAG = "Helpshift Native";
@Override
public void onMessageReceived(RemoteMessage message) {
String from = message.getFrom();
Map<String, String> data = message.getData();
Log.d(TAG, "onMessageReceived, from: " + from + ", data: " + data);
String origin = data.get("origin");
if (origin != null && origin.equals("helpshift")) {
Log.d(TAG, "Helpshift Notification received");
// Handle push with native Helpshift java apis directly.
HelpshiftUnity.handlePush(this, data);
} else {
Log.d(TAG, "Notification from non-helpshift service");
// Call super to forward the notification to the default FCM service.
super.onMessageReceived(message);
}
}
}
Refer the sample project for FCM Unity plugin integration with Helpshift SDK here.
Configure Other push notification plugins
If you are using any third party plugin for push notifications. you can use HelpshiftSdk.registerDeviceToken(string deviceToken) API to register the device token and HelpshiftSdk.handlePushNotification(Dictionary<string, object> pushNotificationData) API to send the payload received in the notification.
The following is an example to register device token:
void registrationSucceededEvent( string registrationId )
{
Debug.Log( "registrationSucceededEvent: " + registrationId );
HelpshiftSdk.getInstance().registerDeviceToken (registrationId);
}
Once this is done, you can use the HelpshiftSdk.handlePushNotification(Dictionary<string, object> pushNotificationData) API to send payload which you receive in the notificationReceivedEvent callback in your plugin.
To check whether this notification is being sent from the Helpshift's push notification service, please check the origin
field of the notification. If it is "helpshift"
, the notification is a Helpshift notification.
In-app notifications
In-app notifications are similar to notifications in the notification drawer . Unlike push notifications, they appear only when you app is running.
These notifications are sent when an agent replies to a customer's issue. Your customers can go straight into the conversation screen when they tap on the notification.
If the FCM device token is registered for push notifications, then in-app notifications will be disabled. In-app notifications are disabled to avoid duplicate notifications from both push notifications and in-app notifications.
Configuring in-app notifications
If you do not want the in-app notifications support provided by the
Helpshift SDK, please set this flag to "no". The default value of this
flag is "yes" i.e in-app notifications will be enabled.
Read more about in-app notifications in the Notifications section.
Flag | enableInAppNotification |
Values | "yes" / "no" |
Default | "yes" |
Example:
using Helpshift;
.
.
.
private HelpshiftSdk help;
this.help = HelpshiftSdk.getInstance();
Dictionary<string, string> configMap = new Dictionary<string, string>();
configMap.Add("unityGameObject", "DemoControl");
configMap.Add("enableInAppNotification", "yes");
help.install("<YOUR_API_KEY>", "<YOUR_HELPSHIFT_DOMAIN>", "<YOUR_APP_ID>", configMap);
Showing notification count when replies are sent to the user
Via Helpshift API
If you want to show your user notifications for replies sent by the Agent to their Issues, you can use notification counts provided by the Helpshift SDK. These give you the total number of unread messages and display that number as a badge. You can get notification counts asynchronously by implementing the Helpshift delegate method didReceiveUnreadMessageCount.
The notification count is fetched on-demand from the SDK cache and Helpshift's servers. However, the count from the Helpshift's servers is rate limited and its value is returned only if a subsequent call to this API is made after the reset timeout or if the user just closed the chat screen (whichever is earlier). The reset timeout is 1 minute if there is an active issue else 5 minutes if there are no active issues.
Notifications are typically displayed as badges inside your app where a user clicks on the help section. These badges can be displayed anywhere in your app's interface to tell the user that they have unread replies/messages from you.
You can implement the "didReceiveUnreadMessageCount" delegate method like the following example:
API:
using Helpshift;
.
.
.
private HelpshiftSdk help;
this.help = HelpshiftSdk.getInstance();
help.requestUnreadMessagesCount(true);
Delegate:
public void didReceiveUnreadMessagesCount(int count) {
// your code here
}
Via In-App Notifications
If you want to use the in-app notifications mechanism to get the count of unread notifications, you can implement the didReceiveInAppNotificationCount
message handler on the Game object which you have registered at the time of install.
For example
public void didReceiveInAppNotificationCount(string count) {
Debug.Log("In-app Notification count : " + count);
}