Sending SMS notifications

A very common use case for using a service like Ringcaptcha is to be able to schedule SMS’s or calls. Maybe you want to schedule a text to go out at specific time, or notify all your users about something via SMS every day. Ringcaptcha doesn’t have scheduling built in, but here’s an easy way to schedule your Ringcaptcha SMS’s using IronWorker.

All of the code in this post is available on Github and I recommend you clone that repo as a starting point. You will need to have an account and a Ringcaptcha account to run the examples and this post is meant to quickly take you through the important things without going into setup/configuration which you can find on this README.

Create an SMS worker

First, let’s start by creating a simple sms worker. You can write this in any language, but for this post, I’ll be using Ruby. This worker simply sends an SMS via the Ringcaptcha API, but you can easily make it do a whole lot more like get data from various places and send a more meaningful message depending on what your application does. This is sms.rb:

Upload the worker

Now that we have our worker code, we need to install our worker’s dependencies, zip the code and upload to Iron. Pull our github repo and run the following commands:

cd /iron-worker-examples/sms_notifications/ruby/ringcaptcha/

docker run --rm -v "$PWD":/worker -w /worker iron/ruby:2.4-dev bundle install --standalone --clean

zip -r .

iron worker upload -e "APP_KEY=YOUR_RINGCAPTCHA_APP_KEY" -e "API_KEY=YOUR_RINGCAPTCHA_API_KEY" --name ringcaptcha-worker --zip iron/ruby:2.4 ruby sms.rb

Queue up tasks for the worker

Now that we’ve created our sms worker and uploaded it, we can queue up tasks for it. One task or millions of tasks, doesn’t matter.

iron worker queue --payload-file payload.json --wait ringcaptcha-worker

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.