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
  • By Sam Agnew
    Identifying Phone Number Line Types with Twilio Lookup and Node.js Copy of Generic Blog Header 2 (3).png

    While the Twilio Messaging API won't charge you for attempting to send an SMS to a landline number, identifying the line type of a phone number can be useful for other reasons. A lot of businesses won't let users sign up with VoIP numbers, for example.

    Let's walk through how to identify a phone number's line type with Twilio Lookup and Node.js.

    Setting up

    For this post you will need:

    To install the Twilio npm module, navigate to the directory where you want this code to live and navigate to the directory where you want this code to live and run the following command in your terminal to create a package for this project:

    npm init --yes
    

    The --yes argument just runs through all of the prompts that you would otherwise …

    Read More
  • By Sam Agnew
    Identifying Phone Number Carriers with Node.js and Twilio Lookup Copy of Generic Blog Header 2 (2).png

    Trolls and bad actors sometimes use phone numbers from free online providers to create fake profiles for making spam calls. Twilio's Lookup API helps you identify the carrier behind the phone number to learn which users have real mobile numbers.

    Setting up

    To lookup a phone number you will need:

    To install the Twilio npm module, navigate to the directory where you want this code to live and navigate to the directory where you want this code to live and run the following command in your terminal to create a package for this project:

    npm init --yes
    

    The --yes argument just runs through all of the prompts that you would otherwise have to fill out or skip. Now that we have a package.json for our app, let’s install the Twilio module …

    Read More
  • By Sam Agnew
    Identifying Phone Number Carriers in Python with Twilio Lookup Copy of Generic Blog Header 2 (1).png

    Trolls and bad actors sometimes use phone numbers from free online providers to create fake profiles for making spam calls. Twilio's Lookup API helps you identify the carrier behind the phone number to learn which users have real mobile numbers.

    Setting up

    To lookup a phone number you will need:

    To install the Twilio Python module, navigate to the directory where you want this code to live and make sure you create a virtual environment. Once you have a virtual environment activated, run the following command to install the dependencies:

    pip install twilio==6.31.1
    

    After this you should be good to write some code!

    Looking up a carrier with Twilio

    You can query the Twilio Lookup API for information about a phone number. There are two Type …

    Read More
  • By Sam Agnew
    Scheduling Tasks in Python with Redis Queue and RQ Scheduler Copy of Generic Blog Header 3.png

    Executing specific code at specific times is a common task in Python. There are a variety of tools to solve this issue, but RQ Scheduler is a lightweight, elegant solution built on top of another tool with a low barrier to entry called Redis Queue.

    With RQ Scheduler, all you need to do is create a Scheduler object and provide it with a Python datetime and a function to execute, along with any arguments you want to pass to the function:

    from datetime import datetime
    
    from redis import Redis
    from rq_scheduler import Scheduler
    
    from some_module import arbitrary_function
    
    scheduler = Scheduler(connection=Redis()) # Get a scheduler for the "default" queue
    scheduler.enqueue_at(datetime(2020, 1, 1), arbitrary_function) # Date time should be in UTC
    

    Let’s walk through how to queue up a function that notifies you when the International …

    Read More
  • By Sam Agnew
    Asynchronous Tasks in Python with Redis Queue Copy of Generic Blog Header 4 (1).png

    RQ (Redis Queue) is a Python library that uses Redis for queueing jobs and processing them in the background with workers. It has a much lower barrier to entry and is simpler to work with than other libraries such as Celery.

    RQ, and task queues in general, are great for executing functions that are lengthy or contain blocking code, such as networking requests.

    Using RQ is as simple as creating a queue, and enqueueing the desired function along with the arguments you want to pass to it, according to the code in their “Hello World” example:

    from redis import Redis
    from rq import Queue
    
    from my_module import count_words_at_url
    
    q = Queue(connection=Redis())
    result = q.enqueue(count_words_at_url, 'http://nvie.com')
    

    Let’s walk through how to use RQ to execute a function that grabs data from the Mars Rover API.

    Setting up your …

    Read More
  • By Sam Agnew
    Updating Twilio phone calls in real time with Python Copy of Generic Blog Header 4.png

    Twilio use TwiML to programmatically define the actions that take place during a phone call. But this doesn't have to be a rigid script that every call follows. You can also use the Twilio REST API to update these phone calls in real time.

    For example, given a Call SID, a unique identifier to a phone call resource, you can redirect which TwiML the phone call is using with the following code:

    from twilio.rest import Client
    
    client = Client('ACCOUNT_SID', 'AUTH_TOKEN')
    
    call = client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
    call.update(method='POST', url='http://demo.twilio.com/docs/voice.xml')
    

    Let's walk through how to set up a Twilio phone number to receive phone calls in Python, and test this out for yourself.

    Development Environment Setup

    Start by making sure you have the right software installed and set up that you'll need to use for the …

    Read More
  • By Sam Agnew
    Updating Twilio phone calls in real time with Node.js Copy of Generic Blog Header 2.png

    Twilio use TwiML to programmatically define the actions that take place during a phone call. But this doesn't have to be a rigid script that every call follows. You can also use the Twilio REST API to update these phone calls in real time.

    For example, given a Call SID, a unique identifier to a phone call resource, you can redirect which TwiML the phone call is using with the following code:

    const client = require('twilio')();
    
    client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
      .update({method: 'POST', url: 'http://demo.twilio.com/docs/voice.xml'})
    

    Let's walk through how to set up a Twilio phone number to receive phone calls, and test this out for yourself.

    Development Environment Setup

    Start by making sure you have the right software installed and set up that you'll need to use for the rest of this post. Throughout this post, you will need: …

    Read More
  • By Sam Agnew
    Web Scraping and Parsing HTML in Python with Beautiful Soup Copy of Generic Blog Header 4.png

    The internet has an amazingly wide variety of information for human consumption. But this data is often difficult to access programmatically if it doesn't come in the form of a dedicated REST API. With Python tools like Beautiful Soup, you can scrape and parse this data directly from web pages to use for your projects and applications.

    Let's use the example of scraping MIDI data from the internet to train a neural network with Magenta that can generate classic Nintendo-sounding music. In order to do this, we'll need a set of MIDI music from old Nintendo games. Using Beautiful Soup we can get this data from the Video Game Music Archive.

    Getting started and setting up dependencies

    Before moving on, you will need to make sure you have an up to date version of Python 3 and pip installed. Make sure you create and activate …

    Read More
  • By Sam Agnew
    Generating Nintendo Music Over the Phone in Python with Magenta and Twilio Copy of Generic Blog Header 1-3.png

    Artificial creativity is amazing, and I am always blown away by what people accomplish with neural networks. Lots of developers have used Python libraries like Magenta to create awesome music.

    I used Magenta to train a neural network on a bunch of classic Nintendo music, and I thought it would be fun to hack around with that and make a Twilio phone number you can call to hear computer-generated NES music. If you're in the US, try calling ‭(424) 398-8637‬ (424-39-TUNES) to hear!

    Let's walk through how to build a phone number that plays computer generated music using Magenta.

    Installing dependencies

    First we need to install Magenta, which can be done using pip. Make sure you create a virtual environment before moving forward. I am using Python 3.6.5, but Magenta is compatible with both Python 2 and 3.

    Run the following command to install Magenta in your …

    Read More
  • By Sam Agnew
    Training a Neural Network on MIDI data with Magenta and Python Copy of Generic Blog Header 3-5.png

    Since I started learning how to code, one thing that has always fascinated me was the concept of computers creating music. With Magenta, a Python library built that makes it easier to process music and image data, this can be done more easily than before. Magenta has pre-trained example models you can use to generate music, as seen in a previous blog post, but it's a lot more fun to create your own.

    Let's walk through how to use Magenta to train a neural network on a set of music data from classic Nintendo games to generate new Nintendo-sounding tunes.

    Super Mario Bros 2 GIF

    Installing Magenta

    First we need to install Magenta, which can be done using pip. Make sure you create a virtual environment before installing. I am using Python 3.6.5, but Magenta is compatible with both Python 2 and 3.

    Run the following command to install Magenta in your …

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