├── .gitignore ├── src ├── android │ ├── cordovaZohoPortalSDK.gradle │ └── com │ │ └── zoho │ │ └── desk │ │ └── portal │ │ └── CordovaZohoDeskPortal.java └── ios │ └── CordovaZohoDeskPortal.m ├── package.json ├── www └── CordovaZohoDeskPortal.js └── plugin.xml /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/android/cordovaZohoPortalSDK.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | google() 3 | jcenter() 4 | maven { url "https://maven.zohodl.com/"} 5 | } 6 | 7 | dependencies { 8 | implementation "com.zoho.desk:asapsdk:1.1.6" 9 | } 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-zohodesk-portal", 3 | "version": "0.4.0", 4 | "description": "cordova-plugin-zohodesk-portal", 5 | "cordova": { 6 | "id": "cordova-plugin-zohodesk-portal", 7 | "platforms": [ 8 | "android" 9 | ] 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/zoho/cordova-plugin-zohodesk-portal.git" 14 | }, 15 | "keywords": [ 16 | "ecosystem:cordova", 17 | "cordova-android" 18 | ], 19 | "author": "vignesh.thillai@zohocorp.com", 20 | "license": "ISC", 21 | "bugs": { 22 | "url": "https://github.com/zoho/cordova-plugin-zohodesk-portal/issues" 23 | }, 24 | "homepage": "https://github.com/zoho/cordova-plugin-zohodesk-portal#readme" 25 | } 26 | -------------------------------------------------------------------------------- /www/CordovaZohoDeskPortal.js: -------------------------------------------------------------------------------- 1 | var exec = require('cordova/exec'); 2 | 3 | exports.initialize = function (scb, ecb, orgId, appId, dc) { 4 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'initialize', [orgId, appId, dc]); //No I18N 5 | }; 6 | 7 | exports.startDeskHomeScreen = function (scb, ecb) { 8 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'startDeskHomeScreen', ['']); //No I18N 9 | }; 10 | 11 | exports.startNewTicket = function (scb, ecb) { 12 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'startNewTicket', ['']); //No I18N 13 | }; 14 | 15 | exports.startHelpCenter = function (scb, ecb) { 16 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'startHelpCenter', ['']); //No I18N 17 | }; 18 | 19 | exports.startCommunity = function (scb, ecb) { 20 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'startCommunity', ['']); //No I18N 21 | }; 22 | 23 | exports.startTickets = function (scb, ecb) { 24 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'startTickets', ['']); //No I18N 25 | }; 26 | 27 | exports.startLiveChat = function (scb, ecb) { 28 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'startLiveChat', ['']); //No I18N 29 | }; 30 | 31 | exports.setUserToken = function (scb, ecb, userToken) { 32 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'setUserToken', [userToken]); //No I18N 33 | }; 34 | 35 | exports.removeUser = function (scb, ecb) { 36 | exec(scb, ecb, 'CordovaZohoDeskPortal', 'removeUser', ['']); //No I18N 37 | }; 38 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | CordovaZohoDeskPortal 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | $CAMERA_USAGE_DESCRIPTION 34 | 35 | 36 | 37 | 38 | $PHOTOLIBRARY_USAGE_DESCRIPTION 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/ios/CordovaZohoDeskPortal.m: -------------------------------------------------------------------------------- 1 | /********* CordovaZohoDeskPortal.m Cordova Plugin Implementation *******/ 2 | 3 | #import 4 | #import 5 | 6 | @interface CordovaZohoDeskPortal : CDVPlugin { 7 | // Member variables go here. 8 | } 9 | 10 | - (void)initialize:(CDVInvokedUrlCommand*)command; 11 | - (void)setUserToken:(CDVInvokedUrlCommand*)command; 12 | - (void)removeUser:(CDVInvokedUrlCommand*)command; 13 | - (void)startDeskHomeScreen:(CDVInvokedUrlCommand*)command; 14 | - (void)startNewTicket:(CDVInvokedUrlCommand*)command; 15 | - (void)startHelpCenter:(CDVInvokedUrlCommand*)command; 16 | - (void)startCommunity:(CDVInvokedUrlCommand*)command; 17 | - (void)startTickets:(CDVInvokedUrlCommand*)command; 18 | - (void)startLiveChat:(CDVInvokedUrlCommand*)command; 19 | @end 20 | 21 | @implementation CordovaZohoDeskPortal 22 | 23 | - (void)initialize:(CDVInvokedUrlCommand*)command{ 24 | NSArray* arguments = command.arguments; 25 | if (arguments == nil) { 26 | [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Arugument cannot be nil"] callbackId:command.callbackId]; 27 | return; 28 | } 29 | ZDDataCenter dataCenter = ZDDataCenterUS; 30 | 31 | if ([arguments[2] isEqualToString:@"EU"]){ 32 | dataCenter = ZDDataCenterEU; 33 | }else if ([arguments[2] isEqualToString:@"IN"]){ 34 | dataCenter = ZDDataCenterIN; 35 | }else if ([arguments[2] isEqualToString:@"CN"]){ 36 | dataCenter = ZDDataCenterCN; 37 | }else{ 38 | dataCenter = ZDDataCenterUS; 39 | } 40 | 41 | ZDPortalConfiguration * config = [[ZDPortalConfiguration alloc]init]; 42 | [ZohoDeskPortalSDK initializeSDK:arguments[0] appId:arguments[1] dataCenter:dataCenter configuration:config]; 43 | } 44 | 45 | - (void)setUserToken:(CDVInvokedUrlCommand*)command{ 46 | NSArray* arguments = command.arguments; 47 | if (arguments == nil) { 48 | [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Arugument cannot be nil"] callbackId:command.callbackId]; 49 | return; 50 | } 51 | if (![ZohoDeskPortalSDK isZDUserSignedIn]){ 52 | [ZohoDeskPortalSDK setWithJwtUserIdentifier:arguments[0] onComplition:^{ 53 | [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId]; 54 | } onError:^(NSError * error) { 55 | [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description] callbackId:command.callbackId]; 56 | }]; 57 | }else{ 58 | //User already signed into SDK 59 | } 60 | } 61 | 62 | - (void)removeUser:(CDVInvokedUrlCommand*)command{ 63 | 64 | [ZohoDeskPortalSDK logoutOnComplition:^{ 65 | //User Logged out successfully 66 | [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId]; 67 | } onError:^(NSError * error) { 68 | //error while logging out user 69 | [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description] callbackId:command.callbackId]; 70 | }]; 71 | } 72 | 73 | - (void)startDeskHomeScreen:(CDVInvokedUrlCommand*)command{ 74 | ZDPortalConfiguration * config = [[ZDPortalConfiguration alloc]init]; 75 | [ZohoDeskPortalSDK showHomePageWithController:self.viewController withConfiguration:config]; 76 | } 77 | 78 | - (void)startNewTicket:(CDVInvokedUrlCommand*)command{ 79 | [ZohoDeskPortalSDK addTicketWithController:self.viewController]; 80 | } 81 | 82 | - (void)startHelpCenter:(CDVInvokedUrlCommand*)command{ 83 | [ZohoDeskPortalSDK showHelpCenterWithController:self.viewController]; 84 | } 85 | 86 | - (void)startCommunity:(CDVInvokedUrlCommand*)command{ 87 | [ZohoDeskPortalSDK showCommunityWithController:self.viewController]; 88 | } 89 | 90 | - (void)startTickets:(CDVInvokedUrlCommand*)command{ 91 | [ZohoDeskPortalSDK ticketListWithController:self.viewController]; 92 | } 93 | 94 | - (void)startLiveChat:(CDVInvokedUrlCommand*)command{ 95 | [ZohoDeskPortalSDK showLiveChatWithController:self.viewController]; 96 | } 97 | 98 | @end 99 | 100 | -------------------------------------------------------------------------------- /src/android/com/zoho/desk/portal/CordovaZohoDeskPortal.java: -------------------------------------------------------------------------------- 1 | package com.zoho.desk.portal; 2 | 3 | import android.app.Activity; 4 | 5 | import com.google.gson.JsonArray; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonParser; 8 | import com.zoho.deskportalsdk.DeskConfig; 9 | import com.zoho.deskportalsdk.ZohoDeskPortalSDK; 10 | import com.zoho.deskportalsdk.android.network.DeskCallback; 11 | 12 | import org.apache.cordova.CordovaPlugin; 13 | import org.apache.cordova.CallbackContext; 14 | 15 | import org.json.JSONArray; 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | 19 | /** 20 | * This class echoes a string called from JavaScript. 21 | */ 22 | public class CordovaZohoDeskPortal extends CordovaPlugin { 23 | 24 | private ZohoDeskPortalSDK deskPortalSDK; 25 | private Activity activity; 26 | 27 | @Override 28 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 29 | if (action.equals("initialize")) { 30 | this.initialize(args, callbackContext); 31 | return true; 32 | } 33 | if (action.equals("startDeskHomeScreen")) { 34 | this.startDeskHomeScreen(callbackContext); 35 | return true; 36 | } 37 | if(action.equals("startNewTicket")) { 38 | this.startNewTicket(callbackContext); 39 | return true; 40 | } 41 | if(action.equals("startHelpCenter")) { 42 | this.startHelpCenter(callbackContext); 43 | return true; 44 | } 45 | if(action.equals("startCommunity")) { 46 | this.startCommunity(callbackContext); 47 | return true; 48 | } 49 | if(action.equals("startTickets")) { 50 | this.startTickets(callbackContext); 51 | return true; 52 | } 53 | if(action.equals("startLiveChat")) { 54 | this.startLiveChat(callbackContext); 55 | return true; 56 | } 57 | if(action.equals("setUserToken")) { 58 | this.setUserToken(args.getString(0), callbackContext); 59 | return true; 60 | } 61 | if(action.equals("removeUser")) { 62 | this.removeUser(callbackContext); 63 | return true; 64 | } 65 | return false; 66 | } 67 | 68 | 69 | private void initialize(JSONArray array, CallbackContext callbackContext) { 70 | activity = cordova.getActivity(); 71 | deskPortalSDK = ZohoDeskPortalSDK.getInstance(cordova.getActivity().getApplication()); 72 | DeskConfig config = new DeskConfig.Builder().build(); 73 | try { 74 | long orgId = Long.valueOf(array.getString(0)); 75 | String appId = array.getString(1); 76 | String dcString = array.getString(2); 77 | ZohoDeskPortalSDK.DataCenter dataCenter = ZohoDeskPortalSDK.DataCenter.US; 78 | if("EU".equalsIgnoreCase(dcString)) { 79 | dataCenter = ZohoDeskPortalSDK.DataCenter.EU; 80 | } else if ("CN".equalsIgnoreCase(dcString)) { 81 | dataCenter = ZohoDeskPortalSDK.DataCenter.CN; 82 | } else if ("IN".equalsIgnoreCase(dcString)) { 83 | dataCenter = ZohoDeskPortalSDK.DataCenter.IN; 84 | } 85 | deskPortalSDK.initDesk(orgId, appId, dataCenter, config); 86 | callbackContext.success(); 87 | } catch (Exception e) { 88 | if(callbackContext != null) { 89 | callbackContext.error("Error while initialize"); 90 | } 91 | } 92 | } 93 | 94 | private boolean initializeCheck(CallbackContext callbackContext) { 95 | if(activity == null) { 96 | callbackContext.error("Plugin is not initialised."); 97 | } 98 | return activity != null; 99 | } 100 | 101 | private void startDeskHomeScreen(CallbackContext callbackContext) { 102 | if(initializeCheck(callbackContext)) { 103 | deskPortalSDK.startDeskHomeScreen(activity); 104 | } 105 | } 106 | 107 | private void startNewTicket(CallbackContext callbackContext) { 108 | if(initializeCheck(callbackContext)) { 109 | deskPortalSDK.startNewTicket(activity); 110 | } 111 | } 112 | 113 | private void startHelpCenter(CallbackContext callbackContext) { 114 | if(initializeCheck(callbackContext)) { 115 | deskPortalSDK.startHelpCenter(activity); 116 | } 117 | } 118 | 119 | private void startCommunity(CallbackContext callbackContext) { 120 | if(initializeCheck(callbackContext)) { 121 | deskPortalSDK.startCommunity(activity); 122 | } 123 | } 124 | 125 | private void startTickets(CallbackContext callbackContext) { 126 | if(initializeCheck(callbackContext)) { 127 | deskPortalSDK.startTickets(activity); 128 | } 129 | } 130 | 131 | private void startLiveChat(CallbackContext callbackContext) { 132 | if(initializeCheck(callbackContext)) { 133 | deskPortalSDK.startLiveChat(activity); 134 | } 135 | } 136 | 137 | private void setUserToken(String userToken, CallbackContext callbackContext) { 138 | if(initializeCheck(callbackContext)) { 139 | deskPortalSDK.setUserToken(userToken, new DeskCallback.DeskSetUserCallback() { 140 | @Override 141 | public void onUserSetSuccess() { 142 | callbackContext.success(); 143 | } 144 | 145 | @Override 146 | public void onException(DeskException e) { 147 | callbackContext.error(e.getMessage()); 148 | } 149 | }); 150 | } 151 | } 152 | 153 | private void removeUser(CallbackContext callbackContext) { 154 | if(initializeCheck(callbackContext)) { 155 | deskPortalSDK.removeUser(new DeskCallback.DeskRemoveUserCallback() { 156 | @Override 157 | public void onUserRemoveSuccess() { 158 | callbackContext.success(); 159 | } 160 | 161 | @Override 162 | public void onException(DeskException e) { 163 | callbackContext.error(e.getMessage()); 164 | } 165 | }); 166 | } 167 | } 168 | } 169 | --------------------------------------------------------------------------------