Skip to content

Commit

Permalink
Dedupe (#10)
Browse files Browse the repository at this point in the history
* fix: add unsubscribed status, remove clearing device token on change events logic, add badge clearing on app open

* fix: add dedup_id fix push_open

* fix: change message_id to message_id from push data

* fix: change message_id to twi messageId

---------

Co-authored-by: Alan Charles <acharles@twilio.com>
  • Loading branch information
alanjcharles and alanjcharles authored Sep 6, 2023
1 parent e077bfa commit c3cd49e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Sources/TwilioEngage/TwilioEngage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,23 @@ public class TwilioEngage: EventPlugin {
// we only wanna look at track events
guard var event = event as? TrackEvent else { return event }
guard var context = event.context else { return event as? T }
// guard var properties = event.properties else {return event }

// this will succeed if the event name can be used to generate a push event case.
guard Events(rawValue: event.event) != nil else { return event as? T }


// we only need to add a deDup_id to `push recieved` and `push opened` events
if event.event == Events.tapped.rawValue || event.event == Events.received.rawValue {
if var properties = event.properties?.dictionaryValue {
let formattedEventName = event.event.lowercased().replacingOccurrences(of: " ", with: "_")
let messageId = properties["message_id"] ?? UUID().toString()
let deDup_id = "\(formattedEventName)\(messageId)"
properties[keyPath: "dedup_id"] = deDup_id

event.properties = try? JSON(properties)
}
}

// `messaging_subscription` data type is an array of objects
context[keyPath: KeyPath(Self.contextKey)] = [[
"key": deviceToken,
Expand All @@ -142,7 +155,6 @@ public class TwilioEngage: EventPlugin {

extension TwilioEngage: RemoteNotifications {
public func receivedRemoteNotification(userInfo: [AnyHashable: Any]) {
// notification was received while the app was open.
if let notification = userInfo as? [String: Any] {
trackNotification(notification, fromLaunch: false)
}
Expand Down

0 comments on commit c3cd49e

Please sign in to comment.