Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now
Build the future of communications.
Start building for free

"ruby" posts

  • By Phil Nash
    Build a WhatsApp chatbot with Ruby, Sinatra and Twilio Build a WhatsApp chatbot with Ruby, Sinatra and Twilio

    Chatbots are programs that communicate some way with humans. They can be very basic, responding to keywords or phrases, or use something like Twilio Autopilot to take advantage of natural language understanding (NLU) to provide a richer experience and build out more complicated conversations.

    In this tutorial we are going to see how easy it is to get started building chatbots for WhatsApp using the Twilio API for WhatsApp and the Ruby web framework Sinatra. Here's an example of the conversation we're going to build:

    Using the bot inside the WhatsApp application. First we ask for cats and get a cat picture and fact. Then we ask for dogs and get a dog picture and fact. Finally we ask the bot if it can do anything else and it says it only knows about dogs and cats.

    What you'll need

    To build your own WhatsApp bot along with this tutorial, you will need the following:

    Configure …

    Read More
  • By Phil Nash
    Send and track faxes with the Twilio Fax API using Sinatra and Ruby Send and track faxes with the Twilio Fax API using Sinatra and Ruby

    It happened! I've been waiting for the moment I needed to send a fax since Twilio launched the Programmable Fax API back in 2017 and this week it finally happened! I won't go into detail about what I needed to send, but it's safe to say the medical profession could consider their communication choices for the future.

    I could have sent the fax by uploading a PDF to Twilio Assets and using the API explorer, but that wouldn't have been as fun as over-engineering an entire application to send and track the fax to make sure it arrived and be prepared for any future fax situations.

    In this post I'll share how to build an application for sending and tracking faxes, but if you have faxes to send and want to jump straight into using it, you can find all the source code on GitHub.

    Weapons of choice …

    Read More
  • By Phil Nash
    Track email statuses in Ruby on Rails with SendGrid Track email statuses in Ruby on Rails with SendGrid

    When your application sends emails it is useful to know what happens to those emails, like whether it has been delivered or opened. Or, sometimes more importantly, whether it bounced. The Twilio SendGrid email API doesn't just send emails, it can also send you events via webhook that tell you what happened to your emails.

    In this post we'll build a small application using Ruby on Rails to send emails and update their status based on the Twilio SendGrid event webhooks.

    What you'll need

    In order to build this application along with this post, you will need:

    If you have all of that, then you're ready to get building.

    Preparing the example application

    I …

    Read More
  • By Phil Nash
    Serverless Ruby on AWS Lambda with the Jets framework oMX1dI2w2BskhPm3NagdjbXVb0t9ONMEUOR_7ms5C51r_dW_1mNwj0Y7CYGhu6rlqef7HZr_rh659ECtBuVzqJyqEP5UuHfp6y9JGjCs53qLxeSq0hcbwxyZQZxV4L1dHiaMuBY

    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 …

    Read More
  • By Phil Nash
    Send Images and Files via WhatsApp Using Ruby 8kEzE4pzPwWTXwfR8Cf702Bf_WzY45UvAPBbdqohDl1qudH815kSjIhWqqV4hirBR8iPDRw6EzhsyIH7z4QaJuNvWLyjYmFxrkhBzC8vlaZNsN89BoJx7AToabvAl-M_br4nZBo

    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:

    Got all that? Let's get coding then!

    Create a new directory for your project and use Bundler to initialise a new Gemfile:

    mkdir whatsapp-messages
    cd whatsapp-messages
    bundle init
    

    Open up the new Gemfile and add the twilio-ruby gem:

    # frozen_string_literal: true
    
    source "https://rubygems.org"
    
    gem "twilio-ruby"
    

    Install the gem by running bundle install on the command line.

    Sending your first WhatsApp message

    Create a …

    Read More
  • By Phil Nash
    Go celebrity spotting with the Twilio API for WhatsApp, AWS Rekognition and Ruby Go celebrity spotty 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:

    Got all that? Let's get started then.

    Application basics

    When Twilio receives a WhatsApp message it will send an HTTP request, a webhook …

    Read More
  • By Phil Nash
    How to download image files in Ruby MSjyG8qNtcrbONBpWKztYRJqSpr4R2M6K83KXW4dj05n5p1Q2Ez4kQyLxiX69xnjo2gBNd-KleVK_tnzFhPbqCK70HVdlI-BR9H8Dk8KRL8RcwlpsYT5uysgm5ado7pxcASFHP4

    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 open-uri.

    Kernel#open is 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
    

    open-uri extends Kernel#open so 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-uri then use the open method to access an image URL. We can then open up a file and write the contents of the image …

    Read More
  • By Kevin Thompson
    How to Build Chat into Ruby on Rails Applications M3gM5qVbtMu9XneBCDDDlPXgDITbX1aUvzgLAdF7D4ks04jbNslXJrzNA-jDBKfk2X181Y3G5ip95xws5ETyHSk5i-n1apG_ITJ_U9BFrEv74S-8fXlFodBDUnSdl5sMlkvUdtNk

    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-chat directory. If we move into our newly created directory and start our server, then visit http://localhost:3000 in 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 server …

    Read More
  • By Daniel Phillips
    Verifying Phone Numbers in Ruby on Rails with Twilio's Verify API 6htvpXAFaN9DGB25bk0nOoDQcJqvbUhjC8-aRXWa6H9pBeJFdyh5V0hhzVKTYiIBmkPW976rAK-nOt_KZvceefMvI1GMonwOQvmXJ5h9raCNYEk0u8K0Zf7JTI4LIbG40iFaDzMp

    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.  

    Getting Started

    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:

    1. The user submits a phone number to the application.
    2. The phone number is verified as real, or not; and whether the phone is a mobile or a landline.
    3. If the number is a valid cell, the user is sent an authentication code. …
    Read More
  • By Phil Nash
    Build a collaborative playlist over WhatsApp with Rails, Twilio, and Spotify ugrWaR5LljMMUPyVEqxuZ926T4rpyZUj4vpt0ObjwSQEo7kWscZbctRvJpNMbTakGAQLg7WF9gitzaELHYRhI9eFxJRHJjd6HRg6kkyBLkqTcrzU9qbx9M4L1Amr6iKSmS_5Dds

    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.

    Getting started

    To build this application we will need a few things:

    Read More
  • Newer
    Older
    Sign up and start building
    Not ready yet? Talk to an expert.