Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedupe #10

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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