This is a demo app showcasing how to get up and running with the Vonage Verify API in Ruby.
Users sign up on the website by providing their mobile phone number. The Verify API sends a pin code to the user's phone. The user enters the pin code on the website and confirms their identity. The application also provides a raffle drawing option, wherein a random confirmed user can be selected from the database and they will be notified via a phone call that they won the drawing.
This app requires Ruby v2.7 or greater and the following gems:
These are all included in the project's Gemfile
and will be installed when you run bundle install
from the command line.
Once you clone the repository, make sure its dependencies are installed on your local machine:
$ bundle install
Then you will want to create the PostgreSQL database by first running bundle exec rake db:load_config
and then bundle exec rake db:migrate
.
The application to run requires your Vonage API key and secret. Add your Vonage API key and your Vonage API secret to your .env
file. You can rename the .env.sample
file provided in this repository to .env
and fill in the values there.
To start your web server run the following from the command line:
$ bundle exec ruby app.rb
The above command will begin a web server running on port 3000.
The application is now ready to visit.
Users can begin to verify their identity by visiting https://localhost:3000
. They will enter their phone number in the form and press the Submit button. The application will then render a new view with a form to enter the pin code the Vonage Verify API sent to their phone via SMS.
The Verify API will wait 300 seconds for the user to enter the pin. If they do not enter the pin, the API tries again with another text message. If another 300 seconds elapse and the user does not enter the pin, the API will try again with a phone call to the user. You can find more information on the various Verify API workflows, and the default workflow behavior on the Vonage API Developer Portal.
Once the user enters the pin code and presses the Submit button, the application will send a verify request to the Verify API to confirm the pin was correct. If it was correct, the user is saved to the database if they were not previously verified. The final view of the website confirms the verification to the user and lets them know that they have either been entered into the database or not depending on if it was their first confirmed verification.
To select a random winner from confirmed users in the database, the application requires a Vonage provisioned virtual number that is linked to a Voice Voice application. Both of those items can be created from your Vonage Dashboard. The phone number you create in the Dashboard will be the number that will send the pin code to the user.
You will need to provide an event URL
for the application you create that corresponds to the event route provided in the app.rb
file. The event URL needs to be an externally accessible URL that ends with /webhooks/event
. For example, if your URL was example.com
, then your answer URL would be http://example.com/webhooks/event
.
Next, open up the app.rb
file in your preferred code editor and add both your Vonage application ID and your Vonage phone number to the constants defined in the file:
VONAGE_APPLICATION_ID = ''
VONAGE_NUMBER = ''
Make sure to also add your Vonage API key and your Vonage API secret to your .env
file. You can rename the .env.sample
file provided in this repository to .env
and fill in the values there.
Lastly, make sure to generate a public and private key in your Vonage API Dashboard for your application and save the private key to the root folder of this project. Do not forget to also press the Save
button in the dashboard to ensure that the key has been stored successfully for your account.
Once that is completed you are ready to select a winner you can visit http://localhost:3000/winner
and the application will choose one visitor at random and call them to notify them that they won the prize.
If you are running this for a one-time event or do not want to persist the data you can execute bundle exec rake db:drop
at the conclusion of your use of the application. This will drop the database and delete all of the records.
This library is released under the MIT License