Skip to content

Commit c4a9c40

Browse files
committed
bridge: add phone number and sms subscription apis
1 parent 26cc4dc commit c4a9c40

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

android/src/main/java/com/batch/batch_rn/RNBatchModuleImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.batch.android.BatchPushRegistration;
2424
import com.batch.android.BatchTagCollectionsFetchListener;
2525
import com.batch.android.BatchEmailSubscriptionState;
26+
import com.batch.android.BatchSMSSubscriptionState;
2627
import com.batch.android.BatchUserAttribute;
2728
import com.batch.android.PushNotificationType;
2829
import com.batch.android.BatchInboxFetcher;
@@ -654,6 +655,17 @@ public void profile_saveEditor(ReadableArray actions) {
654655
} else if (type.equals("setEmailMarketingSubscription")) {
655656
String value = action.getString("value");
656657
editor.setEmailMarketingSubscription(BatchEmailSubscriptionState.valueOf(value));
658+
} else if (type.equals("setPhoneNumber")) {
659+
ReadableType valueType = action.getType("value");
660+
if (valueType.equals(ReadableType.Null)) {
661+
editor.setPhoneNumber(null);
662+
} else {
663+
String value = action.getString("value");
664+
editor.setPhoneNumber(value);
665+
}
666+
} else if (type.equals("setSMSMarketingSubscription")) {
667+
String value = action.getString("value");
668+
editor.setSMSMarketingSubscription(BatchSMSSubscriptionState.valueOf(value));
657669
} else if (type.equals("setLanguage")) {
658670
ReadableType valueType = action.getType("value");
659671
if (valueType.equals(ReadableType.Null)) {

ios/RNBatch.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,19 @@ - (BatchEventAttributes*) convertSerializedEventDataToEventAttributes:(NSDiction
583583
}
584584
}
585585

586+
else if([type isEqualToString:@"setPhoneNumber"]) {
587+
[editor setPhoneNumber:[self safeNilValue:action[@"value"]] error:nil];
588+
}
589+
590+
else if([type isEqualToString:@"setSMSMarketingSubscription"]) {
591+
NSString* value = action[@"value"];
592+
if([value isEqualToString:@"SUBSCRIBED"]) {
593+
[editor setSMSMarketingSubscriptionState:BatchSMSSubscriptionStateSubscribed];
594+
} else if ([value isEqualToString:@"UNSUBSCRIBED"]) {
595+
[editor setSMSMarketingSubscriptionState: BatchSMSSubscriptionStateUnsubscribed];
596+
}
597+
}
598+
586599
else if([type isEqualToString:@"setLanguage"]) {
587600
[editor setLanguage:[self safeNilValue:action[@"value"]] error:nil];
588601
}

src/BatchProfileAttributeEditor.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export enum BatchEmailSubscriptionState {
88
UNSUBSCRIBED = 'UNSUBSCRIBED',
99
}
1010

11+
/**
12+
* Enum defining the state of an SMS subscription
13+
*/
14+
export enum BatchSMSSubscriptionState {
15+
SUBSCRIBED = 'SUBSCRIBED',
16+
UNSUBSCRIBED = 'UNSUBSCRIBED',
17+
}
18+
1119
interface IUserSettingsSetAttributeAction {
1220
type: 'setAttribute';
1321
key: string;
@@ -51,6 +59,16 @@ interface IUserSettingsSetEmailMarketingSubscriptionAction {
5159
value: BatchEmailSubscriptionState;
5260
}
5361

62+
interface IUserSettingsSetPhoneNumberAction {
63+
type: 'setPhoneNumber';
64+
value: string | null;
65+
}
66+
67+
interface IUserSettingsSetSMSMarketingSubscriptionAction {
68+
type: 'setSMSMarketingSubscription';
69+
value: BatchSMSSubscriptionState;
70+
}
71+
5472
interface IUserSettingsAddToArrayAction {
5573
type: 'addToArray';
5674
key: string;
@@ -73,7 +91,9 @@ type IUserSettingsAction =
7391
| IUserSettingsAddToArrayAction
7492
| IUserSettingsRemoveFromArrayAction
7593
| IUserSettingsSetEmailAddressAction
76-
| IUserSettingsSetEmailMarketingSubscriptionAction;
94+
| IUserSettingsSetEmailMarketingSubscriptionAction
95+
| IUserSettingsSetPhoneNumberAction
96+
| IUserSettingsSetSMSMarketingSubscriptionAction;
7797

7898
type IUserSettingsActions = IUserSettingsAction[];
7999

@@ -137,6 +157,20 @@ export class BatchProfileAttributeEditor {
137157
});
138158
}
139159

160+
public setPhoneNumber(value: string | null): BatchProfileAttributeEditor {
161+
return this.addAction({
162+
type: 'setPhoneNumber',
163+
value,
164+
});
165+
}
166+
167+
public setSMSMarketingSubscription(value: BatchSMSSubscriptionState): BatchProfileAttributeEditor {
168+
return this.addAction({
169+
type: 'setSMSMarketingSubscription',
170+
value,
171+
});
172+
}
173+
140174
public setLanguage(value: string | null): BatchProfileAttributeEditor {
141175
return this.addAction({
142176
type: 'setLanguage',

0 commit comments

Comments
 (0)