@@ -47,6 +47,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
4747 var bundleCommerceEvents = false
4848 var isMpidIdentityType = false
4949 var identityType: IdentityType ? = null
50+ var subscriptionGroupIds: MutableMap <String , String >? = mutableMapOf ()
5051 private val dataFlushHandler = Handler ()
5152 private var dataFlushRunnable: Runnable ? = null
5253 private var forwardScreenViews = false
@@ -85,6 +86,9 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
8586 }
8687 }
8788 forwardScreenViews = settings[FORWARD_SCREEN_VIEWS ].toBoolean()
89+ subscriptionGroupIds = settings[SUBSCRIPTION_GROUP_MAPPING ]?.let {
90+ getSubscriptionGroupIds(it)
91+ }
8892 if (key != null ) {
8993 val config = BrazeConfig .Builder ().setApiKey(key)
9094 .setSdkFlavor(SdkFlavor .MPARTICLE )
@@ -318,10 +322,29 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
318322 else value.setGender(Gender .MALE )
319323 }
320324 else -> {
321- if (key.startsWith(" $" )) {
322- key = key.substring(1 )
325+ if (subscriptionGroupIds?.containsKey(key) == true ) {
326+ val groupId = subscriptionGroupIds?.get(key)
327+ when (attributeValue.lowercase()) {
328+ " true" -> {
329+ groupId?.let { value.addToSubscriptionGroup(it) }
330+ }
331+
332+ " false" -> {
333+ groupId?.let { value.removeFromSubscriptionGroup(it) }
334+ }
335+
336+ else -> {
337+ Logger .warning(
338+ " Unable to set Subscription Group ID for user attribute: $key due to invalid value data type. Expected Boolean."
339+ )
340+ }
341+ }
342+ } else {
343+ if (key.startsWith(" $" )) {
344+ key = key.substring(1 )
345+ }
346+ userAttributeSetter?.parseValue(key, attributeValue)
323347 }
324- userAttributeSetter?.parseValue(key, attributeValue)
325348 }
326349 }
327350 queueDataFlush()
@@ -966,6 +989,29 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
966989 return promotionArray
967990 }
968991
992+ private fun getSubscriptionGroupIds (subscriptionGroupMap : String ): MutableMap <String , String > {
993+ val subscriptionGroupIds = mutableMapOf<String , String >()
994+
995+ if (subscriptionGroupMap.isEmpty()) {
996+ return subscriptionGroupIds
997+ }
998+
999+ val subscriptionGroupsArray = JSONArray (subscriptionGroupMap)
1000+
1001+ return try {
1002+ for (i in 0 until subscriptionGroupsArray.length()) {
1003+ val subscriptionGroup = subscriptionGroupsArray.getJSONObject(i)
1004+ val key = subscriptionGroup.getString(" map" )
1005+ val value = subscriptionGroup.getString(" value" )
1006+ subscriptionGroupIds[key] = value
1007+ }
1008+ subscriptionGroupIds
1009+ } catch (e: JSONException ) {
1010+ Logger .warning(" Braze, unable to parse \" subscriptionGroup\" " )
1011+ mutableMapOf ()
1012+ }
1013+ }
1014+
9691015 fun getImpressionListParameters (impressionList : List <Impression >): JSONArray {
9701016 val impressionArray = JSONArray ()
9711017 for ((i, impression) in impressionList.withIndex()) {
@@ -1083,6 +1129,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
10831129 const val USER_IDENTIFICATION_TYPE = " userIdentificationType"
10841130 const val ENABLE_TYPE_DETECTION = " enableTypeDetection"
10851131 const val BUNDLE_COMMERCE_EVENTS = " bundleCommerceEventData"
1132+ const val SUBSCRIPTION_GROUP_MAPPING = " subscriptionGroupMapping"
10861133 const val HOST = " host"
10871134 const val PUSH_ENABLED = " push_enabled"
10881135 const val NAME = " Appboy"
0 commit comments