smartmessage-react-native 2.11.2

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 ADDED
@@ -0,0 +1,494 @@
1
+ # Smart Message Engage React Native SDK
2
+ > Last Update: `08.05.2025`
3
+ > Last Version: `v2.0.11`
4
+ ## Installation
5
+ npm install react-native-smartmessage
6
+
7
+ # Android Specific Install
8
+ `{YOUR_PORJECT}/android/app/build.gradle`
9
+ ```groovy
10
+ ...
11
+ dependencies {
12
+ ...
13
+ implementation 'io.github.smartmessagesdk:smartmessage-sdk:<latest-version>'
14
+ }
15
+ ...
16
+ ```
17
+
18
+ ---
19
+ # 🔥 Firebase Project
20
+ We need `google-services.json` file.
21
+ ###### follow the links
22
+ https://firebase.google.com/docs/android/setup
23
+ https://support.google.com/firebase/answer/7015592
24
+
25
+ after downloading `google-services.json` file, move to `{YOUR_APP}/android/app/google-services.json`
26
+
27
+ `{YOUR_PROJECT}/android/build.gradle`
28
+
29
+ ```groovy
30
+ buildscript {
31
+ ...
32
+ dependencies {
33
+ ...
34
+ classpath 'com.github.kezong:fat-aar:1.3.6' // add this line
35
+ classpath 'com.google.gms:google-services:4.3.10' // add this line
36
+ }
37
+ }
38
+ ```
39
+
40
+ `{YOUR_PROJECT}/android/app/build.gradle`
41
+ (add to the bottom line of dependencies definitions)
42
+ ```groovy
43
+ ...
44
+ apply plugin: 'com.google.gms.google-services' // add this line
45
+ ```
46
+
47
+ ---
48
+ # 📝 SmartMessage config file
49
+ you can access this file from SmartMessage panel
50
+ `{YOUR_PROJECT}/android/app/src/main/assets/sme-config.json`
51
+
52
+ ⚠️ The config file should contain hashed value containing Basic Auth credentials. For Example:
53
+ ```javascript
54
+ {
55
+ ...
56
+ "credential": "6d6847e878d7076bd6057b4618eec0c79bfc3c93fa661feb4f63d1413b08a3d50e147384eeff624df7d210db0cb4343db67a6923c980a646c7ecffea6b8736819fe75998f3b080c2ba11ba301ae81457f5dd5844bf9d0ffae50223601d82bcdc",
57
+ ...
58
+ }
59
+ ```
60
+
61
+ ---
62
+
63
+ # 🤝 SDK Initilization
64
+ Add this line to `onCreate` method of `Application` subclass
65
+ #### Like this
66
+ ```java
67
+ ...
68
+ import tr.com.odc.smartmessage.SmartMessage; // add this line
69
+
70
+ public class MainApplication extends Application {
71
+ @Override
72
+ public void onCreate() {
73
+ super.onCreate();
74
+ SmartMessage.getInstance().init(this); // add this line
75
+ //..
76
+ }
77
+ }
78
+ ```
79
+
80
+ # 💂‍♂️ ProGuard Rule
81
+ If you're using `shrinkResources` and `minifyEnabled`, you should add the proguard rule.
82
+ ```java
83
+ -keep class tr.com.odc.smartmessage.** { *; }
84
+ ```
85
+
86
+ ## 🔔 Notification Icon
87
+ The drawable folders can contain the file `sme_ic_notification.png`
88
+ [Check this doc for more information](http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/#dimensions)
89
+ If this drawable file is missing, the app’s default launcher icon will show.
90
+
91
+ ## 🔔 Notification Sound
92
+ If you want to use a different sound than the default notification sound of the device.
93
+ `{YOUR_PROJECT}/android/app/src/main/res/raw` folder can contain the file `sme_sound.wav`
94
+ If this sound file is missing, the device's default notification sound will play.
95
+
96
+ ---
97
+ # 🖌 Dialog Designs
98
+ We have provided a flexible design structure for you. You should keep the xml Layout files we shared with you in the relevant place.
99
+ `You can change these designs as you wish but you should not change the classes and ids`
100
+
101
+ ##### `{YOUR_PROJECT}`/android/app/src/main/res/layout
102
+ - sme_0_basic_layout.xml
103
+ - sme_1_image_layout.xml
104
+ - sme_2_14_html_dialog_layout.xml
105
+ - sme_3_gif_layout.xml
106
+ - sme_4_video_layout.xml
107
+ - sme_5_audio_layout.xml
108
+ - sme_6_carousel_basic_layout.xml
109
+ - sme_7_carousel_rotary_layout.xml
110
+ - sme_8_carousel_coverflow_layout.xml
111
+ - sme_9_slider_layout.xml
112
+ - sme_10_small_dialog_layout.xml
113
+ - sme_10_small_dialog_button.xml
114
+ - sme_11_medium_dialog_layout.xml
115
+ - sme_12_fullscreen_dialog_layout.xml
116
+ - sme_13_interactive_dialog_layout.xml
117
+ - sme_audio_player.xml
118
+ - sme_common_button.xml
119
+ - sme_common_header.xml
120
+ - sme_common_title_and_message.xml
121
+ - sme_slide_layout.xml
122
+ - sme_audio_player.xml
123
+
124
+
125
+ ##### `{YOUR_PROJECT}`/android/app/src/main/res/anim
126
+ > It is the enter and exit animations of the dialogs of the SDK opened in the application. It enters from right to left. Exits left to right. You can change it as you wish.
127
+ - sme_enter_anim.xml
128
+ - sme_exit_anim.xml
129
+
130
+
131
+ ##### `{YOUR_PROJECT}`/android/app/src/main/res/drawable
132
+ - sme_ic_play_audio.png
133
+ - sme_ic_stop_audio.png
134
+ - sme_ic_back_arrow.png
135
+
136
+
137
+ # Deep Link
138
+
139
+ ```xml
140
+ <activity
141
+ android:name=".MainActivity"
142
+ ...
143
+ >
144
+ <intent-filter>
145
+ <action android:name="android.intent.action.MAIN" />
146
+ <category android:name="android.intent.category.LAUNCHER" />
147
+ </intent-filter>
148
+ <intent-filter> <!-- add this line -->
149
+ <action android:name="android.intent.action.VIEW" /> <!-- add this line -->
150
+ <category android:name="android.intent.category.DEFAULT" /> <!-- add this line -->
151
+ <category android:name="android.intent.category.BROWSABLE" /> <!-- add this line -->
152
+ <data android:scheme="YOUR_SCHEME" /> <!-- add this line -->
153
+ </intent-filter><!-- add this line -->
154
+ </activity>
155
+ ```
156
+
157
+ ```javascript
158
+ import { Linking } from 'react-native';
159
+
160
+ const handleDeeplink = (url) => {
161
+ if (url === 'YOUR_SCHEME://campaigns') {
162
+ // ex: navigationRef.current.navigate('Campaigns')
163
+ }
164
+ }
165
+
166
+ React.useEffect(() => {
167
+ // Handle the deeplink that launches the application.
168
+ Linking.getInitialURL().then((url) => {
169
+ handleDeeplink(url)
170
+ }).catch((error) => {
171
+ // handle error
172
+ })
173
+
174
+ // Handle the deeplink while the application is running.
175
+ let unsubscribe = Linking.addEventListener('url', ({ url }) => {
176
+ handleDeeplink(url)
177
+ });
178
+
179
+ return unsubscribe
180
+ }, [])
181
+
182
+ ```
183
+
184
+
185
+ # 🔎 How do I distinguish it from other SDKs?
186
+ It is important that you inherit from the SMEMessagingService class.
187
+ ```java
188
+ public class MyFirebaseService extends SMEMessagingService {
189
+
190
+ @Override
191
+ public void onNewToken(String token) {
192
+ super.onNewToken(token);
193
+ }
194
+
195
+ @Override
196
+ public void onMessageReceived(RemoteMessage remoteMessage) {
197
+ super.onMessageReceived(remoteMessage);
198
+ // sdk does its own vendor check
199
+
200
+ String vendor = remoteMessage.getData().get("vendor");
201
+ // check vendor field
202
+ if (!vendor.equals(SmartMessage.VENDOR)) {
203
+ // your codes
204
+ }
205
+ }
206
+ }
207
+ ```
208
+
209
+
210
+
211
+ # iOS Specific Install
212
+ ---
213
+ > It is very similar to the native iOS SDK document. There are a few minor differences.
214
+ - Open `{PROJECT_PATH}/ios/{PROJECT_NAME}.xcworkspace` folder with Xcode.
215
+ - Create the SmartMessageSdk folder and move the Config.plist file into it.
216
+ - Create an empty swift file to create a Swift bridge in the Objective-C project. After creating the empty swift file, Xcode will ask you if you want to enable bridging. Accept that request.
217
+ ![](https://i.hizliresim.com/D8ts2B.png)
218
+ You can edit it from Target > Build Settings> Swift Compiler - General
219
+ ![](https://i.hizliresim.com/92ZIVq.png)
220
+ Target > Signing & Capabilities> + Capability
221
+ ![](https://i.hizliresim.com/Jx90Q3.png)
222
+ Set app group name in `SmartMessageSdk > Config.plist > appGroupName`
223
+ ![](https://i.hizliresim.com/KDIjgo.png)
224
+
225
+ # Notification Content Extension
226
+ #### `step 1`
227
+ `select Notification Content Extension`
228
+ ![](https://i.hizliresim.com/OaZjVZ.png)
229
+ #### `step 2`
230
+ ![](https://i.hizliresim.com/cx9SXg.png)
231
+ #### `step 3`
232
+ ![](https://i.hizliresim.com/50p4Ck.png)
233
+ #### `step 4`
234
+ #### ⚠️ Create an empty swift file to create a Swift bridge in the Objective-C project. After creating the empty swift file, Xcode will ask you if you want to enable bridging. Accept that request.
235
+ ![](https://i.hizliresim.com/dv13jag.png)
236
+ #### `step 5`
237
+ ![](https://i.hizliresim.com/3qqg2x.png)
238
+
239
+ # Notification Service Extension
240
+ #### `step 1`
241
+ `select Notification Service Extension`
242
+ ![](https://i.hizliresim.com/OaZjVZ.png)
243
+ #### `step 2`
244
+ ![](https://i.hizliresim.com/0EIZM5.png)
245
+ #### `step 3`
246
+ ![](https://i.hizliresim.com/cb3L26.png)
247
+ #### `step 4`
248
+ ##### ⚠️ Create an empty swift file to create a Swift bridge in the Objective-C project. After creating the empty swift file, Xcode will ask you if you want to enable bridging. Accept that request.
249
+ ![](https://i.hizliresim.com/dv13jag.png)
250
+ #### `step 5`
251
+ ![](https://i.hizliresim.com/C2fGvj.png)
252
+
253
+ #### Add search paths to `podfile > target 'TARGET_NAME'` for extensions and run `pod install`
254
+ ```ruby
255
+ target 'BaseNotificationExtension' do
256
+ inherit! :search_paths
257
+ end
258
+
259
+ target 'BaseServiceExtension' do
260
+ inherit! :search_paths
261
+ end
262
+ ```
263
+
264
+ ### AppDelegate.m
265
+ `didRegisterForRemoteNotificationsWithDeviceToken` will be triggered when you get permission from the user to send push notifications. The SDK will register to the server.
266
+
267
+ ```objc
268
+ // ...
269
+ #import <RNSmartMessage/RNSmartMessage.h> // add this line
270
+ // ...
271
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
272
+ {
273
+ [RNSmartMessage initializeSdk:deviceToken]; // add this line
274
+ }
275
+ // ...
276
+ ```
277
+
278
+ ### NotificationService.m
279
+ ```objc
280
+ #import <RNSmartMessage/RNSmartMessage.h> // add this line
281
+
282
+ self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title]; // remove this line
283
+
284
+ // add this lines
285
+ [RNSmartMessage configureNotificationService:request
286
+ contentHandler:self.contentHandler
287
+ bestAttemptContent:self.bestAttemptContent];
288
+ ```
289
+
290
+ ### NotificationViewController.m
291
+ ```objc
292
+ #import <RNSmartMessage/RNSmartMessage.h> // add this line
293
+
294
+ @property IBOutlet UILabel *label; // remove this line
295
+
296
+ self.label.text = notification.request.content.body; // remove this line
297
+
298
+ // add this lines
299
+ [RNSmartMessage handleNotification:self
300
+ baseView:self.view
301
+ userInfo:notification.request.content.userInfo
302
+ isNotificationWillPresent:false];
303
+ ```
304
+
305
+ ![](https://i.hizliresim.com/XL9gCH.png)
306
+
307
+ #### Notification Content Extension > Info.plist
308
+ ###### `Replace this part`
309
+ ```plist
310
+ <key>NSExtensionAttributes</key>
311
+ <dict>
312
+ <key>UNNotificationExtensionCategory</key>
313
+ <string>myNotificationCategory</string>
314
+ <key>UNNotificationExtensionInitialContentSizeRatio</key>
315
+ <real>1</real>
316
+ </dict>
317
+ ```
318
+ ###### `with this part`
319
+ ```plist
320
+ <key>NSExtensionAttributes</key>
321
+ <dict>
322
+ <key>UNNotificationExtensionCategory</key>
323
+ <string>smBaseNotification</string>
324
+ <key>UNNotificationExtensionInitialContentSizeRatio</key>
325
+ <real>1</real>
326
+ <key>UNNotificationExtensionDefaultContentHidden</key>
327
+ <true/>
328
+ <key>UNNotificationExtensionUserInteractionEnabled</key>
329
+ <true/>
330
+ </dict>
331
+ ```
332
+
333
+ # Deep Link
334
+ Let's configure the native iOS app to open based on the `smerndemo://` URI scheme.
335
+
336
+ You'll need to link `RCTLinking` to your project by following the steps described here. To be able to listen to incoming app links, you'll need to add the following lines to `APP_NAME/ios/APP_NAME/AppDelegate.m`
337
+
338
+ ```objc
339
+ // Add the header at the top of the file:
340
+ #import <React/RCTLinkingManager.h>
341
+
342
+ // Add this above `@end`:
343
+ - (BOOL)application:(UIApplication *)application
344
+ openURL:(NSURL *)url
345
+ options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
346
+ {
347
+ return [RCTLinkingManager application:application openURL:url options:options];
348
+ }
349
+ ```
350
+
351
+ ```bash
352
+ npx uri-scheme add smerndemo --ios
353
+ ```
354
+
355
+ ```javascript
356
+ import { Linking } from 'react-native';
357
+
358
+ const handleDeeplink = (url) => {
359
+ if (url === 'smerndemo://campaigns') {
360
+ // ex: navigationRef.current.navigate('Campaigns')
361
+ }
362
+ }
363
+
364
+ React.useEffect(() => {
365
+ // Handle the deeplink that launches the application.
366
+ Linking.getInitialURL().then((url) => {
367
+ handleDeeplink(url)
368
+ }).catch((error) => {
369
+ // handle error
370
+ })
371
+
372
+ // Handle the deeplink while the application is running.
373
+ let unsubscribe = Linking.addEventListener('url', ({ url }) => {
374
+ handleDeeplink(url)
375
+ });
376
+
377
+ return unsubscribe
378
+ }, [])
379
+
380
+ ```
381
+
382
+ # Usage in React Native
383
+ ---
384
+ ```javascript
385
+ import SmartMessage from 'react-native-smartmessage';
386
+ ```
387
+ #### User Info
388
+ ```js
389
+ // GETTER
390
+ SmartMessage.getUserInfo().then((userInfo: UserInfo) => {
391
+ // handle userInfo
392
+ setCurrentUserInfo(userInfo)
393
+ }).catch((error) => {
394
+ // handle error
395
+ });
396
+
397
+ SmartMessage.getMemberFields((memberFields: {FIELDNAME:string}[])=>{
398
+ // returns [
399
+ // {"FIELDNAME":"YOUR_FIELD_NAME_1"},
400
+ // {"FIELDNAME":"YOUR_FIELD_NAME_2"},
401
+ // ]
402
+ });
403
+
404
+
405
+ // SETTER
406
+ SmartMessage.setUserInfo({
407
+ ...userInfo,
408
+ name: 'John',
409
+ surname: 'Doe',
410
+ email: 'john.doe@example.com',
411
+ lang: 'tr',
412
+ gender: '1', // or 0
413
+ tags: ['tag1', 'tag2', 'tag3'].join(','),
414
+ rcv_not: true,
415
+ mobile: '08502213900',
416
+ birthdate: '04.02.2020',
417
+ username: 'johndoe',
418
+ id: 'customer_id_123',
419
+ memberfields: [
420
+ { fieldName: 'YOUR_FIELD_NAME_1', fieldValue: 'VALUE_1' },
421
+ { fieldName: 'YOUR_FIELD_NAME_2', fieldValue: 'VALUE_2' },
422
+ //...
423
+ ]
424
+ }).then(() => {
425
+ // handle success
426
+ }).catch((error) => {
427
+ // handle error
428
+ });
429
+
430
+ ```
431
+
432
+ #### Device Info
433
+ Device information is automatically sent to the server by the SDK.
434
+ ```javascript
435
+ // GETTER
436
+ SmartMessage.getDeviceInfo().then((deviceInfo: DeviceInfo) => {
437
+ // handle deviceInfo
438
+ }).catch((err) => {
439
+ // handle error
440
+ });
441
+ ```
442
+
443
+ # Login & Logout
444
+ ```js
445
+ SmartMessage.reportLoggedIn()
446
+ SmartMessage.reportLoggedOut()
447
+ ```
448
+
449
+ # Analytics
450
+ ```js
451
+ SmartMessage.reportAnalytic(KEYWORD)
452
+ ```
453
+
454
+ # Events
455
+ ```js
456
+ // MESSAGE_ID can be null
457
+ SmartMessage.reportEvent(MESSAGE_ID, EVENT_TYPE, EVENT_NAME, DATA)
458
+ ```
459
+
460
+ # 📬 Inbox
461
+ ```js
462
+ SmartMessage.getMessageList({
463
+ page_index: 1,
464
+ page_size: 20,
465
+ start_date: moment().subtract(1, 'months').format('DD.MM.yyyy HH:mm:ss'),
466
+ end_date: moment().format('DD.MM.yyyy HH:mm:ss'),
467
+ expired_push: true,
468
+ status: ['0', '1', '2'],
469
+ push_type: ['0', '1'],
470
+ }).then((messageListResponse: MessageListResponse) => {
471
+ // handle response
472
+ }).catch((error) => {
473
+ // handle error
474
+ });
475
+ ```
476
+
477
+ If you want to open the notification from the inbox, you can use the `displayMessageContent` method. The SDK will automatically give feedback to server.
478
+ ```js
479
+ SmartMessage.displayMessageContent(MessageContent)
480
+ ```
481
+
482
+ ---
483
+
484
+ # ✅ Status Feedback
485
+ DELIVERED(0), VIEW(1), OPEN(2), DELETE(3) status feedback is available.
486
+
487
+ | Status | Action | When does it happen? |
488
+ | ------- | --- | ---- |
489
+ | DELIVERED | SmartMessage.reportMessageDelivered(NOTIFICATION_ID); | When the notification reaches the phone, it is automatically called by the SDK. |
490
+ | VIEW | SmartMessage.reportMessageView(NOTIFICATION_ID); | When notification is displayed within the application via SDK it is automatically called by the SDK. |
491
+ | OPEN | SmartMessage.reportMessageOpen(NOTIFICATION_ID); | When the notification is clicked from the notification panel it is automatically called by the SDK. |
492
+ | DELETE | SmartMessage.reportMessageDeleted(NOTIFICATION_ID); | When it is swiped and deleted from the notification panel it is automatically called by the SDK |
493
+
494
+