This example sends and receives Vonage SMS with Cloud Functions for Firebase. Inbound SMS messages use a webhook on Firebase to add the message to the Firebase Realtime Database. Upon creation, a triggered function will echo back the original text to the phone number.
If you're new to Vonage, you can sign up for a Vonage account and get some free credit to get you started.
- Google Cloud account
- Vonage account
- SMS enabled phone
- Clone this repository and switch to the cloned directory
- Setup Firebase Tools
- Run
firebase init functions
- Create a new project
- Select JavaScript
- Add ESLint (optional)
- Do not overwrite any files
- Install all dependencies
- Run
- Open Firebase console https://console.firebase.google.com/project/YOUR-PROJECT-ID/
overview
. Go to ⚙️ -> Project Settings
- Update
Google Cloud Platform (GCP) resource location
to something near your location - Go to ⚙️ -> Usage and Billing -> Details & Settings
- Update the plan to
Blaze - Pay As You Go
- Update
- Run
firebase deploy --only functions
- Copy the function route -
https://[LOCATION]-[YOUR-PROJECT-ID].cloudfunctions.net/inboundSMS
- Copy the function route -
- Setup the Vonage CLI
- Create a new application
vonage apps:create
- Purchase a new phone number using. The example below will buy an available US phone number. For more information on SMS Countries and Features - visit the API Support Help Center
vonage numbers:search US
vonage numbers:buy [NUMBER] --country_code US
- Link the number (for instance 15555555555) to the application
vonage apps:link [APPID] --number=[NUMBER]
- Add the function to the inbound SMS in the Vonage dashboard
https://[LOCATION]-[YOU R-PROJECT-ID].cloudfunctions.net/inboundSMS
- Add your Vonage keys to the Firebase environment variables
firebase functions:config:set vonage.api_key="Your Key" vonage.api_secret="Your Secret"
Text anything you want to the purchased number, and it will echo back what you sent in.
To: 15555555555
Hello World!
From: 15555555555
You sent the following text: Hello World!
We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:
- Open an issue on this repository
- Tweet at us! We're @VonageDev on Twitter
- Or join the Vonage Community Slack
- Check out the Developer Documentation
- Details about Vonage SMS Functionality
- Getting started with Cloud Functions for Firebase