Skip to content

Reach Messaging API - Quickstart - Go

Sending SMS with the Reach Messaging API from TalkyLabs is made possible with just a few lines of Go code.

In what follows, we provide a step-by-step guide to facilitate your debut. In this quickstart, you will learn how to:

Information Circle
  • Sign up for the Reach platform

  • Create an applet

  • Retrieve your API credentials

  • Verify your phone number

  • Send a SMS

Sign-up / Sign-in

Information Circle

You can skip this section if you already have an account on the Reach platform.

You can sign up for an account on the Reach platform here. You will be asked to verify your email address to activate your account.

Create an applet

Information Circle

You can skip this section if you already have an applet and want to use it here.

An applet can be viewed as a subaccount or a development environment within the Reach platform. It allows you to regroup your operations in the Reach platform based on your customer segments, e.g., by country. You can have more than one applet associated with your account.

Creating an applet is just as simple as clicking a button and specifying the applet name as well as the operating country, that is the country where most of the customers targeted by the operations that will be performed under this applet reside.

Retrieve your API credentials

After accessing your applet, you can retrieve your API credentials by visiting Settings -> API from the left side menu.

As you will notice, you will gain access to your API User as well as your Test and Live API Key. Recall that the Test API key is for the sandbox mode where you can emulate sending messages while the Live API key is for sending messages for real.

Finally, note that it is possible to re-generate your API keys as you go.

Verify your phone number

Information Circle

You can skip this section if you already have a verified number.

With an applet, you can emulate sending messages in a sandbox mode by using whatever valid phone numbers you want. However, for sending real messages, you can only use phone numbers that you own.

To demonstrate the ownership of a phone number, you need to verify it. Within an applet, visit the section Phone numbers -> Verified numbers from the left side menu to add your number and start a verification process.

Warning

Once the number is verified, it will be valid for a period of time. For now, that period is three months and this can changed without prior notice. You will have to re-verify the number to continue use it after that period of time.

Install the client library

Information Circle

If you already have the Go client library installed, you can skip this step and get straight to sending your first message.

You have to make sure you have Go installed on your computer. This could be checked by running the following command:

go version

If it is installed, you would see something like:

go version go1.20.4 linux/amd64

Our Go client library supports Go 1.15+. To install it, you first need to start a new Go project. Create a Go project by running the command below:

go mod init reach-talkylabs-example

Then, move into the project folder reach-talkylabs-example and install the client library using:

go get github.com/talkylabs/reach-go

Send a message

Now that the Go client library is installed, we can send an SMS using a valid verified number registered in the applet. Create a file name sendMessage.go and paste in it the code sample below.

package main

import (
    "fmt"
    "os"
    "github.com/talkylabs/reach-go"
    reachMessaging "github.com/talkylabs/reach-go/rest/api/messaging"
)

func main() {
    apiUser := os.Getenv("REACH_TALKYLABS_API_USER")
    apiKey := os.Getenv("REACH_TALKYLABS_API_KEY")

    client := reach.NewRestClientWithParams(reach.ClientParams{
        ApiUser: apiUser,
        ApiKey: apiKey,
    })

    params := &reachMessaging.SendMessageParams{}
    params.SetDest("+237671234567")
    params.SetSrc("+237691234567")
    params.SetBody("Hello World! This is a sms message.")

    resp, err := client.Messaging.SendMessage(params)
    if err != nil {
        fmt.Println("Error: " + err.Error())
    } else {
      fmt.Println(resp.MessageId)
    }
}

Replace the value in params.SetSrc with your verified number and the value in params.SetDest with the number you want to send the message to. The phone numbers must be in the E.164 format.

Also, use your API credentials to replace the placeholder values for apiUser and apiKey. Remember to use your Live API key.

Warning

For getting started, it is okay to hardcode your credentials in the file. However, it is highly recommend to use environment variables to store sensitive data instead.

Save the file and run the following command in your terminal:

go run sendMessage.go

That's it! In a few moments, your message will be delivered to the destination phone number.