Skip to main content

Overview

This guide shows how to conduct an SMS survey using Plivo’s APIs and Node.js. This involves two parts: sending an initial question via the REST API, and then handling the user’s reply via a webhook.

How it works

  1. Initiate Survey: Your application makes a POST request to a /send-survey/ endpoint. This triggers Plivo’s Send Message API to send the first survey question to the user.
  2. Handle Response: The user replies to the SMS. Plivo sends a webhook with their reply to a /survey-response/ endpoint. Your application processes their answer (“Yes” or “No”) and replies with a thank-you message using Plivo XML.

Prerequisites


Create the survey application

Create a file named survey.js and paste in this code. It sets up an Express server with two endpoints: one to start the survey and one to handle replies.

Test

  1. Run the application: node survey.js.
  2. Expose your local server to the internet using ngrok: ngrok http 3000.
  3. Create a Plivo Application with the Message URL set to https://<your-ngrok-url>.ngrok.io/survey-response/.
  4. Assign a Plivo number to the application.
  5. Use a tool like Postman to send a POST request to http://localhost:3000/send-survey/ to start the survey.
  6. Reply “Yes” or “No” from the destination phone to see the auto-response.