Get Consent Events
Consent events are events triggered by granting, updating or revoking consents for your product, either for a single user or for an operator.
The events can originate from:
- Bundling of your product for a subscriber
- Preview consent added by Cisco on your behalf
- Operator consent covering all subscribers for an operator
- Subscriber signing up to your product
Prerequisites
Required Scope
None.
Code Dependencies
<dependency>
<groupId>com.wgtwo.api.v1.grpc</groupId>
<artifactId>consent-events</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.consents.v1.ConsentEventService/StreamConsentChangeEvents
package com.example.consents
import com.wgtwo.api.v1.consent.ConsentEventServiceGrpc
import com.wgtwo.api.v1.consent.ConsentEventsProto.AckConsentChangeEventRequest
import com.wgtwo.api.v1.consent.ConsentEventsProto.StreamConsentChangeEventsRequest
import com.wgtwo.api.v1.consent.ConsentEventsProto.StreamConsentChangeEventsResponse
import io.grpc.ManagedChannelBuilder
import io.grpc.StatusRuntimeException
import java.util.concurrent.TimeUnit
private val channel = ManagedChannelBuilder.forTarget("sandbox.api.shamrock.wgtwo.com:443")
.keepAliveWithoutCalls(true)
.keepAliveTime(1, TimeUnit.MINUTES)
.keepAliveTimeout(10, TimeUnit.SECONDS)
.idleTimeout(1, TimeUnit.HOURS)
.build()
private val stub = ConsentEventServiceGrpc.newBlockingStub(channel)
fun main() {
while (!channel.isShutdown) {
try {
subscribe()
} catch (e: StatusRuntimeException) {
println("Got exception: ${e.status} - Reconnecting in 1 second")
Thread.sleep(1000)
}
}
}
fun subscribe() {
println("Starting subscription")
val request = StreamConsentChangeEventsRequest.newBuilder().build()
stub.streamConsentChangeEvents(request).forEach { response ->
handleResponse(response)
ack(response)
}
}
fun handleResponse(response: StreamConsentChangeEventsResponse) {
println("Got response:
$response")
}
fun ack(response: StreamConsentChangeEventsResponse) {
val ackInfo = response.metadata.ackInfo
val request = AckConsentChangeEventRequest.newBuilder().setAckInfo(ackInfo).build()
stub.ackConsentChangeEvent(request)
}
Example Results
{
"metadata": {
"timestamp": "2022-08-09T12:22:57.110Z",
"identifier": {
"subscriptionIdentifier": {
"value": "490e6f4a2cccd6067741b8a2a4bb14b2a1b2756c523c6c818e7eaee651b07743e69383304f45b3f6970b8bd01d16f845bc999d1ff036a5e605fec314d8aed99e"
}
},
"ackInfo": {
"value": "$JS.ACK.consent_stream.H5yg2gnj.1.9.1.1660047797010497111.0"
}
},
"consentChangeEvent": {
"added": {
"scopes": [ "sms.text:send_to_subscriber" ]
},
"number": {
"e164": "+46724452050"
}
}
}
{
"metadata": {
"timestamp": "2022-08-09T12:23:17.010Z",
"identifier": {
"subscriptionIdentifier": {
"value": "490e6f4a2cccd6067741b8a2a4bb14b2a1b2756c523c6c818e7eaee651b07743e69383304f45b3f6970b8bd01d16f845bc999d1ff036a5e605fec314d8aed99e"
}
},
"ackInfo": {
"value": "$JS.ACK.consent_stream.H5yg2gnj.1.9.1.1660047797010497633.0"
}
},
"consentChangeEvent": {
"revoked": {
},
"number": {
"e164": "+46724452050"
}
}
}
{
"metadata": {
"timestamp": "2022-08-09T12:22:57.110Z",
"identifier": {
"subscriptionIdentifier": {
"value": "490e6f4a2cccd6067741b8a2a4bb14b2a1b2756c523c6c818e7eaee651b07743e69383304f45b3f6970b8bd01d16f845bc999d1ff036a5e605fec314d8aed99e"
}
},
"ackInfo": {
"value": "$JS.ACK.consent_stream.H5yg2gnj.1.9.1.1660047797010497111.0"
}
},
"consentChangeEvent": {
"added": {
"scopes": [ "sms.text:send_to_subscriber" ]
},
"number": {
"e164": "+46724452050"
}
}
}
{
"metadata": {
"timestamp": "2022-08-09T12:23:17.010Z",
"identifier": {
"subscriptionIdentifier": {
"value": "490e6f4a2cccd6067741b8a2a4bb14b2a1b2756c523c6c818e7eaee651b07743e69383304f45b3f6970b8bd01d16f845bc999d1ff036a5e605fec314d8aed99e"
}
},
"ackInfo": {
"value": "$JS.ACK.consent_stream.H5yg2gnj.1.9.1.1660047797010497633.0"
}
},
"consentChangeEvent": {
"revoked": {
},
"number": {
"e164": "+46724452050"
}
}
}