vibes-react-native 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -151,7 +151,7 @@ const App = (): React.ReactElement => {
151
151
  }
152
152
  ```
153
153
 
154
- ### Associating a User With a Device for Targeting
154
+ ### associatePerson
155
155
  To link a device to a user, perhaps by their username/email or any other unique identifier, you can use the `associatePerson` bridge function.
156
156
 
157
157
  ```js
@@ -166,6 +166,22 @@ const onPress = () => {
166
166
  };
167
167
  ```
168
168
 
169
+ ### getPerson
170
+ To fetch details of a person associated with a device, use `getPerson` bridge function.
171
+
172
+ ```js
173
+
174
+ const onPress = () => {
175
+ try {
176
+ const result = await Vibes.getPerson();
177
+ console.log(result.person_key())
178
+ console.log(result.external_person_id())
179
+ } catch (error) {
180
+ console.error(error);
181
+ }
182
+ };
183
+ ```
184
+
169
185
  ### updateDevice
170
186
  This call updates client device information with Vibes. It returns a promise, which on success contains no data and on failure contains an error message. The method requires key parameters i.e.
171
187
  > updateCredential of type boolean which indicates whether an update is a token update otherwise false
@@ -275,6 +291,103 @@ class RichPushNotificationParsing: NSObject {
275
291
  10. You should end up with Rich Push notification, when you send a broadcast that has a media attachment from the Campaign Manager.
276
292
 
277
293
  > More information about setting up your iOS app for Rich Push notifications can be found [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ModifyingNotifications.html#//apple_ref/doc/uid/TP40008194-CH16-SW1)
294
+
295
+
296
+ ## Inbox Support
297
+ This SDK also supports interaction with inbox messages. The following actions are available for inbox message support.
298
+
299
+ ### fetchInboxMessages
300
+ This call returns a JSON array of inbox messages that have been received for this person. The promise returns on success with the array of inbox messages, or an error message when there's a failure. The array of fetched inbox messages should look like below.
301
+
302
+ ```
303
+ [
304
+ {
305
+
306
+ "content": "Content here",
307
+ "created_at": "Jun 16, 2020 6:26:52 PM",
308
+ "expires_at": "Sep 14, 2020 12:00:00 AM",
309
+ "message_uid": "a62b9c70-3b50-40c0-aaf5-9d55c0149e7c",
310
+ "read": false,
311
+ "subject": "Subject here",
312
+ "collapse_key": "vibes-acee3b99-10c1-4dd5-b0e5-1589296ba3a2",
313
+ "detail": "https://publiclyhostedurl.com/image.png",
314
+ "images": {
315
+ "icon": "https://publiclyhostedurl.com/icon.jpg",
316
+ "main": "https://publiclyhostedurl.com/main.jpg"
317
+ },
318
+ "apprefdata": {
319
+ "personUid": "83497970-280e-4cc8-92c3-e699c3db0738",
320
+ "activityUid": "acee3b99-10c1-4dd5-b0e5-1589296ba3a2",
321
+ "vibesDeviceId": "32515f9b-f722-4914-9afc-c734790e5789",
322
+ "flightUid": "f76cd0c9-6245-4ea1-ae36-0b5a13b8fba5",
323
+ "deviceUid": "7e0d100e-c549-4d0d-a28f-3f7336c04f3e",
324
+ "activityType": "Broadcast",
325
+ "last_opened_at": "2020-06-16T18:25:55Z"
326
+ }
327
+ },
328
+ {
329
+
330
+ "content": "This is the content",
331
+ "created_at": "Jun 16, 2020 6:26:20 PM",
332
+ "expires_at": "Sep 14, 2020 12:00:00 AM",
333
+ "message_uid": "3407658c-85d2-439c-9c6d-2b642ef78761",
334
+ "read": false,
335
+ "subject": "This is the message",
336
+ "collapse_key": "vibes-c9ae6ba9-8041-437d-9521-c3db803c19ce",
337
+ "detail": "https://publiclyhostedurl.com/image.png",
338
+ "images": {
339
+ "icon": "https://publiclyhostedurl.com/icon.jpg",
340
+ "main": "https://publiclyhostedurl.com/main.jpg"
341
+ },
342
+ "apprefdata": {
343
+ "personUid": "83497970-280e-4cc8-92c3-e699c3db0738",
344
+ "activityUid": "c9ae6ba9-8041-437d-9521-c3db803c19ce",
345
+ "vibesDeviceId": "32515f9b-f722-4914-9afc-c734790e5789",
346
+ "flightUid": "bcfe6100-516a-484f-84cb-60686e216041",
347
+ "deviceUid": "7e0d100e-c549-4d0d-a28f-3f7336c04f3e",
348
+ "activityType": "Broadcast",
349
+ "last_opened_at": "2020-06-16T18:25:55Z"
350
+ },
351
+ }
352
+ ]
353
+ ```
354
+
355
+ ### fetchInboxMessage
356
+ This call fetches a single inbox message based on the `message_uid` supplied. This is ideal for cases when a push message is linked to an inbox message. It returns a promise, which contains the inbox message on success, or an error message on failure. Note that the `message_uid` is required to invoke this call.
357
+
358
+ ```
359
+ {
360
+ "collapse_key": "vibes-acee3b99-10c1-4dd5-b0e5-1589296ba3a2",
361
+ "content": "Content here",
362
+ "created_at": "Jun 16, 2020 6:26:52 PM",
363
+ "expires_at": "Sep 14, 2020 12:00:00 AM",
364
+ "message_uid": "a62b9c70-3b50-40c0-aaf5-9d55c0149e7c",
365
+ "read": false,
366
+ "subject": "Subject here"
367
+ "apprefdata": {
368
+ "personUid": "83497970-280e-4cc8-92c3-e699c3db0738",
369
+ "activityUid": "acee3b99-10c1-4dd5-b0e5-1589296ba3a2",
370
+ "vibesDeviceId": "32515f9b-f722-4914-9afc-c734790e5789",
371
+ "flightUid": "f76cd0c9-6245-4ea1-ae36-0b5a13b8fba5",
372
+ "deviceUid": "7e0d100e-c549-4d0d-a28f-3f7336c04f3e",
373
+ "activityType": "Broadcast",
374
+ "last_opened_at": "2020-06-16T18:25:55Z"
375
+ }
376
+ }
377
+ ```
378
+
379
+ ### expireInboxMessage
380
+ This call is used to mark a message for expiry. The call requires a `message_uid`. It marks the message as expired immediately. The promise returns with the updated json payload of the expired message, or an error message if there's a failure. Note that the `message_uid` is required to invoke this call.
381
+
382
+ ### markInboxMessageAsRead
383
+ This call is used to mark a message as read. The call requires a `message_uid`. The promise returns with the updated json payload with the `read` field set to true, or an error message if there's a failure. Note that the `message_uid` is required to invoke this call.
384
+
385
+ ### onInboxMessageOpen
386
+ This call generates an event showing that a single inbox message has been opened. The call requires the full message that has been viewed to be passed as JSON. The promise returns with no data on success, or an error message on failure.
387
+
388
+ ### onInboxFetched
389
+ This call generates an event for tracking the usage of inbox functionality by recording the most recent time when inbox messages were fetched for the person on this device. It should typically be called after the `fetchInboxMessages` call above. The promise returns with no data on success, or an error message on failure.
390
+
278
391
  ## License
279
392
 
280
393
  MIT
@@ -1,61 +1,63 @@
1
1
  buildscript {
2
- if (project == rootProject) {
3
- repositories {
4
- google()
5
- mavenCentral()
6
- jcenter()
7
- }
8
-
9
- dependencies {
10
- classpath 'com.android.tools.build:gradle:3.5.3'
11
- }
2
+ if (project == rootProject) {
3
+ repositories {
4
+ google()
5
+ mavenCentral()
6
+ jcenter()
12
7
  }
8
+
9
+ dependencies {
10
+ classpath 'com.android.tools.build:gradle:3.5.4'
11
+ }
12
+ }
13
13
  }
14
14
 
15
15
  apply plugin: 'com.android.library'
16
16
 
17
17
  def safeExtGet(prop, fallback) {
18
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
18
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
19
19
  }
20
20
 
21
21
  android {
22
- compileSdkVersion safeExtGet('Vibes_compileSdkVersion', 29)
23
- defaultConfig {
24
- minSdkVersion safeExtGet('Vibes_minSdkVersion', 19)
25
- targetSdkVersion safeExtGet('Vibes_targetSdkVersion', 30)
22
+ compileSdkVersion safeExtGet('Vibes_compileSdkVersion', 31)
23
+ defaultConfig {
24
+ minSdkVersion safeExtGet('Vibes_minSdkVersion', 19)
25
+ targetSdkVersion safeExtGet('Vibes_targetSdkVersion', 31)
26
26
 
27
- }
27
+ }
28
28
 
29
- buildTypes {
30
- release {
31
- minifyEnabled false
32
- }
33
- }
34
- lintOptions {
35
- disable 'GradleCompatible'
36
- }
37
- compileOptions {
38
- sourceCompatibility JavaVersion.VERSION_1_8
39
- targetCompatibility JavaVersion.VERSION_1_8
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
40
32
  }
33
+ }
34
+ lintOptions {
35
+ disable 'GradleCompatible'
36
+ }
37
+ compileOptions {
38
+ sourceCompatibility JavaVersion.VERSION_1_8
39
+ targetCompatibility JavaVersion.VERSION_1_8
40
+ }
41
41
  }
42
42
 
43
43
  repositories {
44
- mavenLocal()
45
- maven {
46
- // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
47
- url("$rootDir/../node_modules/react-native/android")
48
- }
49
- google()
50
- mavenCentral()
51
- jcenter()
44
+ mavenLocal()
45
+ maven {
46
+ // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
47
+ url("$rootDir/../node_modules/react-native/android")
48
+ }
49
+ google()
50
+ mavenCentral()
51
+ jcenter()
52
52
 
53
53
  }
54
54
 
55
55
  dependencies {
56
- //noinspection GradleDynamicVersion
57
- implementation "com.facebook.react:react-native:+" // From node_modules
58
- api "com.vibes.vibes:vibes:4.6.0"
59
- implementation 'com.google.firebase:firebase-iid:21.0.0'
60
- implementation 'com.google.firebase:firebase-messaging:21.0.0'
56
+ //noinspection GradleDynamicVersion
57
+ implementation "com.facebook.react:react-native:+" // From node_modules
58
+ api "com.vibes.vibes:vibes:4.9.0"
59
+ implementation 'com.google.firebase:firebase-iid:21.1.0'
60
+ implementation 'com.google.firebase:firebase-messaging:23.0.8'
61
+ implementation 'com.google.code.gson:gson:2.9.0'
62
+
61
63
  }
@@ -4,16 +4,18 @@
4
4
 
5
5
  <uses-permission android:name="android.permission.INTERNET" />
6
6
  <uses-permission android:name="android.permission.WAKE_LOCK" />
7
-
7
+
8
8
  <application>
9
9
 
10
- <service android:name=".notifications.Fms">
10
+ <service android:name=".notifications.Fms"
11
+ android:exported="false">
11
12
  <intent-filter>
12
13
  <action android:name="com.google.firebase.MESSAGING_EVENT" />
13
14
  </intent-filter>
14
15
  </service>
15
16
 
16
- <receiver android:name=".notifications.VibesPushReceiver">
17
+ <receiver android:name=".notifications.VibesPushReceiver"
18
+ android:exported="false">
17
19
  <intent-filter>
18
20
  <category android:name="${applicationId}" />
19
21
 
@@ -23,6 +25,6 @@
23
25
  </receiver>
24
26
 
25
27
  </application>
26
-
28
+
27
29
 
28
30
  </manifest>
@@ -3,98 +3,184 @@ package com.vibes.push.rn.plugin;
3
3
  import android.app.Application;
4
4
  import android.content.Context;
5
5
  import android.content.Intent;
6
+ import android.content.SharedPreferences;
7
+ import android.preference.PreferenceManager;
6
8
  import android.util.Log;
7
9
  import com.facebook.react.bridge.Arguments;
8
10
  import com.facebook.react.bridge.WritableMap;
11
+ import com.facebook.react.bridge.WritableNativeMap;
12
+ import org.json.*;
13
+ import com.facebook.react.bridge.*;
9
14
 
10
- import android.content.SharedPreferences;
11
- import android.preference.PreferenceManager;
15
+
16
+ import java.util.Iterator;
12
17
 
13
18
  import static com.vibes.push.rn.plugin.VibesModule.TAG;
14
19
 
15
20
  /**
16
21
  * Utility class for obtaining items from the ApplicationContext
17
22
  */
18
- public class VibesAppHelper{
19
- private Context context;
20
-
21
- public VibesAppHelper(Application context){
22
- this.context = context;
23
- }
24
-
25
- /**
26
- * Returns the push token already stored in shared preferences after Firebase runtime was initialized.
27
- * @return
28
- */
29
- public String getPushToken(){
30
- return getSharedPreferences().getString(VibesModule.TOKEN_KEY, null);
31
- }
32
-
33
- /**
34
- * Returns the Vibes device id already stored in shared preferences after Vibes SDK was initialized.
35
- * @return
36
- */
37
- public String getDeviceId(){
38
- return getSharedPreferences().getString(VibesModule.DEVICE_ID, null);
39
- }
40
-
41
- /**
42
- * Returns a Map containing items for <code>device_id</code> and <code>push_token</code> keys to enable quick display.
43
- *
44
- * @return
45
- */
46
- public WritableMap getDeviceInfo(){
47
- WritableMap map = Arguments.createMap();
48
- map.putString("device_id", getDeviceId());
49
- map.putString("push_token", getPushToken());
50
- return map;
51
- }
52
-
53
- public void saveString(String key, String value){
54
- SharedPreferences.Editor editor = getSharedPreferences().edit();
55
- editor.putString(key, value);
56
- editor.apply();
57
- }
58
-
59
- public void saveBoolean(String key, boolean value){
60
- SharedPreferences.Editor editor = getSharedPreferences().edit();
61
- editor.putBoolean(key, value);
62
- editor.apply();
63
- }
64
-
65
- public boolean getBoolean(String key, boolean alternative){
66
- return getSharedPreferences().getBoolean(key, alternative);
67
- }
68
-
69
- public String getString(String key, String alternative){
70
- return getSharedPreferences().getString(key, alternative);
71
- }
72
-
73
- private SharedPreferences getSharedPreferences(){
74
- return PreferenceManager.getDefaultSharedPreferences(this.context);
75
- }
76
-
77
- private Class getMainActivityClass() {
78
- String packageName = context.getPackageName();
79
- Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
80
- String className = launchIntent.getComponent().getClassName();
81
- try {
82
- return Class.forName(className);
83
- } catch (ClassNotFoundException e) {
84
- e.printStackTrace();
85
- return null;
86
- }
87
- }
88
-
89
- public void invokeApp() {
90
- try {
91
- Class<?> activityClass = getMainActivityClass();
92
- Intent activityIntent = new Intent(context, activityClass);
93
- activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
94
- context.startActivity(activityIntent);
95
- } catch(Exception e) {
96
- Log.e(TAG, "Class not found", e);
97
- return;
98
- }
99
- }
23
+ public class VibesAppHelper {
24
+ private final Context context;
25
+
26
+ public VibesAppHelper(Application context) {
27
+ this.context = context;
28
+ }
29
+
30
+ public WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
31
+ WritableMap map = new WritableNativeMap();
32
+
33
+ Iterator<String> iterator = jsonObject.keys();
34
+ while (iterator.hasNext()) {
35
+ String key = iterator.next();
36
+ Object value = jsonObject.get(key);
37
+ if (value instanceof JSONObject) {
38
+ map.putMap(key, convertJsonToMap((JSONObject) value));
39
+ } else if (value instanceof Boolean) {
40
+ map.putBoolean(key, (Boolean) value);
41
+ } else if (value instanceof Integer) {
42
+ map.putInt(key, (Integer) value);
43
+ } else if (value instanceof Double) {
44
+ map.putDouble(key, (Double) value);
45
+ } else if (value instanceof String) {
46
+ map.putString(key, (String) value);
47
+ } else {
48
+ map.putString(key, value.toString());
49
+ }
50
+ }
51
+ return map;
52
+ }
53
+
54
+ public JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException {
55
+ JSONObject object = new JSONObject();
56
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
57
+ while (iterator.hasNextKey()) {
58
+ String key = iterator.nextKey();
59
+ switch (readableMap.getType(key)) {
60
+ case Null:
61
+ object.put(key, JSONObject.NULL);
62
+ break;
63
+ case Boolean:
64
+ object.put(key, readableMap.getBoolean(key));
65
+ break;
66
+ case Number:
67
+ object.put(key, readableMap.getDouble(key));
68
+ break;
69
+ case String:
70
+ object.put(key, readableMap.getString(key));
71
+ break;
72
+ case Map:
73
+ object.put(key, convertMapToJson(readableMap.getMap(key)));
74
+ break;
75
+ case Array:
76
+ object.put(key, convertArrayToJson(readableMap.getArray(key)));
77
+ break;
78
+ }
79
+ }
80
+ return object;
81
+ }
82
+
83
+ public JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
84
+ JSONArray array = new JSONArray();
85
+ for (int i = 0; i < readableArray.size(); i++) {
86
+ switch (readableArray.getType(i)) {
87
+ case Null:
88
+ break;
89
+ case Boolean:
90
+ array.put(readableArray.getBoolean(i));
91
+ break;
92
+ case Number:
93
+ array.put(readableArray.getDouble(i));
94
+ break;
95
+ case String:
96
+ array.put(readableArray.getString(i));
97
+ break;
98
+ case Map:
99
+ array.put(convertMapToJson(readableArray.getMap(i)));
100
+ break;
101
+ case Array:
102
+ array.put(convertArrayToJson(readableArray.getArray(i)));
103
+ break;
104
+ }
105
+ }
106
+ return array;
107
+ }
108
+
109
+ /**
110
+ * Returns the push token already stored in shared preferences after Firebase runtime was initialized.
111
+ *
112
+ * @return
113
+ */
114
+ public String getPushToken() {
115
+ return getSharedPreferences().getString(VibesModule.TOKEN_KEY, null);
116
+ }
117
+
118
+ /**
119
+ * Returns the Vibes device id already stored in shared preferences after Vibes SDK was initialized.
120
+ *
121
+ * @return
122
+ */
123
+ public String getDeviceId() {
124
+ return getSharedPreferences().getString(VibesModule.DEVICE_ID, null);
125
+ }
126
+
127
+ /**
128
+ * Returns a Map containing items for <code>device_id</code> and <code>push_token</code> keys to enable quick display.
129
+ *
130
+ * @return
131
+ */
132
+ public WritableMap getDeviceInfo() {
133
+ WritableMap map = Arguments.createMap();
134
+ map.putString("device_id", getDeviceId());
135
+ map.putString("push_token", getPushToken());
136
+ return map;
137
+ }
138
+
139
+ public void saveString(String key, String value) {
140
+ SharedPreferences.Editor editor = getSharedPreferences().edit();
141
+ editor.putString(key, value);
142
+ editor.apply();
143
+ }
144
+
145
+ public void saveBoolean(String key, boolean value) {
146
+ SharedPreferences.Editor editor = getSharedPreferences().edit();
147
+ editor.putBoolean(key, value);
148
+ editor.apply();
149
+ }
150
+
151
+ public boolean getBoolean(String key, boolean alternative) {
152
+ return getSharedPreferences().getBoolean(key, alternative);
153
+ }
154
+
155
+ public String getString(String key, String alternative) {
156
+ return getSharedPreferences().getString(key, alternative);
157
+ }
158
+
159
+ private SharedPreferences getSharedPreferences() {
160
+ return PreferenceManager.getDefaultSharedPreferences(this.context);
161
+ }
162
+
163
+ private Class getMainActivityClass() {
164
+ String packageName = context.getPackageName();
165
+ Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
166
+ String className = launchIntent.getComponent().getClassName();
167
+ try {
168
+ return Class.forName(className);
169
+ } catch (ClassNotFoundException e) {
170
+ e.printStackTrace();
171
+ return null;
172
+ }
173
+ }
174
+
175
+ public void invokeApp() {
176
+ try {
177
+ Class<?> activityClass = getMainActivityClass();
178
+ Intent activityIntent = new Intent(context, activityClass);
179
+ activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
180
+ context.startActivity(activityIntent);
181
+ } catch (Exception e) {
182
+ Log.e(TAG, "Class not found", e);
183
+ return;
184
+ }
185
+ }
100
186
  }