cordova-plugin-ymchat 2.2.1 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-ymchat",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "Cordova plugin to integrate yellow.ai chatbot",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-ymchat",
@@ -56,6 +56,12 @@ public class YmChatCordova extends CordovaPlugin {
56
56
  case "unlinkDeviceToken":
57
57
  unlinkDeviceToken(args, callbackContext);
58
58
  return true;
59
+ case "registerDevice":
60
+ registerDevice(args, callbackContext);
61
+ return true;
62
+ case "getUnreadMessagesCount":
63
+ getUnreadMessagesCount(callbackContext);
64
+ return true;
59
65
  case "setVersion":
60
66
  setVersion(args,callbackContext);
61
67
  return true;
@@ -205,10 +211,25 @@ public class YmChatCordova extends CordovaPlugin {
205
211
 
206
212
  private void unlinkDeviceToken(JSONArray args, CallbackContext callbackContext) {
207
213
  try {
208
- String botId = args.getString(0);
209
- String apiKey = args.getString(1);
210
- String deviceToken = args.getString(2);
211
- ymChatService.unlinkDeviceToken(botId, apiKey, deviceToken, callbackContext);
214
+ String apiKey = args.getString(0);
215
+ ymChatService.unlinkDeviceToken(apiKey, callbackContext);
216
+ } catch (Exception e) {
217
+ Utils.genericErrorHelper(e, callbackContext);
218
+ }
219
+ }
220
+
221
+ private void registerDevice(JSONArray args, CallbackContext callbackContext) {
222
+ try {
223
+ String apiKey = args.getString(0);
224
+ ymChatService.registerDevice(apiKey, callbackContext);
225
+ } catch (Exception e) {
226
+ Utils.genericErrorHelper(e, callbackContext);
227
+ }
228
+ }
229
+
230
+ private void getUnreadMessagesCount(CallbackContext callbackContext) {
231
+ try {
232
+ ymChatService.getUnreadMessagesCount(callbackContext);
212
233
  } catch (Exception e) {
213
234
  Utils.genericErrorHelper(e, callbackContext);
214
235
  }
@@ -105,9 +105,9 @@ public class YmChatService {
105
105
  });
106
106
  }
107
107
 
108
- public void unlinkDeviceToken(String botId, String apiKey, String deviceToken,CallbackContext callbackContext) {
108
+ public void unlinkDeviceToken(String apiKey, CallbackContext callbackContext) {
109
109
  try{
110
- ymChat.unlinkDeviceToken(botId, apiKey, deviceToken, new YellowCallback() {
110
+ ymChat.unlinkDeviceToken(apiKey, ymChat.config, new YellowCallback() {
111
111
  @Override
112
112
  public void success() {
113
113
  callbackContext.success();
@@ -125,6 +125,47 @@ public class YmChatService {
125
125
  }
126
126
  }
127
127
 
128
+ public void registerDevice(String apiKey, CallbackContext callbackContext) {
129
+ try{
130
+ ymChat.registerDevice(apiKey, ymChat.config, new YellowCallback() {
131
+ @Override
132
+ public void success() {
133
+ callbackContext.success();
134
+ }
135
+
136
+ @Override
137
+ public void failure(String message) {
138
+ Utils.genericErrorHelper(new Exception(),callbackContext);
139
+ }
140
+ });
141
+ }
142
+ catch (Exception e)
143
+ {
144
+ Utils.genericErrorHelper(e, callbackContext);
145
+ }
146
+ }
147
+
148
+ public void getUnreadMessagesCount(CallbackContext callbackContext) {
149
+ try{
150
+ ymChat.getUnreadMessagesCount(ymChat.config, new YellowCallback() {
151
+ @Override
152
+ public <T> void success(T data) {
153
+ YellowUnreadMessageResponse response = (YellowUnreadMessageResponse) data;
154
+ callbackContext.success(response.getUnreadCount());
155
+ }
156
+
157
+ @Override
158
+ public void failure(String message) {
159
+ Utils.genericErrorHelper(new Exception(),callbackContext);
160
+ }
161
+ });
162
+ }
163
+ catch (Exception e)
164
+ {
165
+ Utils.genericErrorHelper(e, callbackContext);
166
+ }
167
+ }
168
+
128
169
  public void setVersion(int version, CallbackContext callbackContext) {
129
170
  ymChat.config.version = version;
130
171
  }
package/src/ios/ymchat.m CHANGED
@@ -120,18 +120,59 @@
120
120
  }
121
121
 
122
122
  - (void) unlinkDeviceToken:(CDVInvokedUrlCommand*)command {
123
- NSString* botId = [command.arguments objectAtIndex:0];
124
- NSString* apiKey = [command.arguments objectAtIndex:1];
125
- NSString* deviceToken = [command.arguments objectAtIndex:2];
126
- [[YMChat shared] unlinkDeviceTokenWithBotId:botId apiKey:apiKey deviceToken:deviceToken success:^{
123
+ if(YMChat.shared.config) {
124
+ NSString* apiKey = [command.arguments objectAtIndex:0];
125
+ [[YMChat shared] unlinkDeviceTokenWithApiKey:apiKey ymConfig:YMChat.shared.config success:^{
126
+ CDVPluginResult* pluginResult = nil;
127
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
128
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
129
+ } failure:^(NSString * _Nonnull failureMessage) {
130
+ CDVPluginResult* pluginResult = nil;
131
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:failureMessage];
132
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
133
+ }];
134
+ } else {
127
135
  CDVPluginResult* pluginResult = nil;
128
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
136
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Bot id not found"];
129
137
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
130
- } failure:^(NSString * _Nonnull failureMessage) {
138
+ }
139
+ }
140
+
141
+ - (void) registerDevice:(CDVInvokedUrlCommand*)command {
142
+ NSString* apiKey = [command.arguments objectAtIndex:0];
143
+ if(YMChat.shared.config) {
144
+ [[YMChat shared] registerDeviceWithApiKey:apiKey ymConfig:YMChat.shared.config success:^{
145
+ CDVPluginResult* pluginResult = nil;
146
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
147
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
148
+ } failure:^(NSString * _Nonnull failureMessage) {
149
+ CDVPluginResult* pluginResult = nil;
150
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:failureMessage];
151
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
152
+ }];
153
+ } else {
131
154
  CDVPluginResult* pluginResult = nil;
132
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:failureMessage];
155
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Bot id not found"];
133
156
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
134
- }];
157
+ }
158
+ }
159
+
160
+ - (void) getUnreadMessagesCount:(CDVInvokedUrlCommand*)command {
161
+ if(YMChat.shared.config) {
162
+ [[YMChat shared] getUnreadMessagesCountWithYmConfig:YMChat.shared.config success:^(NSString * _Nonnull unreadCount) {
163
+ CDVPluginResult* pluginResult = nil;
164
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:unreadCount];
165
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
166
+ } failure:^(NSString * _Nonnull failureMessage) {
167
+ CDVPluginResult* pluginResult = nil;
168
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:failureMessage];
169
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
170
+ }];
171
+ } else {
172
+ CDVPluginResult* pluginResult = nil;
173
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Bot id not found"];
174
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
175
+ }
135
176
  }
136
177
 
137
178
  - (void)setCustomLoaderURL:(CDVInvokedUrlCommand*)command
package/www/ymchat.js CHANGED
@@ -35,8 +35,14 @@ const YmChatAPI = {
35
35
  closeBot: () => {
36
36
  exec(null, null, "ymchat", "closeBot", []);
37
37
  },
38
- unlinkDeviceToken: (botId, apiKey, deviceToken, success, failure) => {
39
- exec(success, failure, "ymchat", "unlinkDeviceToken", [botId, apiKey, deviceToken])
38
+ unlinkDeviceToken: (apiKey, success, failure) => {
39
+ exec(success, failure, "ymchat", "unlinkDeviceToken", [apiKey])
40
+ },
41
+ registerDevice: (apiKey, success, failure) => {
42
+ exec(success, failure, "ymchat", "registerDevice", [apiKey])
43
+ },
44
+ getUnreadMessagesCount: (success, failure) => {
45
+ exec(success, failure, "ymchat", "getUnreadMessagesCount", [])
40
46
  },
41
47
  setVersion: (version) => {
42
48
  exec(null, null, "ymchat", "setVersion", [version])