Serverless Ruby on AWS Lambda with the Jets framework
When AWS launched Lambda in 2014 there was no love for Ruby. Platforms like Python, Node.js, and Java started the serverless revolution for hosting and running functions in the cloud. At the end of 2018, support for Ruby was finally launched.
You can build with Ruby on Lambda using raw functions and Serverless Application Model (SAM) templates as described in the getting started guide for Ruby on Lambda, but Ruby is all about developer happiness and when the config file is longer than your program the process could be described as painful. Enter the Jets framework a framework that "leverages the power of Ruby to make serverless joyful for everyone."
From Rails to Jets
Jets combines the experience of building a Rails application with the ability to deploy to AWS Lambda and related services, including API Gateway, S3, and DynamoDB. In this post we're going to see how ...
Send Images and Files via WhatsApp Using Ruby
With the Twilio API for WhatsApp we can send messages to WhatsApp numbers. Those messages can be plain text or include files like images, audio and even PDFs up to 5MB. Let's see how to do so using Ruby.
Things you'll need
If you want to code along with this post, you'll need a few things:
- A Twilio account (sign up for a free account now)
- Ruby and Bundler installed
- The WhatsApp Sandbox Channel installed (learn how to activate your WhatsApp sandbox)
Got all that? Let's get coding then!
Create a new directory for your project and use Bundler to initialise a new
mkdir whatsapp-messages cd whatsapp-messages bundle init
Open up the new
Gemfileand add the
# frozen_string_literal: true source "https://rubygems.org" gem "twilio-ruby"
Install the gem by running
bundle installon the command line.
Sending your first WhatsApp message
Create a file in your project ...
Go celebrity spotting with the Twilio API for WhatsApp, AWS Rekognition and Ruby
Did you know you can send and receive media using the Twilio API for WhatsApp? When I found out I wanted to make something fun with it, so why not combine it with AWS Rekognition to work out if I look like any celebrities?
By the end of this post, you'll know how to build an app that lets you send an image to a WhatsApp number, download the image, analyse the image with the AWS Rekognition API and respond to say whether there are any celebrities in the picture.
What you'll need
To build this application you'll need a few things:
- A Twilio account, sign up for a free one here
- An AWS account
- Ruby and Bundler installed
- ngrok to help us test our webhooks
Got all that? Let's get started then.
When Twilio receives a WhatsApp message it will send an HTTP request, a webhook, to ...
How to download image files in Ruby
Have you ever needed to download and save an image in your Ruby application? Read on to find out how.
Plain old Ruby
The most popular way to download a file without any dependencies is to use the standard library
Kernel#openis a method that you can use to open files, streams, or processes to read to or write from. For example, you can open a file and read its contents with the following code:
open("./test.txt") do |file| puts file.read end
Kernel#openso that it can open URIs as if they were files. We can use this to download an image and then save it as a file.
To do so, we first require
open-urithen use the
openmethod to access an image URL. We can then open up a file and write the contents of the image to the file ...
How to Build Chat into Ruby on Rails Applications
We build web applications for all kinds of projects. If you want to give support agents a way to communicate with customers, or provide your users with a place to share ideas, you might find yourself wanting to add messaging to your application. Let's use Twilio Programmable Chat and Ruby on Rails to build a full-featured chat application from scratch.
Creating a New Rails App
First we'll make sure we've got a recent version of Ruby installed, then we'll install Rails and create a new application.
gem install rails rails new twilio-chat
The last command will generate our Rails application in the
twilio-chatdirectory. If we move into our newly created directory and start our server, then visit
http://localhost:3000in our browser, we should see the default Rails server page.
cd twilio-chat rails s
Adding a Default Action
Now let's return to our terminal and stop our Rails ...
Verifying Phone Numbers in Ruby on Rails with Twilio's Verify API
In the public-facing world of apps, verifying that users are real people can be tough. This is where phone verification really becomes an asset, helping to mitigate fraud.
In this post, we will walk through integrating Twilio’s Verify API into a Ruby on Rails application to discover whether a user’s phone number exists, its type of line, and its carrier. We will then authenticate the user with Verify’s token verification.
We will build a simple login action, with phone verification. This walk-through will provide basic functionality that can be ported to new or existing Ruby/Rails applications.
At a high level, successful interactions will look something like:
- The user submits a phone number to the application.
- The phone number is verified as real, or not; and whether the phone is a mobile or a landline.
- If the number is a valid cell, the user is ...
Build a collaborative playlist over WhatsApp with Rails, Twilio, and Spotify
Sharing music over playlists is a great way to discover new and old music. Spotify has collaborative playlists, but I don't like how they let your friends re-order and delete songs from the list. We can fix this by building our own collaborative playlist that only allows additions using the Spotify Web API. With the Twilio API for WhatsApp we can let our friends send in a song whenever they are struck by inspiration.
In this post we are going to build a WhatsApp bot that can do all of the above using Ruby on Rails.
To build this application we will need a few things:
Adding Automated Speech Recognition for Phone Calls to Ruby on Rails Applications
With the advent of personal digital assistants and in-home, voice-controlled gadgets, voice technologies are on the rise. Working with voice and speech recognition technologies is a crucial skill to have, not just in emergent technologies, but also in robust, existing applications. In this tutorial, we will build an implementation of Twilio’s Automated Speech Recognition (ASR) service in a simple Ruby on Rails Application, in hopes of you being able to see the wide-reaching possibilities for other implementations in your own projects.
In this tutorial, we will build a simple “Feedback Service” that receives, responds to, and stores voice messages from user phone calls—using speech recognition—and then displays them for review at a later time.
Getting Started with Our Rails App
Generating Music with Sonic Pi and Ruby
Sonic Pi is an Integrated Development Environment (IDE) for writing music in Ruby. I write code with Ruby using the Sonic Pi IDE and sample myself screaming over it with Audacity under the artist name Messica Arson. The sound I create is very much inspired by the strange sounds of noise music combined with my screams I perfected while fronting a punk band.
In this tutorial we’ll walk through how to create this song together.
What is Sonic Pi?
With Sonic Pi we can interact with our computer as if we were using a synthesizer. Under the hood Sonic Pi is a Ruby wrapper for SuperCollider. There are samples and synthesizers loaded in that you can interact with in countless ways. You can also add your own samples as we will be doing in this tutorial.
Download Sonic Pi before moving on with the rest of the post. If ...
Add SMS Notifications to Your Rails App Using Twilio
Anyone living in NYC with a car knows the pain that is Alternate Side Parking rules. There’s the need to always to be conscious of which side of the street your car is parked on, to run out at the most inopportune times to move it to the other side of the street, and occasionally the opportunity to be blocked in by someone double-parking. All of these, and more, are part of what New York drivers have to put up with on a weekly cycle.
The idea hit on and followers kept coming in… but it had its limitations. First of all, most people aren’t glued to their Twitter feeds, and one tweet can easily ...