Skip to main content

Documentation Index

Fetch the complete documentation index at: https://plivo.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

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.
Here’s how to use Plivo APIs to set up an SMS autoresponder.

How it works

Outbound-SMS Flow

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. To receive incoming messages, you must have a Plivo phone number that supports SMS; you can rent numbers from the Numbers page of the Plivo console or by using the Numbers API. If this is your first time using Plivo APIs, follow our instructions to set up a .NET development environment.

Create a .NET controller

Navigate to the Controllers directory, create a controller called Autoresponder.cs, and paste into it this code.
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;


namespace demo.Controllers
{
    public class Autoresponder : Controller
    {
        public IActionResult Index()
        {
            String from_number = Request.Form["From"];
            String to_number = Request.Form["To"];
            String text = Request.Form["Text"];
            String body;

            if (text.ToLower() == "interested")
            {
                body = "Thank you for showing interest. One of our agents will contact you.";
            }
            else
            {
                body = "Reply 'Interested' to connect with our agents";
            }

            Plivo.XML.Response resp = new Plivo.XML.Response();
            resp.AddMessage(body, new Dictionary<string, string>()
            {
                {"src", from_number},
                {"dst", to_number},
                {"type", "sms"}
            });
            var output = resp.ToString();
            Console.WriteLine(output);
            return this.Content(output, "text/xml");
        }
    }
}
Run the project and you should see your basic server application in action at http://localhost:5001/autoresponder/.Set up ngrok to expose your local server to the internet.

Create a Plivo application for the autoresponder

Associate the controller you created with Plivo by creating a Plivo application. Visit Messaging > Applications and click Add New Application. You can also use Plivo’s Application API.Give your application a name — we called ours Autoresponder. Enter the server URL you want to use (for example https://<yourdomain>.com/autoresponder/) in the Message URL field and set the method to POST. Click Create Application to save your application.
Create Application

Assign a Plivo number to your application

Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, select XML Application.From the Plivo Application drop-down, select Autoresponder (the name we gave the application).Click Update Number to save.
Assign Phone Number to Plivo Number

Test

Send a text message to the Plivo number you specified using any phone.