Working with the ASAP SDK for React Native

Working with the ASAP SDK for React Native

The ASAP SDK for React Native makes help available within quick reach for the end-users of your mobile app. Using this SDK, you can add and customize an add-on that resides within your iOS/Android app and provides end-users with easy access to your:
  • Customer support team (to raise tickets or chat with support agents)
  • Knowledge base (to access help articles)
  • User community (to interact with other users of the app)
What this addition means for end-users is that they do not have to exit your app and visit your website or send an email to contact you for support. They can easily seek help right from within your app, thereby saving time and enjoying a superior customer experience.

Here's how you can add an ASAP add-on to your app, using the React Native SDK.  

Step 1: Create a mobile add-on in Zoho Desk.

To create the add-on, perform the following steps.
  1. Go to this path in Zoho Desk: Setup → Channels → ASAP.
  2. In the Setup pane on the left, under ASAP, click the button next to Mobile. The Create Mobile Add-On page appears. 

  3. Under Add-On Details, configure the following settings:
    1. Name: Name for the ASAP add-on. This name is only for reference; it does not appear anywhere on the app UI.
    2. Available for: Departments for which this ASAP add-on must be enabled
    3. Bundle ID: In the iOS/Android field, enter the bundle ID of your iOS/Android app. 
    4. Note: Bundle ID is mandatory for enabling Live Chat and sending push notifications.
    5. Live Chat: Toggle switch for enabling/disabling Live Chat.
      Note: The Live Chat component reflects the settings configured for the chat channel in your help desk portal. Therefore, any change required must be done via the Setup page in Zoho Desk.
    6. Push Notifications: Toggle switch for enabling/disabling push notifications. (For more details, refer to Step 7 in this document.)  
      Note: JWT-based user authentication is mandatory for enabling notifications. Push notifications related to tickets are not sent to anonymous users.
    7. Authentication Method: User authentication setting for the add-on
      1. Anonymous - In this method, end-users are considered guest users. They can only submit tickets, view posts in the user community, and chat with a customer support agent. They cannot view the tickets they submitted or actively participate in the user community.
      2. JWT - In this method, end-users are considered authenticated users. In addition to the activities that guest users can perform, authenticated users can also view and track the status of the tickets they submitted, reply/comment to a ticket, and actively participate in the user community (with rights to perform actions, such as following a topic, adding a topic, and adding a comment to existing posts).
  4. Click Save.
A new section called Code Snippet appears. This section displays the Org ID, App ID, and Deployment type details of your app. These details are vital for initializing the ASAP SDK in your app.  



Step 2: Install the plugin.

To install the plugin, open the React Native project directory in Terminal and run the following commands:
npm install react-native-zohodesk-portal-sdk --save 
react-native link react-native-zohodesk-portal-sdk   	

Step 3: Include the SDK in your app.

For Android apps, this step involves the use of Maven.

The ASAP SDK for React Native is released at maven.zohodl.com. Therefore, you must mention the URL in your Android Project. To do this, open the Android folder of your React Native project in Android Studio and add the following Maven repository in the project level 
build.gradle file.
allprojects{ 				
repositories{ 				
maven { url 'https://maven.zohodl.com/'} 			
}
} 	

For iOS apps, this step involves the use of CocoaPods. 

If the Podfile is already part of your React Native project, run the pod install command.

If the Podfile is not part of your project, run the following command from the iOS folder:
pod init
Now, include the RNZohodeskPortalSdk React Native SDK into your Podfile using the following code snippet:
target 'YourProjectName' do
pod 'RNZohodeskPortalSdk',:path => '../node_modules/react-native-zohodesk-portal-sdk/ios/RNZohodeskPortalSdk.podspec'
end 
Then, run the pod install command from the iOS directory.

After successfully installing the pod, open the iOS project in Xcode and navigate to Build Settings  Build Options. Under Build Options, set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to Yes.

Next, include the following keys and their descriptions in the Info.plist file of your app. 
  1. Privacy - Camera Usage Description,
  2. Privacy - Microphone Usage Description, and 
  3. Privacy - Photo Library Usage Description

Step 4: Initialize the SDK.

To initialize the SDK, include the following snippet in your JavaScript code.
import {
ZohoDeskPortalSDK
}from 'react-native-zohodesk-portal-sdk';
ZohoDeskPortalSDK.initialise("orgId", "appId", "dc");

Step 5: Configure the UI and include/exclude help modules the way you want. 

To show the Zoho Desk Home Screen, use the following code snippet.
import {
ZDPortalHome
} from 'react-native-zohodesk-portal-sdk';
ZDPortalHome.show();

To show the Knowledge Base, use the following code snippet.
import {
ZDPortalKB
} from 'react-native-zohodesk-portal-sdk';
ZDPortalKB.show();

To show the Community module, use the following code snippet.
import {
ZDPortalCommunity
} from 'react-native-zohodesk-portal-sdk';
ZDPortalCommunity.show();

To show the Tickets List, use the following code snippet.
import {
ZDPortalTickets
} from 'react-native-zohodesk-portal-sdk';
ZDPortalTickets.show();

To show the Submit Ticket form, use the following code snippet.
import {
ZDPortalSubmitTicket
} from 'react-native-zohodesk-portal-sdk';
ZDPortalSubmitTicket.show();

To show the Live Chat module, use the following code snippet.
import {
ZDPortalChat
} from 'react-native-zohodesk-portal-sdk';
ZDPortalChat.show();

Step 6: Configure user authentication in the add-on.

