Send text SMS from subscriber

This part of the SMS API enables a third party to send out text SMSes on behalf of an authorized subscriber. This required that the API key holder has the authorization to send on behalf of that subscriber, which is set in the from_subscriber field.

FieldDescription
from_subscriberThe E.164 number with '+' of the subscriber.

The destination number can be set to international or short numbers. Which numbers is allowed is based on a matrix of rights for the product and subscriber, so you must check for rejected messages based on it's content.

FieldContentDescription
to_address+numberAn international number in E.164 format with a '+'.
to_addressnumberA short format or network specific number in the national format. Numbers resolving to international must be entered as international.

Note that using this API may incur costs or quota uses to the subscriber. Any such cost will be based on the number of fragments sent. See the response num_fragments field for details.

Fragmentation and Encoding

Fragmentation and message encoding is handled the same way as for messages to subscriber.

Limitations

There are also some other restrictions to this API.

  • This API cannot send a message from the subscriber that are blocked by subscription policies or quotas, i.e. messages that the subscriber is not allowed to send from the handset itself.
  • This API will not send messages larger than 2000 characters. Note that unicode characters outside of the BMP plane counts as 2 characters each, and number of emoji characters and the newer CJK characters are in this group. Worst case this is 35 fragments for a single message.
  • This API does not guarantee that the message is successfully delivered.

Prerequisites

  1. An OAuth 2.0 client
  2. A client access token

Required scope

  • sms.text.send_from_subscriber is required to use the API function.

Code

TIP

You can test our APIs without authorization by targetting sandbox.api.wgtwo.com instead of api.wgtwo.com and removing any authorization from the request/code sample.

Download proto definitions
curl -sL 'https://github.com/working-group-two/wgtwoapis/blob/master/image.bin?raw=true' -o wgtwo.bin
1
export ACCESS_TOKEN="my_client_access_token"
grpcurl -protoset wgtwo.bin \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '
  {
    "content": "My text message",
    "fromSubscriber": "+47xxxxxxxx",
    "toAddress": "+47yyyyyyyy"
  }
  ' \
  api.wgtwo.com:443 \
  wgtwo.sms.v1.SmsService/SendTextFromSubscriber
1
2
3
4
5
6
7
8
9
10
11
12

Example result

{
  "messageId": "6a75356e-6191-11ec-b47d-7382e9b102b6",
  "status": "SEND_STATUS_OK",
  "numFragments": 1
}
1
2
3
4
5
Install dependencies

Maven

<dependency>
  <groupId>com.wgtwo.api.v1.grpc</groupId>
  <artifactId>sms</artifactId>
  <version>1.8.0</version>
</dependency>

search.maven.org/search?q=g:com.wgtwo.api.v1.grpcopen in new window

package com.example.sms

import com.wgtwo.api.v1.sms.SmsProto.SendTextFromSubscriberRequest
import com.wgtwo.api.v1.sms.SmsServiceGrpc
import com.wgtwo.api.util.auth.BearerToken
import io.grpc.ManagedChannelBuilder

fun main(vararg args: String) {
    if (args.size != 3) throw IllegalArgumentException(
        "This program requires 3 arguments: from-number to-number content")
    val accessToken = "my_client_access_token"
    val api = "api.wgtwo.com" // or use "sandbox.api.wgtwo.com"
    val channel = ManagedChannelBuilder.forAddress(api, 443).build()
    try {
        val service = SmsServiceGrpc.newBlockingStub(channel)
            .withCallCredentials(BearerToken { accessToken })
            .withWaitForReady()
        println(service.sendTextFromSubscriber(SendTextFromSubscriberRequest.newBuilder().apply {
            fromSubscriber = args[0]
            toAddress = args[1]
            content = args[2]
        }.build()))
    } finally {
        channel.shutdownNow()
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

Example result

message_id: "6a75356e-6191-11ec-b47d-7382e9b102b6"
status: SEND_STATUS_OK
num_fragments: 1
1
2
3

Read more