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
- Do not overwrite any files
- Install all dependencies
- 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
- 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
- Purchase a new phone number using
vonage number:buy --country_code US
- This will buy an available US phone number
- For more information on SMS Countries and Features - visit https://help.nexmo.com/hc/en-us/articles/115011451687-SMS-Numbers-Features-Overview
- Link the function route to the number
vonage link:sms 15555555555 https://[LOCATION]-[YOUR-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 at https://developer.vonage.com
- Details about Vonage SMS Functionality https://developer.vonage.com/messaging/sms/overview
- Getting started with Cloud Functions for Firebase https://firebase.google.com/docs/functions/get-started