Write an SMS Autoresponder Using Go


    This guide shows how to write an autoresponder for SMS text messages. Autoresponders can streamline marketing campaigns and subscription signups and reduce the amount of work humans have to do.

    You can create an autoresponder either by using our PHLO visual workflow builder or our APIs. Follow the instructions in one of the tabs below.

    You can create and deploy a PHLO to implement an SMS autoresponder with a few clicks on the PHLO canvas.

    How it works


    To get started, you need a Plivo account — sign up with your work email address if you don’t have one already.

    Create the PHLO

    To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

    • Click Create New PHLO.

    • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.

      Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
    • If you plan to use a dynamic payload — passing values through parameters when you trigger the PHLO from your application — click on the Start node to open the Configuration pane. Under API Request, enter key names for the variables you want to use in your payload — for example, a list of numbers to send an SMS message to.

    • Once you’ve configured the node, click Validate to save the configuration.

    • From the list of components on the left-hand side, drag and drop the Send Message component onto the canvas. When a component is placed on the canvas it becomes a node.

    • Draw a line to connect the Start node’s Incoming Message trigger state to the Send Message node.

    • In the Configuration pane at the right of the canvas, configure the Send Message node with a sender ID in the From field. Enter the destination number you wish to send a message to in the To field. Put your message in the Text field.

      Note: You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through Liquid templating parameters when you trigger the PHLO from your application.
    • Once you’ve configured the node, click Validate to save the configuration.

    • After you complete the configuration, give the PHLO a name by clicking in the upper left, then click Save.

    Assign the PHLO to a Plivo number

    Once you’ve created and configured your PHLO, assign it to a Plivo number.

    • On the Numbers page of the console, under Your Numbers, click the phone number you want to use for the PHLO.
    • In the Number Configuration box, select PHLO from the Application Type drop-down.
    • From the PHLO Name drop-down, select the PHLO you want to use with the phone number, then click Update Number.

    Assign PHLO to a Plivo Number


    You can now send a message to your Plivo phone number and see how the autoresponder works.

    For more information about creating a PHLO application, see the PHLO Getting Started guide. For information on components and their variables, see the PHLO Components Library.

    Note: If you’re using a Plivo Trial account, you can send SMS messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.

    To implement SMS Autoresponder use-case in the traditional API way, you can refer to the instructions in the below section to begin your implementation.


    Outbound-SMS Flow


    In this section, we will guide you in setting up an app using Plivo’s API to implement SMS Autoresponder use-case. First, let’s make sure you meet these prerequisites before we dive into the code.


    • Plivo Auth Id and Auth Token: You will find your Plivo Auth Id and Auth Token on the home screen of your Plivo Console. Click here to sign-up for a Plivo account if you haven’t already!

      Find Your Auth Credentials on Plivo Console

    • Plivo Phone Number(Optional): To send messages to the United States and Canada, you must have a Plivo phone number that supports SMS. Numbers can be purchased from the Numbers section of your Plivo Console and use the same as the source number/from number for the outbound SMS. This number will also help you receive incoming SMS as you must have a SMS-enabled Plivo phone number to do the same. Please note that you can also purchase numbers using the Numbers API.

      Buy a New Plivo Number

    Set up Your Go Dev Environment

    Once you have the above prerequisites set, You can follow the below instructions to create an app to send an outbound SMS to deliver your message.

    Install Go

    You can install Go from the Official Installer.

    Install Plivo Go Package

    • Create a project directory, run the following command:

      $ mkdir mygoapp
    • Change the directory to our project directory in the command line:

      $ cd mygoapp
    • You can install the Plivo Go package using the go command.

      $ go get github.com/plivo/plivo-go
    • You can also install by cloning this repository into your GOPATH.

    Create the Send SMS App

    Once you have the above prerequisites set, You can follow the below instructions to create an app to send an outbound SMS to deliver your message.

    Now, create a file called SendSMS.go and paste the following code:

    package main
    import "fmt"
    import "github.com/plivo/plivo-go"
    func main() {
    	client, err := plivo.NewClient("<auth_id>","<auth_token>", &plivo.ClientOptions{})
    	if err != nil {
    			fmt.Print("Error", err.Error())
    	response, err := client.Messages.Create(
    			Src: "+14151234567",
    			Dst: "+14157654321",
    			Text: "Hey, I’m interested in this property!",
    	if err != nil {
    			fmt.Print("Error", err.Error())
    	fmt.Printf("Response: %#v\n", response)
    • Replace the placeholders auth_id & auth_token with your credentials from Plivo Console
    • We recommend that you store your credentials in the auth_id & auth_token environment variables, so as to avoid the possibility of accidentally committing them to source control. If you do this, you can initialize the client with no arguments and it will automatically fetch them from the environment variables
    • You can use os.Setenv & os.Getenv function to store environment variables and fetch them while initializing the client.
    • Replace the placeholder +14151234567 with the Phone number which you have purchased and +14157654321 with the phone number you will be sending SMS to.
    • Both plivo_source_number and +14157654321 should be in E.164 format
    • For other countries, this can be either a Alpha Sender ID or Numeric Sender ID based on the Sender ID support for the respective countries, to know more you can refer to the Sender ID Usage guide

    Test and Validate

    Once you have created the Send SMS App, save the file and use the below command to run it.

    go run SendSMS.go
    Note: If you are using a Plivo Trial account for this example, you can only send SMS to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.