Use Twilio and NodeJs to Instantly Receive Customer Support Text Messages

Imagine if you could respond to a customer support request the instant a customer has a problem. Luckily, the Twilio API makes this automation not only a possibility, but incredibly easy and free.

In this tutorial I am going to show you how to forward customer service requests from your website to your phone, by creating a simple program that will send a text message whenever a customer submits a request on my website. I am going to use Nodejs, and the Twilio API.

You can checkout the github link here

The first step is to create an npm project using npm init

mkdir twiliocs
cd twiliocs
npm init

Then install the twilio package

npm install twilio

To use the Twilio API you need to make an account with Twilio, and include your account sid and auth token credentials, which can be found here

You also need to create a Twilio phone number (free with trail account)

Finally, include the phone number that you would like to receive the texts on

I created a file called server.js, and included these credentials

Once you have these credentials in your file, create a message

Great! Run the program by typing node server.js into the terminal, and you should receive a text!

node server.js

The next step is to create a GET and POST route, the later will receive the customers message, and forward the message to your phone using Twilio. In this example, I use express to handle my routing. I also npm install ‘body-parser’, which will help me read the customer’s message from my html page, and I npm install ‘path’, which will help serve my simple html page when the GET request is made.

The html file I created, contact.html, contains a simple form that makes a post request to the /contact route when someone submits a customer service request

Once this form is submitted, the name, email, number, and message of the customer are sent to the POST contact route, which then sends a text message directly to my phone, with the contents being the customers contact info and problem

And that’s it!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.