Skip to content

Commit 31f1781

Browse files
authored
Merge branch 'master' into response-status-updates
2 parents 70f8c75 + 8585e31 commit 31f1781

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

e2e-cli/src/main/kotlin/cli/Main.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.google.gson.reflect.TypeToken
55
import com.segment.analytics.Analytics
66
import com.segment.analytics.Callback
77
import com.segment.analytics.messages.*
8+
import java.time.Instant
9+
import java.util.Date
810
import java.util.concurrent.CountDownLatch
911
import java.util.concurrent.TimeUnit
1012
import java.util.concurrent.atomic.AtomicBoolean
@@ -109,14 +111,20 @@ fun sendEvent(analytics: Analytics, event: Map<String, Any>) {
109111
val userId = event["userId"] as? String ?: ""
110112
val anonymousId = event["anonymousId"] as? String
111113
val messageId = event["messageId"] as? String
114+
val timestamp = event["timestamp"] as? String
112115
@Suppress("UNCHECKED_CAST")
113116
val traits = event["traits"] as? Map<String, Any> ?: emptyMap()
114117
@Suppress("UNCHECKED_CAST")
115118
val properties = event["properties"] as? Map<String, Any> ?: emptyMap()
116119
val eventName = event["event"] as? String
117120
val name = event["name"] as? String
121+
val category = event["category"] as? String
118122
val groupId = event["groupId"] as? String
119123
val previousId = event["previousId"] as? String
124+
@Suppress("UNCHECKED_CAST")
125+
val context = event["context"] as? Map<String, Any>
126+
@Suppress("UNCHECKED_CAST")
127+
val integrations = event["integrations"] as? Map<String, Any>
120128

121129
val messageBuilder: MessageBuilder<*, *> = when (type) {
122130
"identify" -> {
@@ -156,6 +164,28 @@ fun sendEvent(analytics: Analytics, event: Map<String, Any>) {
156164
if (anonymousId != null) {
157165
messageBuilder.anonymousId(anonymousId)
158166
}
167+
if (messageId != null) {
168+
messageBuilder.messageId(messageId)
169+
}
170+
if (timestamp != null) {
171+
messageBuilder.timestamp(parseTimestamp(timestamp))
172+
}
173+
if (context != null) {
174+
messageBuilder.context(context)
175+
}
176+
if (integrations != null) {
177+
for ((key, value) in integrations) {
178+
when (value) {
179+
is Boolean -> messageBuilder.enableIntegration(key, value)
180+
is Map<*, *> -> @Suppress("UNCHECKED_CAST")
181+
messageBuilder.integrationOptions(key, value as Map<String, Any>)
182+
}
183+
}
184+
}
159185

160186
analytics.enqueue(messageBuilder)
161187
}
188+
189+
private fun parseTimestamp(iso: String): Date {
190+
return Date.from(Instant.parse(iso))
191+
}

0 commit comments

Comments
 (0)