infobip-mobile-messaging-react-native-plugin 11.3.2 → 12.0.0

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.
@@ -87,7 +87,7 @@ repositories {
87
87
  }
88
88
 
89
89
  dependencies {
90
- def mmVersion = "12.7.1"
90
+ def mmVersion = "12.9.0"
91
91
  //react and mm dependencies clash
92
92
  if (!overrideKotlinVersion.empty) {
93
93
  constraints {
@@ -104,6 +104,7 @@ dependencies {
104
104
 
105
105
  implementation "com.infobip:infobip-mobile-messaging-android-resources:$mmVersion@aar"
106
106
  implementation "com.infobip:infobip-mobile-messaging-android-chat-sdk:$mmVersion@aar"
107
+ implementation "com.infobip:infobip-mobile-messaging-android-inbox-sdk:$mmVersion@aar"
107
108
  implementation ("com.infobip:infobip-mobile-messaging-android-sdk:$mmVersion@aar") {
108
109
  transitive = true;
109
110
 
@@ -23,6 +23,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
23
23
 
24
24
  import com.facebook.react.ReactApplication;
25
25
  import com.facebook.react.bridge.ActivityEventListener;
26
+ import com.facebook.react.bridge.Arguments;
26
27
  import com.facebook.react.bridge.Callback;
27
28
  import com.facebook.react.bridge.LifecycleEventListener;
28
29
  import com.facebook.react.bridge.ReactApplicationContext;
@@ -31,6 +32,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
31
32
  import com.facebook.react.bridge.ReactMethod;
32
33
  import com.facebook.react.bridge.ReadableArray;
33
34
  import com.facebook.react.bridge.ReadableMap;
35
+ import com.facebook.react.bridge.WritableMap;
34
36
  import com.facebook.react.modules.core.PermissionAwareActivity;
35
37
  import com.facebook.react.modules.core.PermissionListener;
36
38
  import com.google.android.gms.common.ConnectionResult;
@@ -49,6 +51,9 @@ import org.infobip.mobile.messaging.User;
49
51
  import org.infobip.mobile.messaging.chat.InAppChat;
50
52
  import org.infobip.mobile.messaging.chat.core.InAppChatEvent;
51
53
  import org.infobip.mobile.messaging.dal.bundle.MessageBundleMapper;
54
+ import org.infobip.mobile.messaging.inbox.Inbox;
55
+ import org.infobip.mobile.messaging.inbox.MobileInbox;
56
+ import org.infobip.mobile.messaging.inbox.MobileInboxFilterOptions;
52
57
  import org.infobip.mobile.messaging.interactive.InteractiveEvent;
53
58
  import org.infobip.mobile.messaging.interactive.MobileInteractive;
54
59
  import org.infobip.mobile.messaging.interactive.NotificationAction;
@@ -63,8 +68,10 @@ import org.infobip.mobile.messaging.util.Cryptor;
63
68
  import org.infobip.mobile.messaging.util.DeviceInformation;
64
69
  import org.infobip.mobile.messaging.util.PreferenceHelper;
65
70
  import org.infobip.reactlibrary.mobilemessaging.datamappers.CustomEventJson;
71
+ import org.infobip.reactlibrary.mobilemessaging.datamappers.InboxJson;
66
72
  import org.infobip.reactlibrary.mobilemessaging.datamappers.InstallationJson;
67
73
  import org.infobip.reactlibrary.mobilemessaging.datamappers.MessageJson;
74
+ import org.infobip.reactlibrary.mobilemessaging.datamappers.MobileInboxFilterOptionsJson;
68
75
  import org.infobip.reactlibrary.mobilemessaging.datamappers.PersonalizationCtx;
69
76
  import org.infobip.reactlibrary.mobilemessaging.datamappers.ReactNativeJson;
70
77
  import org.infobip.reactlibrary.mobilemessaging.datamappers.UserJson;
@@ -78,6 +85,7 @@ import java.util.Arrays;
78
85
  import java.util.HashMap;
79
86
  import java.util.List;
80
87
  import java.util.Map;
88
+ import java.util.Set;
81
89
  import java.util.concurrent.CopyOnWriteArrayList;
82
90
 
83
91
  public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener,
@@ -403,7 +411,7 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
403
411
  .withoutRegisteringForRemoteNotifications()
404
412
  .withApplicationCode(configuration.applicationCode);
405
413
 
406
- if(configuration.fullFeaturedInAppsEnabled)
414
+ if (configuration.fullFeaturedInAppsEnabled)
407
415
  builder.withFullFeaturedInApps();
408
416
 
409
417
  if (configuration.privacySettings.userDataPersistingDisabled) {
@@ -601,6 +609,73 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
601
609
  onSuccess.invoke();
602
610
  }
603
611
 
612
+ @ReactMethod
613
+ public void fetchInboxMessages(@NonNull String token, @NonNull String externalUserId, ReadableMap args, final Callback successCallback, final Callback errorCallback) throws JSONException {
614
+ try {
615
+ mobileMessagingInbox().fetchInbox(token, externalUserId, MobileInboxFilterOptionsJson.resolveMobileInboxFilterOptions(ReactNativeJson.convertMapToJson(args)), inboxResultListener(successCallback, errorCallback));
616
+ } catch (IllegalArgumentException e) {
617
+ Log.d(Utils.TAG, "Error fetching inbox:" + e.getMessage());
618
+ }
619
+ }
620
+
621
+ @ReactMethod
622
+ public void fetchInboxMessagesWithoutToken(@NonNull String externalUserId, ReadableMap args, final Callback successCallback, final Callback errorCallback) throws JSONException {
623
+ try {
624
+ mobileMessagingInbox().fetchInbox(externalUserId, MobileInboxFilterOptionsJson.resolveMobileInboxFilterOptions(ReactNativeJson.convertMapToJson(args)), inboxResultListener(successCallback, errorCallback));
625
+ } catch (IllegalArgumentException e) {
626
+ Log.d(Utils.TAG, "Error fetching inbox:" + e.getMessage());
627
+ }
628
+ }
629
+
630
+ @ReactMethod
631
+ public void setInboxMessagesSeen(@NonNull String externalUserId, ReadableArray args, final Callback successCallback, final Callback errorCallback) {
632
+ mobileMessagingInbox().setSeen(externalUserId, convertReadableArrayToStringArray(args), setSeenResultListener(successCallback, errorCallback));
633
+ }
634
+
635
+ private String[] convertReadableArrayToStringArray(ReadableArray readableArray) {
636
+ String[] stringArray = new String[readableArray.size()];
637
+ for (int i = 0; i < readableArray.size(); i++) {
638
+ stringArray[i] = readableArray.getString(i);
639
+ }
640
+ return stringArray;
641
+ }
642
+
643
+ @NonNull
644
+ private MobileMessaging.ResultListener<Inbox> inboxResultListener(final Callback successCallback, final Callback errorCallback) {
645
+ return new MobileMessaging.ResultListener<Inbox>() {
646
+ @Override
647
+ public void onResult(Result<Inbox, MobileMessagingError> result) {
648
+ if (result.isSuccess()) {
649
+ ReadableMap readableMap = InboxJson.toReadableMap(result.getData());
650
+ successCallback.invoke(readableMap);
651
+ } else {
652
+ errorCallback.invoke(Utils.callbackError(result.getError().getMessage(), null));
653
+ }
654
+ }
655
+ };
656
+ }
657
+
658
+ @NonNull
659
+ private MobileMessaging.ResultListener<String[]> setSeenResultListener(final Callback successCallback, final Callback errorCallback) {
660
+ return new MobileMessaging.ResultListener<String[]>() {
661
+ @Override
662
+ public void onResult(Result<String[], MobileMessagingError> result) {
663
+ if (result.isSuccess()) {
664
+ String[] messagesSetSeen = result.getData();
665
+ WritableMap writableMap = Arguments.createMap();
666
+
667
+ for (int i = 0; i < messagesSetSeen.length; i++) {
668
+ writableMap.putString(Integer.toString(i), messagesSetSeen[i]);
669
+ }
670
+
671
+ successCallback.invoke(writableMap);
672
+ } else {
673
+ errorCallback.invoke(Utils.callbackError(result.getError().getMessage(), null));
674
+ }
675
+ }
676
+ };
677
+ }
678
+
604
679
 
605
680
  /*User Profile Management*/
606
681
 
@@ -751,6 +826,11 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
751
826
  return MobileMessaging.getInstance(this.reactContext.getApplicationContext());
752
827
  }
753
828
 
829
+
830
+ private MobileInbox mobileMessagingInbox() {
831
+ return MobileInbox.getInstance(this.reactContext.getApplicationContext());
832
+ }
833
+
754
834
  /* Messages and Notifications management */
755
835
 
756
836
  @ReactMethod
@@ -0,0 +1,31 @@
1
+ package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
+
3
+ import com.facebook.react.bridge.ReadableMap;
4
+ import org.infobip.mobile.messaging.inbox.Inbox;
5
+ import org.infobip.mobile.messaging.inbox.InboxMapper;
6
+ import org.json.JSONException;
7
+ import org.json.JSONObject;
8
+
9
+ public class InboxJson extends Inbox {
10
+
11
+ public static JSONObject toJSON(final Inbox inbox) {
12
+ if (inbox == null) {
13
+ return new JSONObject();
14
+ }
15
+ try {
16
+ return new JSONObject(inbox.toString());
17
+ } catch (JSONException e) {
18
+ e.printStackTrace();
19
+ return new JSONObject();
20
+ }
21
+ }
22
+
23
+ public static ReadableMap toReadableMap(final Inbox inbox) {
24
+ try {
25
+ return ReactNativeJson.convertJsonToMap(toJSON(inbox));
26
+ } catch (JSONException e) {
27
+ e.printStackTrace();
28
+ return null;
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,8 @@
1
+ package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
+
3
+ public class MobileInboxFilterOptionsAttrs {
4
+ public static final String fromDateTime = "fromDateTime";
5
+ public static final String toDateTime = "toDateTime";
6
+ public static final String topic = "topic";
7
+ public static final String limit = "limit";
8
+ }
@@ -0,0 +1,84 @@
1
+ package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import android.util.Log;
5
+
6
+ import org.infobip.mobile.messaging.api.support.http.serialization.JsonSerializer;
7
+ import org.infobip.mobile.messaging.inbox.MobileInboxFilterOptions;
8
+ import org.infobip.reactlibrary.mobilemessaging.Utils;
9
+ import org.json.JSONException;
10
+ import org.json.JSONObject;
11
+
12
+ import java.text.SimpleDateFormat;
13
+ import java.util.Date;
14
+
15
+ /**
16
+ * Inbox filter data mapper for JSON conversion
17
+ */
18
+ public class MobileInboxFilterOptionsJson extends MobileInboxFilterOptions {
19
+
20
+ private static final JsonSerializer nullSerializer = new JsonSerializer(true);
21
+
22
+ public MobileInboxFilterOptionsJson(Date fromDateTime, Date toDateTime, String topic, Integer limit) {
23
+ super(fromDateTime, toDateTime, topic, limit);
24
+ }
25
+
26
+ public static JSONObject toJSON(final MobileInboxFilterOptions mobileInboxFilterOptions) {
27
+ if (mobileInboxFilterOptions == null) {
28
+ return new JSONObject();
29
+ }
30
+ try {
31
+ return new JSONObject(nullSerializer.serialize(mobileInboxFilterOptions));
32
+ } catch (JSONException e) {
33
+ e.printStackTrace();
34
+ return new JSONObject();
35
+ }
36
+ }
37
+
38
+ @NonNull
39
+ public static MobileInboxFilterOptions resolveMobileInboxFilterOptions(JSONObject args) throws IllegalArgumentException {
40
+ if (args == null) {
41
+ throw new IllegalArgumentException("Cannot resolve inbox filters from arguments");
42
+ }
43
+ return MobileInboxFilterOptionsJson.mobileInboxFilterOptionsFromJSON(args);
44
+ }
45
+
46
+ private static MobileInboxFilterOptions mobileInboxFilterOptionsFromJSON(JSONObject json) throws IllegalArgumentException {
47
+ MobileInboxFilterOptions mobileInboxFilterOptions = null;
48
+ String fromDate = null;
49
+ String toDate = null;
50
+ String topic = null;
51
+ Integer limit = null;
52
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
53
+ try {
54
+ if (json.has(MobileInboxFilterOptionsAttrs.fromDateTime)) {
55
+ fromDate = json.optString(MobileInboxFilterOptionsAttrs.fromDateTime);
56
+ }
57
+ if (json.has(MobileInboxFilterOptionsAttrs.toDateTime)) {
58
+ toDate = json.optString(MobileInboxFilterOptionsAttrs.toDateTime);
59
+ }
60
+ if (json.has(MobileInboxFilterOptionsAttrs.topic)) {
61
+ topic = json.optString(MobileInboxFilterOptionsAttrs.topic);
62
+ }
63
+ if (json.has(MobileInboxFilterOptionsAttrs.limit)) {
64
+ limit = json.optInt(MobileInboxFilterOptionsAttrs.limit);
65
+ }
66
+ mobileInboxFilterOptions = new MobileInboxFilterOptions(null, null, null, null);
67
+ if(fromDate != null) {
68
+ mobileInboxFilterOptions.setFromDateTime(sdf.parse(fromDate));
69
+ }
70
+ if(toDate != null) {
71
+ mobileInboxFilterOptions.setToDateTime(sdf.parse(toDate));
72
+ }
73
+ if(topic != null) {
74
+ mobileInboxFilterOptions.setTopic(topic);
75
+ }
76
+ if(limit != null) {
77
+ mobileInboxFilterOptions.setLimit(limit);
78
+ }
79
+ } catch (Exception e) {
80
+ e.printStackTrace();
81
+ }
82
+ return mobileInboxFilterOptions;
83
+ }
84
+ }
@@ -19,10 +19,11 @@ Pod::Spec.new do |s|
19
19
  s.requires_arc = true
20
20
 
21
21
  s.dependency "React-Core"
22
- s.dependency "MobileMessaging/Core", "12.6.2"
23
- s.dependency "MobileMessaging/Geofencing", "12.6.2"
24
- s.dependency "MobileMessaging/InAppChat", "12.6.2"
22
+ s.dependency "MobileMessaging/Core", "12.10.0"
23
+ s.dependency "MobileMessaging/Geofencing", "12.10.0"
24
+ s.dependency "MobileMessaging/InAppChat", "12.10.0"
25
+ s.dependency "MobileMessaging/Inbox", "12.10.0"
25
26
  if defined?($WebRTCUIEnabled)
26
- s.dependency "MobileMessaging/WebRTCUI", "12.6.2"
27
+ s.dependency "MobileMessaging/WebRTCUI", "12.10.0"
27
28
  end
28
29
  end
@@ -58,7 +58,7 @@ class RNMMChat: NSObject {
58
58
  setNotNil(&chatSettings.advancedSettings.mainTextColor, CustomisationKeys.inputTextColor.getColor(from: settings))
59
59
 
60
60
  setNotNil(&chatSettings.sendButtonTintColor, CustomisationKeys.sendButtonTintColor.getColor(from: settings))
61
- setNotNil(&chatSettings.backgroungColor, CustomisationKeys.chatBackgroundColor.getColor(from: settings))
61
+ setNotNil(&chatSettings.backgroundColor, CustomisationKeys.chatBackgroundColor.getColor(from: settings))
62
62
  setNotNil(&chatSettings.errorLabelTextColor, CustomisationKeys.noConnectionAlertTextColor.getColor(from: settings))
63
63
  setNotNil(&chatSettings.errorLabelBackgroundColor, CustomisationKeys.noConnectionAlertBackgroundColor.getColor(from: settings))
64
64
  setNotNil(&chatSettings.widgetTheme, CustomisationKeys.widgetTheme.getString(from: settings))
@@ -123,15 +123,17 @@ class RNMMChat: NSObject {
123
123
 
124
124
  @objc(sendContextualData:multiThreadStrategy:onSuccess:onError:)
125
125
  func sendContextualData(data: NSString, multiThreadStrategy: Bool, onSuccess: @escaping RCTResponseSenderBlock, onError: @escaping RCTResponseSenderBlock) {
126
- guard let chatVC = RNMMChatView.viewController else {
127
- return
128
- }
129
- chatVC.sendContextualData(String(data), multiThreadStrategy: multiThreadStrategy ? .ALL : .ACTIVE) { error in
130
- if let error = error {
131
- onError([error.reactNativeObject])
132
- } else {
133
- onSuccess(nil)
126
+ if let chatVC = RNMMChatView.viewController {
127
+ chatVC.sendContextualData(String(data), multiThreadStrategy: multiThreadStrategy ? .ALL : .ACTIVE) { error in
128
+ if let error = error {
129
+ onError([error.reactNativeObject])
130
+ } else {
131
+ onSuccess(nil)
132
+ }
134
133
  }
134
+ } else if let inAppChat = MobileMessaging.inAppChat {
135
+ inAppChat.sendContextualData(String(data), multiThreadStrategy: multiThreadStrategy ? .ALL : .ACTIVE)
136
+ onSuccess(nil)
135
137
  }
136
138
  }
137
139
 
@@ -175,6 +175,55 @@ class ReactNativeMobileMessaging: RCTEventEmitter {
175
175
  }
176
176
  })
177
177
  }
178
+
179
+ @objc(fetchInboxMessages:externalUserId:inboxFilterOptions:onSuccess:onError:)
180
+ func fetchInboxMessages(token: String, externalUserId: String, inboxFilterOptions: NSDictionary, onSuccess: @escaping RCTResponseSenderBlock, onError: @escaping RCTResponseSenderBlock) {
181
+ var filteringOptions: MMInboxFilterOptions? = nil
182
+ if let inboxFilterOptionsDictionary = inboxFilterOptions as? [String: Any] {
183
+ let inboxFilterOptions = MMInboxFilterOptions(dictRepresentation: inboxFilterOptionsDictionary)
184
+ filteringOptions = inboxFilterOptions
185
+ }
186
+ MobileMessaging.inbox?.fetchInbox(token: token, externalUserId: externalUserId, options: filteringOptions, completion: { (inbox, error) in
187
+ if let error = error {
188
+ onError([error.reactNativeObject])
189
+ } else {
190
+ onSuccess([inbox?.dictionary ?? [:]])
191
+ }
192
+ })
193
+ }
194
+
195
+ @objc(fetchInboxMessagesWithoutToken:inboxFilterOptions:onSuccess:onError:)
196
+ func fetchInboxMessagesWithoutToken(externalUserId: String, inboxFilterOptions: NSDictionary, onSuccess: @escaping RCTResponseSenderBlock, onError: @escaping RCTResponseSenderBlock) {
197
+ var filteringOptions: MMInboxFilterOptions? = nil
198
+ if let inboxFilterOptionsDictionary = inboxFilterOptions as? [String: Any] {
199
+ let inboxFilterOptions = MMInboxFilterOptions(dictRepresentation: inboxFilterOptionsDictionary)
200
+ filteringOptions = inboxFilterOptions
201
+ }
202
+ MobileMessaging.inbox?.fetchInbox(externalUserId: externalUserId, options: filteringOptions, completion: { (inbox, error) in
203
+ if let error = error {
204
+ onError([error.reactNativeObject])
205
+ } else {
206
+ onSuccess([inbox?.dictionary ?? [:]])
207
+ }
208
+ })
209
+ }
210
+
211
+ @objc(setInboxMessagesSeen:messages:onSuccess:onError:)
212
+ func setInboxMessagesSeen(externalUserId: String, messages: [String]?, onSuccess: @escaping RCTResponseSenderBlock, onError: @escaping RCTResponseSenderBlock) {
213
+ guard let messagesIDs = messages else
214
+ {
215
+ onError([NSError(type: .InvalidArguments).reactNativeObject])
216
+ return
217
+ }
218
+ MobileMessaging.inbox?.setSeen(externalUserId: externalUserId, messageIds: messagesIDs, completion: { (error) in
219
+ if let error = error {
220
+ onError([error.reactNativeObject])
221
+ } else {
222
+ onSuccess(messagesIDs)
223
+ }
224
+ })
225
+ }
226
+
178
227
 
179
228
  @objc(fetchUser:onError:)
180
229
  func fetchUser(onSuccess: @escaping RCTResponseSenderBlock, onError: @escaping RCTResponseSenderBlock) {
@@ -48,5 +48,9 @@ RCT_EXTERN_METHOD(submitEventImmediately:(NSDictionary *)eventData onSuccess:(RC
48
48
  */
49
49
  RCT_EXTERN_METHOD(showDialogForError:(int)errorCode onSuccess:(RCTResponseSenderBlock)successCallback onError:(RCTResponseSenderBlock)errorCallback)
50
50
 
51
+ /*Inbox*/
52
+ RCT_EXTERN_METHOD(fetchInboxMessages:(NSString *)token externalUserId:(NSString *)externalUserId inboxFilterOptions:(NSDictionary *)inboxFilterOptions onSuccess:(RCTResponseSenderBlock)successCallback onError:(RCTResponseSenderBlock)errorCallback)
53
+ RCT_EXTERN_METHOD(fetchInboxMessagesWithoutToken:(NSString *)externalUserId inboxFilterOptions:(NSDictionary *)inboxFilterOptions onSuccess:(RCTResponseSenderBlock)successCallback onError:(RCTResponseSenderBlock)errorCallback)
54
+ RCT_EXTERN_METHOD(setInboxMessagesSeen:(NSString *)externalUserId messages:(NSArray *)messages onSuccess:(RCTResponseSenderBlock)successCallback onError:(RCTResponseSenderBlock)errorCallback)
51
55
  @end
52
56
 
@@ -14,7 +14,8 @@ public enum RNMobileMessagingErrorType: Error {
14
14
  case InvalidUserIdentity
15
15
  case DefaultStorageNotInitialized
16
16
  case NotSupported
17
-
17
+ case NoData
18
+
18
19
  fileprivate var errorCode: Int {
19
20
  switch self {
20
21
  case .InvalidArguments:
@@ -25,13 +26,15 @@ public enum RNMobileMessagingErrorType: Error {
25
26
  return 2
26
27
  case .NotSupported:
27
28
  return 3
29
+ case .NoData:
30
+ return 4
28
31
  }
29
-
32
+
30
33
  }
31
-
34
+
32
35
  fileprivate var errorDescription: String {
33
36
  var errorDescription: String = ""
34
-
37
+
35
38
  switch self {
36
39
  case .InvalidArguments:
37
40
  errorDescription = NSLocalizedString("Could not retrieve required arguments.", comment: "")
@@ -41,8 +44,9 @@ public enum RNMobileMessagingErrorType: Error {
41
44
  errorDescription = NSLocalizedString("Default storage not initialized.", comment: "")
42
45
  case .NotSupported:
43
46
  errorDescription = NSLocalizedString("Functionality is not supported.", comment: "")
47
+ case .NoData:
48
+ errorDescription = NSLocalizedString("No data retrieved.", comment: "")
44
49
  }
45
-
46
50
  return errorDescription
47
51
  }
48
52
 
@@ -37,6 +37,16 @@ extension MM_MTMessage {
37
37
  }
38
38
  }
39
39
 
40
+ extension MMInbox {
41
+ func dictionary() -> [String: Any] {
42
+ var result = [String: Any]()
43
+ result["countTotal"] = countTotal
44
+ result["countUnread"] = countUnread
45
+ result["messages"] = messages.map({ return $0.dictionaryRepresentation })
46
+ return result
47
+ }
48
+ }
49
+
40
50
  extension MMBaseMessage {
41
51
  class func createFrom(dictionary: [String: Any]) -> MMBaseMessage? {
42
52
  guard let messageId = dictionary["messageId"] as? String,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "infobip-mobile-messaging-react-native-plugin",
3
3
  "title": "Infobip Mobile Messaging React Native Plugin",
4
- "version": "11.3.2",
4
+ "version": "12.0.0",
5
5
  "description": "Infobip Mobile Messaging React Native Plugin",
6
6
  "main": "./src/index.js",
7
7
  "scripts": {
package/src/index.d.ts CHANGED
@@ -90,6 +90,7 @@ declare namespace MobileMessagingReactNative {
90
90
  }
91
91
 
92
92
  export interface Installation {
93
+ pushRegistrationId?: string | undefined;
93
94
  isPrimaryDevice?: boolean | undefined;
94
95
  isPushRegistrationEnabled?: boolean | undefined;
95
96
  notificationsEnabled?: boolean | undefined;
@@ -114,6 +115,19 @@ declare namespace MobileMessagingReactNative {
114
115
  externalUserId?: string;
115
116
  }
116
117
 
118
+ export interface MMInbox {
119
+ countTotal: number;
120
+ countUnread: number;
121
+ messages?: [Message] | undefined;
122
+ }
123
+
124
+ export interface MMInboxFilterOptions {
125
+ fromDateTime?: String | undefined;
126
+ toDateTime?: String | undefined;
127
+ topic?: string | undefined;
128
+ limit?: number | undefined;
129
+ }
130
+
117
131
  export interface PersonalizeContext {
118
132
  userIdentity: UserIdentity;
119
133
  userAttributes?: Record<string, string | number | boolean | object[]> | undefined;
@@ -242,7 +256,7 @@ declare namespace MobileMessagingReactNative {
242
256
  textContainerTopMargin: double;
243
257
  textContainerLeftPadding: double;
244
258
  textContainerCornerRadius: double;
245
- textViewTopMargin: double;
259
+ textViewTopMargin: double;
246
260
  placeholderHeight: double;
247
261
  placeholderSideMargin: double;
248
262
  buttonHeight: double;
@@ -324,9 +338,7 @@ declare namespace MobileMessagingReactNative {
324
338
  * @param callback. callback
325
339
  * @param onInitError. Error callback
326
340
  */
327
- init(config: Configuration,
328
- callback: () => void,
329
- onInitError?: (error: MobileMessagingError) => void): void;
341
+ init(config: Configuration, callback: () => void, onInitError?: (error: MobileMessagingError) => void): void;
330
342
 
331
343
  /**
332
344
  * Add subscription to event coming from MobileMessaging library.
@@ -335,9 +347,7 @@ declare namespace MobileMessagingReactNative {
335
347
  * @param handler will be called when event occurs
336
348
  * @return subscription, to unregister from this subscription call `unsubscribe(subscription)`
337
349
  */
338
- subscribe(eventName: string,
339
- handler: (data: any) => void
340
- ): EmitterSubscription;
350
+ subscribe(eventName: string, handler: (data: any) => void): EmitterSubscription;
341
351
 
342
352
  /**
343
353
  * Unsubscribe from MobileMessaging library event.
@@ -388,6 +398,7 @@ declare namespace MobileMessagingReactNative {
388
398
  callback: () => void,
389
399
  errorCallback: () => void): void;
390
400
 
401
+
391
402
  /**
392
403
  * Saves user data to the server.
393
404
  *
@@ -407,6 +418,39 @@ declare namespace MobileMessagingReactNative {
407
418
  */
408
419
  fetchUser(callback: (userData: UserData) => void, errorCallback: (error: MobileMessagingError) => void): void;
409
420
 
421
+
422
+ /**
423
+ *Fetch mobile inbox data from the server.
424
+ *@name fetchInboxMessages
425
+ *@param token access token (JWT in a strictly predefined format) required for current user to have access to the Inbox messages
426
+ *@param externalUserId External User ID is meant to be an ID of a user in an external (non-Infobip) service
427
+ *@param filterOptions filtering options applied to messages list in response. Nullable, will return default number of messages
428
+ *@param callback will be called on success
429
+ *@param {Function} errorCallback will be called on error
430
+ */
431
+ fetchInboxMessages(token: String, externalUserId: String, filterOptions: MMInboxFilterOptions, callback: (inbox: MMInbox) => void, errorCallback: (error: MobileMessagingError) => void): void;
432
+
433
+ /**
434
+ *Fetch mobile inbox data from the server.
435
+ *@name fetchInboxMessagesWithoutToken
436
+ *@param externalUserId External User ID is meant to be an ID of a user in an external (non-Infobip) service
437
+ *@param filterOptions filtering options applied to messages list in response. Nullable, will return default number of messages
438
+ *@param callback will be called on success
439
+ *@param {Function} errorCallback will be called on error
440
+ */
441
+ fetchInboxMessagesWithoutToken(externalUserId: String, filterOptions: MMInboxFilterOptions, callback: (inbox: MMInbox) => void, errorCallback: (error: MobileMessagingError) => void): void;
442
+
443
+ /**
444
+ * Set inbox messages as seen.
445
+ *
446
+ * @name setInboxMessagesSeen
447
+ * @param externalUserId External User ID is meant to be an ID of a user in an external (non-Infobip) service
448
+ * @param {Function} messages list of message identifiers to mark as seen
449
+ * @param callback will be called on success
450
+ * @param {Function} errorCallback will be called on error
451
+ */
452
+ setInboxMessagesSeen(externalUserId: String, messages: String[], callback: (messages: String[]) => void, errorCallback: (error: MobileMessagingError) => void): void;
453
+
410
454
  /**
411
455
  * Gets user data from the locally stored cache.
412
456
  *
@@ -422,9 +466,7 @@ declare namespace MobileMessagingReactNative {
422
466
  * @param callback will be called on success
423
467
  * @param errorCallback will be called on error
424
468
  */
425
- saveInstallation(installation: Installation,
426
- callback: (data: Installation) => void,
427
- errorCallback: (error: MobileMessagingError) => void): void;
469
+ saveInstallation(installation: Installation, callback: (data: Installation) => void, errorCallback: (error: MobileMessagingError) => void): void;
428
470
 
429
471
  /**
430
472
  * Fetches installation from the server.
@@ -450,10 +492,7 @@ declare namespace MobileMessagingReactNative {
450
492
  * @param callback will be called on success
451
493
  * @param errorCallback will be called on error
452
494
  */
453
- setInstallationAsPrimary(pushRegistrationId: string,
454
- primary: boolean,
455
- callback: (installation: Installation) => void,
456
- errorCallback: (error: MobileMessagingError) => void): void;
495
+ setInstallationAsPrimary(pushRegistrationId: string, primary: boolean, callback: (installation: Installation) => void, errorCallback: (error: MobileMessagingError) => void): void;
457
496
 
458
497
  /**
459
498
  * Performs personalization of the current installation on the platform.
@@ -462,9 +501,7 @@ declare namespace MobileMessagingReactNative {
462
501
  * @param callback will be called on success
463
502
  * @param errorCallback will be called on error
464
503
  */
465
- personalize(context: PersonalizeContext,
466
- callback: (personalizeContext: PersonalizeContext) => void,
467
- errorCallback: (error: MobileMessagingError) => void): void;
504
+ personalize(context: PersonalizeContext, callback: (personalizeContext: PersonalizeContext) => void, errorCallback: (error: MobileMessagingError) => void): void;
468
505
 
469
506
  /**
470
507
  * Performs depersonalization of the current installation on the platform.
@@ -472,8 +509,7 @@ declare namespace MobileMessagingReactNative {
472
509
  * @param callback will be called on success
473
510
  * @param errorCallback will be called on error
474
511
  */
475
- depersonalize(callback: (personalizeContext: PersonalizeContext) => void,
476
- errorCallback: (error: MobileMessagingError) => void): void;
512
+ depersonalize(callback: (personalizeContext: PersonalizeContext) => void, errorCallback: (error: MobileMessagingError) => void): void;
477
513
 
478
514
  /**
479
515
  * Performs depersonalization of the installation referenced by pushRegistrationId.
@@ -482,9 +518,7 @@ declare namespace MobileMessagingReactNative {
482
518
  * @param callback will be called on success
483
519
  * @param errorCallback will be called on error
484
520
  */
485
- depersonalizeInstallation(pushRegistrationId: string,
486
- callback: (installation: Installation) => void,
487
- errorCallback: (error: MobileMessagingError) => void): void;
521
+ depersonalizeInstallation(pushRegistrationId: string, callback: (installation: Installation) => void, errorCallback: (error: MobileMessagingError) => void): void;
488
522
 
489
523
  /**
490
524
  * Mark messages as seen
@@ -493,9 +527,7 @@ declare namespace MobileMessagingReactNative {
493
527
  * @param callback will be called upon completion
494
528
  * @param errorCallback will be called on error
495
529
  */
496
- markMessagesSeen(messageIds: string[],
497
- callback: (messages: Message[]) => void,
498
- errorCallback: (error: MobileMessagingError) => void): void;
530
+ markMessagesSeen(messageIds: string[], callback: (messages: Message[]) => void, errorCallback: (error: MobileMessagingError) => void): void;
499
531
 
500
532
  /**
501
533
  * Displays built-in error dialog so that user can resolve errors during sdk initialization.
@@ -504,9 +536,7 @@ declare namespace MobileMessagingReactNative {
504
536
  * @param callback will be called upon completion
505
537
  * @param errorCallback will be called on error
506
538
  */
507
- showDialogForError(errorCode: number,
508
- callback: () => void,
509
- errorCallback: (error: MobileMessagingError) => void): void;
539
+ showDialogForError(errorCode: number, callback: () => void, errorCallback: (error: MobileMessagingError) => void): void;
510
540
 
511
541
  defaultMessageStorage(): DefaultMessageStorage | undefined;
512
542
 
@@ -514,7 +544,7 @@ declare namespace MobileMessagingReactNative {
514
544
  * Displays chat view
515
545
  * @param config
516
546
  */
517
- showChat(config?: ChatConfig): void;
547
+ showChat(config ?: ChatConfig): void;
518
548
 
519
549
  /**
520
550
  * Set custom style of In-app chat
@@ -530,8 +560,11 @@ declare namespace MobileMessagingReactNative {
530
560
  setupChatSettings(configuration: ChatCustomizationConfiguration): void;
531
561
 
532
562
  /**
533
- * Set contextual data of the widget
563
+ * Set contextual data of the Livechat Widget.
564
+ * If the function is called when the chat is loaded, data will be sent immediately, otherwise they will be sent to the chat once it is loaded.
565
+ * Every function invocation will overwrite the previous contextual data.
534
566
  *
567
+ * @name sendContextualData
535
568
  * @param data contextual data in the form of JSON string
536
569
  * @param allMultiThreadStrategy multi-thread strategy flag, true -> ALL, false -> ACTIVE
537
570
  * @param {Function} onSuccess success callback
@@ -588,7 +621,7 @@ declare namespace MobileMessagingReactNative {
588
621
  * ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, ACCESS_BACKGROUND_LOCATION
589
622
  * @return
590
623
  */
591
- requestAndroidLocationPermissions(rationale?: Rationale): Promise<boolean>;
624
+ requestAndroidLocationPermissions(rationale ?: Rationale): Promise<boolean>;
592
625
 
593
626
  /**
594
627
  * Registering for POST_NOTIFICATIONS permission for Android 13+
@@ -618,29 +651,30 @@ declare namespace MobileMessagingReactNative {
618
651
  declare var mobileMessaging: MobileMessagingReactNative.Api;
619
652
 
620
653
  declare namespace WebRTCUI {
621
- /**
622
- * Manually enable WebRTCUI calls.
623
- * @name enableCalls
624
- * @param identity String to be used as identity for the WebRTC registration. If left empty, push registration Id will be used instead
625
- * @param {Function} onSuccess success callback
626
- * @param {Function} onError error callback
627
- */
628
- enableCalls(identity: string, onSuccess: () => void, onError: (error: MobileMessagingError) => void): void;
629
-
630
- /**
631
- * Manually enable WebRTCUI LiveChat calls.
632
- * @name enableChatCalls
633
- * @param {Function} onSuccess success callback
634
- * @param {Function} onError error callback
635
- */
636
- enableChatCalls(onSuccess: () => void, onError: (error: MobileMessagingError) => void): void;
637
-
638
- /**
639
- * Manually disable WebRTCUI calls if they were previously enabled. Note: This action may need up to half a minute to be completed,
640
- * and calls may still be received in the meantime.
641
- * @name disableCalls
642
- * @param {Function} onSuccess success callback
643
- * @param {Function} onError error callback
644
- */
645
- disableCalls(onSuccess: () => void, onError: (error: MobileMessagingError) => void): void;
654
+ import MobileMessagingError = MobileMessagingReactNative.MobileMessagingError;
655
+ /**
656
+ * Manually enable WebRTCUI calls.
657
+ * @name enableCalls
658
+ * @param identity String to be used as identity for the WebRTC registration. If left empty, push registration Id will be used instead
659
+ * @param {Function} onSuccess success callback
660
+ * @param {Function} onError error callback
661
+ */
662
+ enableCalls(identity:string, onSuccess:() => void, onError:(error: MobileMessagingError) => void):void;
663
+
664
+ /**
665
+ * Manually enable WebRTCUI LiveChat calls.
666
+ * @name enableChatCalls
667
+ * @param {Function} onSuccess success callback
668
+ * @param {Function} onError error callback
669
+ */
670
+ enableChatCalls(onSuccess:() => void, onError:(error: MobileMessagingError) => void):void;
671
+
672
+ /**
673
+ * Manually disable WebRTCUI calls if they were previously enabled. Note: This action may need up to half a minute to be completed,
674
+ * and calls may still be received in the meantime.
675
+ * @name disableCalls
676
+ * @param {Function} onSuccess success callback
677
+ * @param {Function} onError error callback
678
+ */
679
+ disableCalls(onSuccess:() => void, onError:(error: MobileMessagingError) => void):void;
646
680
  }
package/src/index.js CHANGED
@@ -254,6 +254,46 @@ class MobileMessaging {
254
254
  ReactNativeMobileMessaging.init(config, onSuccess, onError);
255
255
  };
256
256
 
257
+ /**
258
+ *Fetch mobile inbox data from the server.
259
+ *
260
+ * @name fetchInboxMessages
261
+ * @param token access token (JWT in a strictly predefined format) required for current user to have access to the Inbox messages
262
+ * @param externalUserId External User ID is meant to be an ID of a user in an external (non-Infobip) service
263
+ * @param filterOptions filtering options applied to messages list in response. Nullable, will return default number of messages
264
+ * @param onSuccess will be called on success
265
+ * @param {Function} onError will be called on error
266
+ */
267
+ fetchInboxMessages(token, externalUserId, filterOptions, onSuccess = function() {}, onError = function() {}) {
268
+ ReactNativeMobileMessaging.fetchInboxMessages(token, externalUserId, filterOptions, onSuccess, onError);
269
+ };
270
+
271
+ /**
272
+ *Fetch mobile inbox data from the server.
273
+ *
274
+ * @name fetchInboxMessagesWithoutToken
275
+ * @param externalUserId External User ID is meant to be an ID of a user in an external (non-Infobip) service
276
+ * @param filterOptions filtering options applied to messages list in response. Nullable, will return default number of messages
277
+ * @param onSuccess will be called on success
278
+ * @param {Function} onError will be called on error
279
+ */
280
+ fetchInboxMessagesWithoutToken(externalUserId, filterOptions, onSuccess = function() {}, onError = function() {}) {
281
+ ReactNativeMobileMessaging.fetchInboxMessagesWithoutToken(externalUserId, filterOptions, onSuccess, onError);
282
+ };
283
+
284
+ /**
285
+ * Set inbox messages as seen.
286
+ *
287
+ * @name setInboxMessagesSeen
288
+ * @param externalUserId External User ID is meant to be an ID of a user in an external (non-Infobip) service
289
+ * @param {Function} messages - array of inbox message IDs to be set seen
290
+ * @param {Function} onSuccess will be called with fetched inbox seen messages data on success
291
+ * @param {Function} onError will be called on error
292
+ */
293
+ setInboxMessagesSeen(externalUserId, messages, onSuccess, onError = function() {}) {
294
+ ReactNativeMobileMessaging.setInboxMessagesSeen(externalUserId, messages, onSuccess, onError);
295
+ };
296
+
257
297
  /**
258
298
  * Saves user data to the server.
259
299
  *
@@ -558,7 +598,9 @@ class MobileMessaging {
558
598
  };
559
599
 
560
600
  /**
561
- * Set contextual data of the widget
601
+ * Set contextual data of the Livechat Widget.
602
+ * If the function is called when the chat is loaded, data will be sent immediately, otherwise they will be sent to the chat once it is loaded.
603
+ * Every function invocation will overwrite the previous contextual data.
562
604
  *
563
605
  * @name sendContextualData
564
606
  * @param data - contextual data in the form of JSON string