Cloud Code Functions
Integrations

Twilio

9min

Using cloud functions and Twilio API to send Text Message

Introduction

This guide explains how you can use the Twilio REST API to send SMS. After completing this step-by-step tutorial, you can use your cloud code function to send SMS to your device.

Prerequisites

To complete this tutorial, you will need:

Let’s get started!

Below are some steps you need to follow when writing a function to send SMS to a User and phone number.

To learn how to create or access an Account in Twilio, check the links given below:

1 - Activate your Phone Number

After logging in or creating a new account, you will be redirected to your Project. There, on the left, you need to click on the #Phone Numbers. Next, tap on the last link ‘Getting Started’, and then click on the button ‘Get your first Twilio phone number’. Same as shown below:

Document image


After that you will receive your first Phone Number for your Twilio Account. If you can’t find your phone number, go to #Phone Numbers and Manage Numbers.

Document image


2 - Get Account SID and Auth Token

To find your Account SID and Auth Token, log in to your Account, go to your Dashboard and click on Settings. All the important information about your Project will be available in that section; as shown in the image below:

Document image


Now, you can Copy your SID and Authentication Token for the Cloud Code.

3 - Install Module from Twilio

After configuring the environment for the Command Line Interface in your computer, create a file called package.json, and inside this file, you need to install the Twilio module, like:

JSON


4 - Implement Cloud Code

Parse Server 3.X
Parse Server 2.X


5- Test the function “sendSMS”

You can also test the function in client SDKs, but for now, we will use the REST API command to send it:

Curl


And the result will be something like as this:

Document image


6 - It’s done!

With the guide described above, you’ll be able to use Twilio with a Cloud Code Function in Back4App and send SMS to your customers!

In case you need any help or a function/link doesn’t work, please contact our team via chat!

Updated 28 Mar 2024
Did this page help you?