This quick walk-through will show you how to create an SMS message log and a response to the sender using Firebase Cloud Functions and the Real Time Database alongside the Vonage SMS API.
You can send SMS messages using Cloud Functions for Firebase.
You'll need to create a couple of accounts:
- a Firebase
- and a Vonage API one.
Create the project in the Firebase console and choose whether or not you will use Analytics.
Wait for your project to be created.
Select the Firebase billing plan, in this case, it is the pay as you go.
In the Command line, install the Firebase tools.
Login to Firebase and authenticate. Create the project folder and change directory inside of it.
Initialize the Cloud Functions for Firebase.
Install the dependencies we are going to use inside the functions folder.
.env file and add the Vonage environment variables there.
Inside the file
index.js, add all the required dependencies and environment variables and initialize Firebase.
In the same file, create the first function which will act as a webhook to capture and log incoming SMS messages from a Vonage phone number.
Let's then create a function for Firebase to send the response SMS and to react to database updates.
Deploy the function, send an SMS message from your phone to the Vonage application phone number.
You'll then receive a response SMS message on your phone and an update to Firebase Real-Time Database.
You can find the full code on GitHub. Thank you for watching and happy coding!