Build the future of communications.
Start building for free
  • By Sam Agnew
    Working with MIDI data in Python using Mido Working with MIDI data in Python with Mido

    MIDI is an extremely popular and versatile format for music data, whether you're using it as a digital musical instrument interface or just transcribing music in it to show your bandmates new songs. Mido is a Python library you can use to interact with MIDI in your code.

    Let's walk through the basics of working with MIDI data using the Mido Python library.

    Setting up

    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 a virtual environment before installing Mido.

    Run the following command to install Mido in your virtual environment:

    pip install mido==1.2.9
    

    In the rest of this post, we will be working with these two MIDI files as examples. Download them and save them to the directory where you want your code to run.

    VampireKillerCV1.mid ...

    Read More
  • By Sam Agnew
    Parsing an Incoming Twilio SMS Webhook with Node.js Copy of Product Template - SMS-4.png

    When responding to an incoming SMS message, you have access to a variety of information about the message through the body of the webhook request that Twilio sends you.

    Here is all the code you need to grab data from an incoming SMS webhook request from the Twilio API and respond with another text message:

    const http = require('http');
    const express = require('express');
    const { urlencoded } = require('body-parser');
    const MessagingResponse = require('twilio').twiml.MessagingResponse;
    
    const app = express();
    app.use(urlencoded({ extended: false }));
    
    app.post('/sms', (req, res) => {
      const twiml = new MessagingResponse();
    
      // Access the message body and the number it was sent from.
      console.log(`Incoming message from ${req.body.From}: ${req.body.Body}`);
    
      twiml.message('The Robots are coming! Head for the hills!');
    
      res.writeHead(200, {'Content-Type': 'text/xml'});
      res.end(twiml.toString());
    });
    
    http.createServer(app).listen(3000, () => {
      console.log('Express server listening on port 3000');
    });
    

    Simply responding to ...

    Read More
  • By Sam Agnew
    How to Send Emails in JavaScript/Node.js with SendGrid Send Emails with Node

    So you're building a Node.js app and you need to programmatically send some emails. The Twilio SendGrid API for sending email is a great solution to this problem. If you have a SendGrid account and an API key set as an environment variable, here is all the code you need to send an email in JavaScript:

    const sgMail = require('@sendgrid/mail');
    sgMail.setApiKey(process.env.SENDGRID_API_KEY);
    const msg = {
      to: test@example.com',
      from: 'test@example.com',
      subject: 'Sending with SendGrid is Fun',
      text: 'and easy to do anywhere, even with Node.js',
      html: '<strong>and easy to do anywhere, even with Node.js</strong>',
    };
    sgMail.send(msg);
    

    Let's walk through how to get this running step by step.

    Development Environment Setup

    Make sure we have the right software installed that we'll need to use for the rest of this post. Throughout this post you will need ...

    Read More
  • By Sam Agnew
    How to Send Emails in Python with Sendgrid PythonEmails

    So you're building a Django or Flask app and you need to programmatically send some emails. The Twilio SendGrid API for sending email is a great solution to this problem. If you have a SendGrid account and an API key set as an environment variable, here is all the code you need to send an email in Python:

    import os
    from sendgrid import SendGridAPIClient
    from sendgrid.helpers.mail import Mail
    
    message = Mail(
        from_email='from_email@example.com',
        to_emails='to@example.com',
        subject='Sending with Twilio SendGrid is Fun',
        html_content='<strong>and easy to do anywhere, even with Python</strong>')
    
    sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
    response = sg.send(message)
    print(response.status_code, response.body, response.headers)
    

    Let's walk through how to get this running step by step.

    Development Environment Setup

    Make sure we have the right software installed that we'll need to use for the rest of this post. Throughout this post ...

    Read More
  • By Sam Agnew
    How to send WhatsApp Media Messages with Python PythonWhatsApp

    WhatsApp is a messaging service used by people all over the world. With Twilio's Messaging API you can programmatically send WhatsApp messages. Let's walk through how to use Python to send a media message over WhatsApp.

    Development Environment Setup

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

    Here is a good guide to follow in general if you are going to be doing more with Twilio and Python.

    Sign up for Twilio and activate the Sandbox

    Before you can send a WhatsApp message, you'll need to sign up for a Twilio account or sign into your existing account and activate the Twilio Sandbox for WhatsApp ...

    Read More
  • By Sam Agnew
    How to Send a WhatsApp Message with JavaScript and Node.js WhatsAppNode

    WhatsApp is a messaging service used by people all over the world. With Twilio's Messaging API you can programmatically send WhatsApp messages. Let's walk through how to use JavaScript to send a message over WhatsApp.

    Development Environment Setup

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

    Here is a good guide to follow in general if you are going to be doing more with Twilio and Node.js and have any more questions.

    Sign up for Twilio and activate the Sandbox

    Before you can send a WhatsApp message from your web language, you'll need to sign up for a Twilio account or ...

    Read More
  • By Sam Agnew
    Generating music with Python and Neural Networks using Magenta for TensorFlow MIDI Data

    Machine Learning is all the rage these days, and with open source frameworks like TensorFlow developers have access to a range of APIs for using machine learning in their projects. Magenta, a Python library built by the TensorFlow team, makes it easier to process music and image data in particular.

    Since I started learning how to code, one of the things that has always fascinated me was the concept of computers artificially creating music. I even published a paper talking about it in an undergrad research journal my freshman year of college.

    Let's walk through the basics of setting up Magenta and programmatically generating some simple melodies in MIDI file format.

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

    Read More
  • By Sam Agnew
    Working with JSON in Swift Swift JSON

    Often developers need to deal with data in various different formats and JSON, short for JavaScript Object Notation, is one of the most popular choices. This is the syntax that the JavaScript language uses to denote objects.

    For this post, we are going to use the following modified JSON data from NASA's Astronomy Picture of the Day API to cover some basic examples of scenarios where you'd need to parse JSON. You will need to be running Swift 4.0 or greater. The following JSON is the example that we are going to be working with:

    {
        "copyright": "Yin Hao",
        "date": "2018-10-30",
        "explanation": "Meteors have been shooting out from the constellation of Orion. This was expected, as October is the time of year for the Orionids Meteor Shower. Pictured here, over two dozen meteors were caught in successively added exposures last October over Wulan Hada volcano in Inner Mongolia, China. The ...
    Read More
  • By Sam Agnew
    Working with JSON in Python json

    Often developers need to deal with data in various different formats and JSON, short for JavaScript Object Notation, is one of the most popular formats used in web development. This is the syntax that the JavaScript language uses to denote objects.

    As a Python developer, you may notice that this looks eerily similar to a Python dictionary. There are several different solutions to working with JSON in Python, and more often than not this data is loaded into a dictionary.

    For this post, we are going to use the following modified JSON data from NASA's Astronomy Picture of the Day API. Navigate to where you want to run the example code, create a file called apod.json and add the following to it:

    {
        "copyright": "Yin Hao",
        "date": "2018-10-30",
        "explanation": "Meteors have been shooting out from the constellation of Orion. This was expected, as October is the time of year for ...
    Read More
  • By Sam Agnew
    Improving your pun game with Python, Rhymebrain and the Twilio API for WhatsApp Guitarmony

    Puns are awesome and one easy way to come up with puns is to combine two different words. This is called a portmanteau. Let’s build a WhatsApp bot that gives you portmanteaus for certain words that you message it, so you can come up with better puns on the fly!

    We’ll be using the Rhymebrain API for the portmanteaus and the Twilio API for WhatsApp to program our WhatsApp bot.

    Setting up

    To get started make sure you have:

    Like with Twilio Programmable SMS we’ll need a webhook that will respond to incoming HTTP requests with every message ...

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