This guide will show you how to schedule messages to be sent at a specific time, how to manage them, and how to change the sending time and status through the Infobip Go SDK. For detailed information on the full capabilities of the Infobip SMS channel, check the API Reference.

Prerequisites

  • Basic Go and API knowledge
  • Go 13 (or newer) installation
  • A running Go project

Steps overview

  1. Install the Infobip SDK.
  2. Import the required packages.
  3. Create an Infobip client.
  4. Schedule some messages.
  5. See your scheduled messages.
  6. Change the sending time.
  7. See the status of your scheduled messages.
  8. Change the status of your scheduled messages.

Install the Infobip SDK

The SDK can be retrieved as a normal Go library, using the go get command as follows:

go get "github.com/infobip-community/infobip-api-go-sdk/v3"

Note: the string v3 part of the import may be updated if there is a new release of the library. Newer versions will use the latest Infobip technology and general enhancements to the developer experience! Check for newer versions on our GitHub Releases page.

Import the required packages

You’ll need the Infobip client and models imported into your source code:

import (
    //..
    "github.com/infobip-community/infobip-api-go-sdk/v3/pkg/infobip"
    "github.com/infobip-community/infobip-api-go-sdk/v3/pkg/infobip/models"
)

Note: The v3 may have changed to a newer version if you updated the library.

Create an Infobip client

To create the main client, you need to specify your API key, and custom base URL.
You can get them by logging into your Infobip account.

// Secrets configuration
baseURL := "your base URL here"
apiKey := "your api key here"

// Initialize Infobip client
client, _ := infobip.NewClient(baseURL, apiKey)

The next steps can use the same client instance or create a new one. They could even be separate programs.

Schedule some messages

Scheduling messages is very similar to sending a simple SMS. To schedule messages, you need to create bulk. To do that, specify a BulkID in the SendSMSRequest instance, so you can later check the status of the messages, and make changes (the bulk ID is just a unique string that you can use to refer to your set of messages). Also, specify a SendAt attribute in one of the SMSMsg instances. This is how you do all this:

msg := models.SMSMsg{
  Destinations: []models.SMSDestination{
    {To: "523311800428"},
  },
  From:   "Cool Gopher",
  Text:   "Hello from Infobip Go SDK!",
  SendAt: "2022-07-01T16:00:00.000+0000",
}

msg2 := models.SMSMsg{
  Destinations: []models.SMSDestination{
    {To: "523311800428"},
  },
  From: "Cool Gopher",
  Text: "Hello again from Infobip Go SDK!",
}

req := models.SendSMSRequest{
  BulkID:   "my-bulk-id-1325753",
  Messages: []models.SMSMsg{msg, msg2},
}

After that, send the messages as when sending a single SMS:

resp, respDetails, _ := client.SMS.Send(context.Background(), req)

Note that messages can only be scheduled six months in advance. Now, let’s see the scheduled messages.

See your scheduled messages

To see your scheduled messages, use your bulk ID as a query parameter and call the GetScheduledMessages function.

queryParams := models.GetScheduledSMSParams{
  BulkID: "my-bulk-id-1325753",
}

resp, respDetails, _ := client.SMS.GetScheduledMessages(context.Background(), queryParams)

After that, you can print the response and status code to see the details:

fmt.Printf("Scheduled Messages: %+vn", resp)
fmt.Printf("HTTP response: %sn", respDetails.HTTPResponse.Status)

You should see something like this:

Scheduled Messages: {BulkID:my-bulk-id-1325753 SendAt:2022-07-01T16:00:00.000+0000}
HTTP response: 200 OK

Now, let’s try changing the SendAt time for our bulk.

Change the sending time

To change the time for sending the bulk, you need to create a request with the new time and use query parameters to specify the bulk ID. We will change the date time to the next day, and an hour earlier. Here are the parameters and the request:

queryParams := models.RescheduleSMSParams{
  BulkID: "my-bulk-id-1325753",
}

req := models.RescheduleSMSRequest{
  SendAt: "2022-07-02T15:00:00.000+0000",
}

And then call the RescheduleMessages function:

resp, respDetails, _ := client.SMS.RescheduleMessages(context.Background(), req, queryParams)

After that, you can print the response and details like this:

fmt.Printf("Rescheduled Messages: %+vn", resp)
fmt.Printf("HTTP response: %sn", respDetails.HTTPResponse.Status)

And you should see the new SendAt time for the bulk:

Rescheduled Messages: {BulkID:my-bulk-id-1325753 SendAt:2022-07-02T15:00:00.000+0000}
HTTP response: 200 OK

See the status of your scheduled messages

You can check the status of your bulk of scheduled messages by calling the GetScheduledMessagesStatus function. Use query parameters to filter your bulk like this:

queryParams := models.GetScheduledSMSStatusParams{
  BulkID: "my-bulk-id-1325753",
}

Then call the function like this:

resp, respDetails, _ := client.SMS.GetScheduledMessagesStatus(context.Background(), queryParams)

Then you can print the response and details like this:

fmt.Printf("Scheduled Messages Status: %+vn", resp)
fmt.Printf("HTTP response: %sn", respDetails.HTTPResponse.Status)

And you should get a status like this:

Scheduled Messages Status: {BulkID:my-bulk-id-1325753 Status:PENDING}
HTTP response: 200 OK

Change the status of your scheduled messages

You can also change the status of your bulk to, for example, cancel sending a bulk. To do that, you need to create a request with the new status and use query parameters to filter your bulk. Create the parameters and request like this:

queryParams := models.UpdateScheduledSMSStatusParams{
  BulkID: "my-bulk-id-1325753",
}

req := models.UpdateScheduledSMSStatusRequest{
  Status: "CANCELED",
}

And then call the UpdateScheduledMessagesStatus function like this:

resp, respDetails, _ := client.SMS.UpdateScheduledMessagesStatus(context.Background(), req, queryParams)

Then you can print the response and details like this:

fmt.Printf("Scheduled Messages Status: %+vn", resp)
fmt.Printf("HTTP response: %sn", respDetails.HTTPResponse.Status)

And you should see the CANCELED status:

Scheduled Messages Status: {BulkID:my-bulk-id-1325753 Status:CANCELED}
HTTP response: 200 OK

And that’s it!

Thanks for reading!