Get started with grpcurl and events

This document will show you how to start using our APIs with a hands-on tutorial for listening to events.

Download proto descriptions

You can find our .proto files at https://github.com/working-group-two/wgtwoapis

Download the FileDescriptorSet for our APIs, which contains all our .proto files:

curl -L 'https://github.com/working-group-two/wgtwoapis/blob/master/image.bin?raw=true' -o wgtwo.bin
1

Set up gRPCurl

We use gRPCurlopen in new window to invoke the gRPC APIs in this guide.

If you don't have gRPCurl installed, you may run it through Docker:

grpcurl() {
  docker run -v $(pwd)/wgtwo.bin:/wgtwo.bin fullstorydev/grpcurl "$@"
}
1
2
3

Sandbox environment

Our sandboxed environment is hosted at sandbox.api.wgtwo.com.

This is a mock implementation of our gRPC APIs, and does not require any authentication.

Setup event streaming

Note: This stream will timeout. If it happens while running these examples, just re-run the command.

This will send you all the available events of type SMS_EVENT:

grpcurl -protoset wgtwo.bin \
  -d '{ "type": ["SMS_EVENT"] }' \
  sandbox.api.wgtwo.com:443 \
  wgtwo.events.v0.EventsService.Subscribe
1
2
3
4

You should be able to see mock events such as:

{
  "event": {
    "smsEvent": {
      "id": "3990fb66-eea0-42ef-9699-1af05516ce00",
      "fromE164": {
        "e164": "+46724450024"
      },
      "toE164": {
        "e164": "+4799977540"
      },
      "direction": "FROM_SUBSCRIBER",
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
      "uuid": "b922f707-f6ce-4369-b816-1051bfa40e0d"
    },
    "owner": {
      "phoneNumber": {
        "e164": "+46724450024"
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Leave the command running for the next step.

Send SMS

Open a new terminal and run the following command:

grpcurl -protoset wgtwo.bin \
  -d '{
        "content": "This is a test message",
        "from_subscriber": { "e164": "+4799990000" },
        "to_e164": { "e164": "+46724450000" }
      }' \
  sandbox.api.wgtwo.com:443 \
  wgtwo.sms.v0.SmsService/SendTextFromSubscriber
1
2
3
4
5
6
7
8

This will send a test SMS and trigger a SMS_EVENT.

You should see something like this in the current terminal:

{
 "requestId": "478be859-614e-4d34-84dd-4ae9d1d0066b",
 "status": "SEND_OK"
}
1
2
3
4

And something like this in your first terminal (that's listening for events):

{
 "event": {
   "smsEvent": {
     "id": "478be859-614e-4d34-84dd-4ae9d1d0066b",
     "fromE164": {
       "e164": "+4799990000"
     },
     "toE164": {
       "e164": "+46724450000"
     },
     "direction": "FROM_SUBSCRIBER",
     "text": "This is a test message",
     "uuid": "478be859-614e-4d34-84dd-4ae9d1d0066b"
   },
   "owner": {
     "phoneNumber": {
       "e164": "+46724450024"
     }
   }
 }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Explore the API

For exploring the API we recommend gRPC UIopen in new window.

If you don't have gRPC UI installed, you may run it through Docker:

$ docker run -v $(pwd)/wgtwo.bin:/wgtwo.bin -p 8080:8080 \
  fullstorydev/grpcui -protoset wgtwo.bin sandbox.api.wgtwo.com:443
$ # - or -
$ grpcui -protoset wgtwo.bin sandbox.api.wgtwo.com:443
1
2
3
4

Production environment

Our production environment is hosted at api.wgtwo.com.

This part of the guide will show you how to create a OAuth 2.0 token and use that to connected to our event stream.

Create OAuth 2.0 client

Before you start, see Create OAuth 2.0 client. You need enable the scope events.sms.subscribe.

Get access token (using the Client Credentials Flow)

curl -s -u ${CLIENT_ID}:${CLIENT_SECRET} # <- Replace CLIENT_ID & CLIENT_SECRET \
    --request POST \
    --url 'https://id.wgtwo.com/oauth2/token' \
    --header 'content-type: application/x-www-form-urlencoded' \
    --data grant_type="client_credentials" \
    --data scope="events.sms.subscribe" \
  | jq .
1
2
3
4
5
6
7

Setup stream listening for events

Note: This stream will timeout. We expect you to automatically reconnect when that happens.

For details, see: Configuration and types 〉 Recommended production configuration. // todo

This will send you all the available events of type SMS_EVENT. As nobody has consented to share their events to you, the stream will be silent until someone has given consent and sent an SMS.

grpcurl -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -protoset wgtwo.bin \
  -d '{ "type": ["SMS_EVENT"] }' \
  api.wgtwo.com:443 \
  wgtwo.events.v0.EventsService.Subscribe
1
2
3
4
5

Example code for Go

Download and run code example
curl -sL https://github.com/working-group-two/docs.wgtwo.com/raw/master/examples/go/events/main.go -o main.go
go mod init example
go mod tidy
CLIENT_ID=${CLIENT_ID} CLIENT_SECRET=${CLIENT_SECRET} go run main.go
1
2
3
4

What's next?

I am building a subscriber product

In the near future there will be a products API and consent API, where subscribers can programmatically consent to products to be enabled for their subscription.

There is a special event named CONSENT_REVOKE_EVENT that you must listen for, as this will fire if the consent is removed by the user through e.g. customer support. See support revoking consent. This event does not require an explicit scope.

When you are done testing, you can submit your product so that it can be reviewed and listed in our marketplace.

I am building an operator product

You can contact us directly at products@wgtwo.com in order to add test subscription(s) to your product. Unfortunately, at this time it is not possible to do this yourself.

When you are done with your testing, you may submit your product so that it can be reviewed and listed in our marketplace.

Summary

In this tutorial we have looked at getting mocked events using gRPC (using gRPCurl and gRPC UI). We have sent an SMS and seen it appear in the events stream. We've also looked at creating a OAuth 2.0 client and moving to the production environment. We've also briefly mentioned publishing your product to a marketplace.

These steps; integrating, moving to production, publishing to a marketplace; are the fundamental steps needed to launch a product on our platform.