To authenticate users in the add-on, use the following code snippet. 
ZohoDeskPortalSDK.isUserSignedIn((isSignedIn) => {
if(!isSignedIn) {
ZohoDeskPortalSDK.setUserToken(curEmailId,
(msg) => {
alert('Success Alert '+msg);
} , msg => {
alert('Failure Alert '+msg);
});
}
else {
alert("User is already signed in");
}
})

To log users out from the add-on, use the following code snippet. 
import {
ZohoDeskPortalSDK
} from 'react-native-zohodesk-portal-sdk';
ZohoDeskPortalSDK.logout((msg)=>{
alert("Success "+msg);
},
(msg) =>{
alert("Failure "+msg);
});

Step 7: Configure push notification settings. 

Prerequisite
Make sure that push notifications are implemented in the add-on. 

For Android Apps
This step involves two actions: 
  1. Enabling push notifications for the mobile add-on you created in Step 1. You can access this setting on the ASAP setup page in Zoho Desk.
  2. Retrieving the FCM key of your app and passing it to the add-on. You can retrieve the token by accessing the following path in Firebase Console: Project Settings → Cloud Messaging → Server Key
As part of the second action, you must pass the FCM token in the Android project of your add-on. To do this, include the following code snippet in the oncreate() method in the MainApplication.java class.
RNZohodeskPortalSDK.setFirebaseId(FirebaseInstanceId.getInstance().getToken());

For iOS Apps
First, create and upload a valid Apple Push Notification service (APNs) certificate. Then, upload the p12 file of the APNs certificate along with its password. 

To enable push notifications, conform the AppDelegate class to use the UNUserNotificationCenterDelegate protocol. Then, import the following headers into the AppDelegate.h file.
#import <UserNotifications/UserNotifications.h>
#import <RNZohodeskPortalSdk/RNZohoDeskPortalSDK.h>
Next, fetch the DeviceID value using the application:didRegisterForRemoteNotificationsWithDeviceToken method in the AppDelegate.m file and pass it on to RNZohodeskPortalSdk using the following code snippet. 
const unsigned *tokenBytes = [deviceToken bytes];
   NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                        ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                        ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                        ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
  [RNZohoDeskPortalSDK setDeviceIDForZDPortal:hexToken];

Enabling Push Notifications
To enable push notifications, include the following snippet in the JavaScript code. 
import {
 ZohoDeskPortalSDK
} from 'react-native-zohodesk-portal-sdk';
ZohoDeskPortalSDK.enablePush();

Disabling Push Notifications
To disable push notifications, include the following snippet in the JavaScript code. 
import {
 ZohoDeskPortalSDK
} from 'react-native-zohodesk-portal-sdk';
ZohoDeskPortalSDK.disablePush();

Handling Push Notifications
For Android Apps
To handle the UI and navigation for push notifications, include the following code snippet in the onMessageReceived() method of the FirebaseMessagingService class. 
RNZohodeskPortalSDK.handleNotification(getApplicationContext(), remoteMessage.getData(), icon);
For iOS Apps
To handle the UI and navigation for push notifications, include the following code snippet in the application:didReceiveRemoteNotification method in the AppDelegate.m file.
[RNZohoDeskPortalSDK processRemoteNotification:userInfo];

Step 8: Customize the theme of the add-on.

For Android Apps
To customize the theme of the add-on, you first need the resource ID of the custom theme. Include the following snippet in the oncreate() method in the MainApplication.java class of your Android project.
RNZohodeskPortalSDK.setThemeResource(resourceId);
The value of resourceId must be R.style.DeskLightTheme or R.style.DeskDarkTheme or any theme resource that extends either of these two themes.

For iOS Apps
The SDK UI comes with two predefined themes: Light and Dark. To apply either of the themes, use the following code snippet.
#import <RNZohodeskPortalSdk/RNZohoDeskPortalSDK.h>
[RNZohoDeskPortalSDK setTheme:RNZDThemeLight]; 

Step 9: Configure error logging for the add-on.

The ASAP SDK for React Native provides you with the option to fix errors that occur while using the add-on. This is made possible by SDK logging.

To enable logging for the add-on, include the following code snippet.
import {
ZohoDeskPortalSDK
} from 'react-native-zohodesk-portal-sdk';
ZohoDeskPortalSDK.enableLogs();

To disable logging for the add-on, include the following code snippet.
import {
ZohoDeskPortalSDK
} from 'react-native-zohodesk-portal-sdk';
ZohoDeskPortalSDK.disableLogs();

    • Related Articles

    • Working with the ASAP SDK for iOS

      SDK v2.0 Introduction The ASAP SDK for iOS makes help available within quick reach for the end-users of your iOS app. Using this SDK, you can create and customize an add-on that resides within your app and provides end-users with easy access to your: ...
    • Working with the ASAP Add-On for the Web

      Introduction The ASAP add-on for websites makes your help center available within quick reach for your end-customers. By integrating this add-on with your website, you can provide your customers with easy access to your:  Customer support team (to ...
    • Working with the ASAP Add-Ons for Mobile Platforms

      The ASAP SDKs for mobile platforms--iOS and Android--make help available within quick reach for the end-users of your mobile apps. Using these SDKs, you can create and customize add-ons that reside within your app and provide end-users with easy ...
    • Working with the ASAP Extension for Google Chrome

      Introduction The ASAP extension for Google Chrome is a nifty tool that helps you bridge your website with your knowledge base for the benefit of your customers/site visitors. This extension enables you to easily configure tooltips that display ...
    • Working with the ASAP SDK for Android

      SDK v2.0 Introduction The ASAP SDK for Android makes help available within quick reach for the end-users of your Android app. Using this SDK, you can create and customize an add-on that resides within your app and provides end-users with easy access ...