Receive SMS Delivery Receipts With Go

In previous posts, we showed you how to send an SMS with Go and receive an SMS with Go. This post will show you how to receive SMS delivery receipts of SMS messages sent from your Vonage account.

This tutorial will cover setting up a publicly accessible webhook and the functionality to receive SMS delivery receipts. You can find the code used in this tutorial on our Go Code Snippets Repository.

Prerequisites

Vonage API Account

This tutorial also uses a virtual phone number. To purchase one, go to Numbers > Buy Numbers and search for one that meets your needs. If you’ve just signed up, the initial cost of a number will be easily covered by your available credit.

Set up the Code

If you have configured a webhook, Vonage will send a POST request to this webhook, so it's time to create the code to handle this webhook request.

Create a file called delivery-receipt.go and enter the following code:

This code will listen for any request sent to the /webhooks/delivery-receipt endpoint and outputs the status part of the body of the request.

Expose the Project To the Internet

Ngrok is our suggested tool used to run examples in development and is used in this tutorial to expose the webhook endpoint. If you haven’t got ngrok installed, you can find a great introduction to this service and how to install it in this tutorial.

Launch ngrok with the command below:

Make a note of the public URLs that ngrok creates for you; these will be similar to the example below:

Note: This URL will be different every time you run the command if you’re using the free plan. So you will have to update the delivery-receipt URL in the dashboard each time you run the command.

Configure Your Vonage Account

Time to Test

Now, within another Terminal window, run the following command, replacing YOUR_NUMBER with your phone number to receive the test SMS message.

If you check the Terminal window where you ran go run ./, you should see a line like what you see below appear:

The webhook receives more fields than are displayed above. You can see a full list of these fields with some examples below. The example below is from the API docs under Delivery Receipt:

Further Reading

Below are a few other tutorials we’ve written involving Go:

Don’t forget that if you have any questions, advice, or ideas you’d like to share with the community, please feel free to jump on our Community Slack workspace. I’d love to hear back from anyone that has implemented this tutorial and how your project works.

Developer content from the team at Vonage, including posts on our Java, Node.js, Python, DotNet, Ruby and Go SDKs