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);
      }
    }
    

Configure Urban Airship

urbanAirshipNotif.png

Helpshift enables you to use Urban Airship to send notifications to your users. This is particularly useful when you have users on multiple platforms like iOS and Android. Urban Airship provides a common framework to notify your users on any platform. 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.

Refer to the following links for Urban Airship account and documentation on GCM Push:-

For Helpshift admin interface

To enable the helpshift system to send push notifications to your users you will have to add your "Application Key" and "Application Master Secret" keys via the helpshift admin interface. If you have multiple apps within a single helpshift instance, you will have to create the same number of apps in Urban Airship. Enter your Urban Airship credentials per app, via the Settings page > App listing in the left navigation > Scroll down to Push Notifications settings section for the app.

urban-airship-push-notifications.png

You can check if your test device is registered via the admin panel on Urban Airship.

urban-airship-dev-token.png

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.

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);

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();