Notifications Android

Configure Push and In-app notifications.

Push notifications via Helpshift

urbanAirshipNotif.png

Helpshift allows you to send Push notifications when an agent replies to a conversation.

Refer to the following link for documentation on GCM Push:- Google Cloud Messaging for Android

Prerequisites

Implement FCM (or the older GCM) push in your app.

For FCM, refer to the Firebase Cloud Messaging documentation.

For GCM, refer to the Google Cloud Messaging documentation.

Configure Helpshift Agent Dashboard

To enable the Helpshift system to send push notifications to your users you will have to add your GCM 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.

helpshift-push-notifications.png

For GCM users, the API key can be found at your Google API Console .show me GCM Console.png

And for FCM users, the API key can be found at your Firebase API Console .show me Firebase Console.png


Configure Helpshift Android SDK

  1. Send the device registration id to Helpshift via the Core.registerDeviceToken API

    import com.helpshift.Core;
    
    private void sendRegistrationIdToBackend() {
      // Send registrationId to Helpshift
      Core.registerDeviceToken(context, regid);
    }
    
  2. Inside your "GcmBroadcastReceiver's onReceive method" check origin is "helpshift" and pass the intent to Core.handlePush API. Please make sure that you initialize the Helpshift before calling the handlePush API.

    import com.helpshift.All;
    import com.helpshift.Core;
    import com.helpshift.exceptions.InstallException;
    
    @Override
    public void onReceive(Context context, Intent intent) {
      if(intent.getExtras().getString("origin").equals("helpshift")) {
        Core.init(All.getInstance());
        try {
           Core.install(getApplication(),
                        <API_KEY>,
                        <DOMAIN_NAME>,
                        <APP_ID>,
                        config);
          } catch (InstallException e) {
            // install credentials are incorrect
          }
        Core.handlePush(context, intent);
      }
      // Explicitly specify that GcmIntentService will handle the intent.
      ComponentName comp = new ComponentName(context.getPackageName(),
                                             GcmIntentService.class.getName());
      // Start the service, keeping the device awake while it is launching.
      startWakefulService(context, (intent.setComponent(comp)));
      setResultCode(Activity.RESULT_OK);
    }
    
  3. If you are using GCM service which provides "Bundle" argument instead of Intent, you should use Core.handlePush API which takes Bundle argument.

    @Override
    public void onMessageReceived(String from, Bundle data) {
      String origin = data.getString("origin");
      if (origin != null && origin.equals("helpshift")) {
         Core.init(All.getInstance());
         try {
           Core.install(getApplication(),
                        <API_KEY>,
                        <DOMAIN_NAME>,
                        <APP_ID>,
                        config);
         } catch (InstallException e) {
            // install credentials are incorrect
         }
        Core.handlePush(context, intent);
        Core.handlePush(this, data);
      }
    }
    
  4. If you are using FCM's new FirebaseMessagingService which provides "RemoteMessage" argument, you should use Core.handlePush API which takes a Map argument.

    @Override
    public void onMessageReceived(RemoteMessage message) {
      Map<String, String> data = message.getData();
      String origin = data.get("origin");
      if (origin != null && origin.equals("helpshift")) {
        Core.init(All.getInstance());
        try {
           Core.install(getApplication(),
                        <API_KEY>,
                        <DOMAIN_NAME>,
                        <APP_ID>,
                        config);
          } catch (InstallException e) {
            // install credentials are incorrect
          }
        Core.handlePush(context, intent);
        Core.handlePush(this, data);
      }
    }
    

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 GCM/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

The Helpshift install call supports flags for configuring the SDK's behaviour. Currently we support one flag i.e enableInAppNotification or you can use macro HS_ENABLE_IN_APP_NOTIFICATION in HelpshiftCocos2dx.h file.

In-app Notification flag

Flag
enableInAppNotification
Values
"yes" or "no" (CCString)
Default
"yes"

If you do not want the in-app notifications for replies to customer issues, please set this flag to "no". The default value of this flag is "yes" i.e in-app notifications will be enabled.

Example:

For cocos2d-x 3.x

ValueMap config;
config[HS_ENABLE_IN_APP_NOTIFICATION] = Value("yes");
HelpshiftCocos2dx::install("<YOUR_API_KEY>",
                           "<YOUR_COMPANY>.helpshift.com",
                           "<YOUR_APP_ID>",
                           config);

For cocos2d-x 2.x

cocos2d::CCDictionary *config = new cocos2d::CCDictionary();
config->setObject(new CCString("yes"), HS_ENABLE_IN_APP_NOTIFICATION);

HelpshiftCocos2dx::install("<YOUR_API_KEY>",
                           "<YOUR_COMPANY>.helpshift.com",
                           "<YOUR_APP_ID>",
                           config);

Customizing notification icons

By default the application icon is used as the notification icon. You can customize the notification icons via the config dictionary passed to the install call.

For Example:

HashMap config = new HashMap();
config.put("notificationIcon", R.drawable.notification_icon_small);
config.put("largeNotificationIcon", R.drawable.notification_icon_large);
HelpshiftBridge.install(this, // "this" should be the application object
                        "YOUR_API_KEY",
                        "<YOUR_HELPSHIFT_DOMAIN>.helpshift.com",
                        "YOUR_APP_ID",
                        config);

Customizing notification sound

By default the default device notification sound is used for helpshift notifications. You can customize the notification sound via the config dictionary passed to the install call.

For Example:

HashMap config = new HashMap();
config.put("notificationSound", R.raw.notification_sound);
HelpshiftBridge.install(this, // "this" should be the application object
                        "YOUR_API_KEY",
                        "<YOUR_HELPSHIFT_DOMAIN>.helpshift.com",
                        "YOUR_APP_ID",
                        config);

Notification channels

Applicable to SDK v1.8.0 and above.

Starting from Android Oreo, Helpshift notifications will have a default channel set as In-app Support. The name and description for this default channel can be changed by setting the following settings. If you want to customize the name and description for the default channel, you can do so by using the following resources in your strings.xml file:

<string name="hs__default_notification_channel_name">Example Support Name</string>
<string name="hs__default_notification_channel_desc">Example Support Description</string>

If you want to customize the notification channels, you can create your own custom channels and set their channel IDs in the in the config dictionary passed to the install corresponsing to following key: supportNotificationChannelId and campaignsNotificationChannelId.

For Example:

HashMap config = new HashMap();
config.put("supportNotificationChannelId", "SUPPORT_CHANNEL_ID");
config.put("campaignsNotificationChannelId", "CAMPAIGNS_CHANNEL_ID");
HelpshiftBridge.install(this, // "this" should be the application object
                        "YOUR_API_KEY",
                        "<YOUR_HELPSHIFT_DOMAIN>.helpshift.com",
                        "YOUR_APP_ID",
                        config);

Showing notification count when replies are sent to the user

If you want to show your user notifications for replies on the issues posted, you can get the notification count synchronously from cache. Example:-

int notifCount = HelpshiftCocos2dx::getNotificationCount();