Get First Attachment Events
The first attachment event will be triggered for each SIM card the first time it connects (attaches) to a mobile network. This happens as soon as the phone is connected to a mobile network.
Note that only operators and third party products enabled by default, that have rights regarding the subscriber before they initially attach, can get this event, as the event is created before the subscriber can authenticate in the products portal.
NOTE that this API responds with the IMSI for the SIM card in the user's handset. This is considered PII information and needs to be handled with care.
Prerequisites
Required Scope
subscription.first_attachment:read
Code Dependencies
<dependency>
<groupId>com.wgtwo.api.v1.grpc</groupId>
<artifactId>subscription</artifactId>
<version>1.10.1</version>
</dependency>
Code
If targeting production, you would need to add authentication to the sample code.
#!/usr/bin/env bash
grpcurl \
-d '
{
"stream_configuration": {
"regular": {},
"disable_explicit_ack": {}
}
}
' \
sandbox.api.shamrock.wgtwo.com:443 \
wgtwo.subscription.v1.SubscriptionEventService/StreamFirstAttachmentEvents
package com.example.firstattachment
import com.wgtwo.api.v1.subscription.SubscriptionEventServiceGrpc
import com.wgtwo.api.v1.subscription.SubscriptionEventsProto.AckFirstAttachmentEventRequest
import com.wgtwo.api.v1.subscription.SubscriptionEventsProto.StreamFirstAttachmentEventsRequest
import com.wgtwo.api.v1.subscription.SubscriptionEventsProto.StreamFirstAttachmentEventsResponse
import io.grpc.ManagedChannelBuilder
import io.grpc.StatusRuntimeException
import java.util.concurrent.Executors
private const val MAX_IN_FLIGHT = 10
private val channel = ManagedChannelBuilder.forAddress("sandbox.api.shamrock.wgtwo.com", 443).build()
private val stub = SubscriptionEventServiceGrpc.newBlockingStub(channel)
private val executor = Executors.newFixedThreadPool(MAX_IN_FLIGHT)
fun main() {
while (!channel.isShutdown) {
try {
subscribe()
} catch (e: StatusRuntimeException) {
println("Got exception: ${e.status} - Reconnecting in 1 second")
Thread.sleep(1000)
}
}
}
private fun subscribe() {
println("Starting subscription")
val request = StreamFirstAttachmentEventsRequest.newBuilder().apply {
streamConfigurationBuilder.maxInFlight = MAX_IN_FLIGHT
}.build()
stub.streamFirstAttachmentEvents(request).forEach { response ->
// Using an executor to handle up to MAX_IN_FLIGHT messages in parallel
executor.submit {
handleResponse(response)
ack(response)
}
}
}
private fun handleResponse(response: StreamFirstAttachmentEventsResponse) {
println("Got response:
$response")
}
private fun ack(response: StreamFirstAttachmentEventsResponse) {
val ackInfo = response.metadata.ackInfo
val request = AckFirstAttachmentEventRequest.newBuilder().setAckInfo(ackInfo).build()
stub.ackFirstAttachmentEvent(request)
}
Example Result
{
"firstAttachmentEvent": {
"number": {
"e164": "+47xxxxxxxx",
},
"imsi": {
"value": "24206000010001"
}
}
}
{
"firstAttachmentEvent": {
"number": {
"e164": "+47xxxxxxxx",
},
"imsi": {
"value": "24206000020001"
}
}
}
first_attachment_event {
number {
e164: "+47xxxxxxxx"
}
imsi {
value: "24206000010001"
}
}
# Ack success
first_attachment_event {
number {
e164: "+47xxxxxxxx"
}
imsi {
value: "24206000020001"
}
}
# Ack success