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

"javascript" posts

  • By Nathaniel Okenwa
    Create a Smart Voicemail with Twilio, JavaScript and Google Calendar 6RDc-eMExBn8vtkgQRwJxsbID95IbJXkGqac1ZoC8vMmh40ejzYE0H0RD1yoyU64-7sQHZwNABCgxkmymMgmiXigQvcqs5B4nelE6RkAneOPJ-DfU30ClMG24vUDqrHnZZH3jKQ1

    We’ve all been there, in an important meeting, you’ve forgotten to mute your phone and all eyes turn to you as you frantically search through your pockets to silence it. That feeling of embarrassment is only matched by the frustration of listening to your voicemail. I dread hearing the robotic voice telling me what numbers to press only to be presented with the sound of somebody hanging up the call.

    To take the hassle out of handling missed calls, today we are going to look at how to create a virtual office manager that is aware of your busy schedule, to handle calls and voice messages for you.

    What We Need

    • A Twilio Account (Get one here for Free)
    • A Twilio Phone Number
    • A Google Calendar
    • Google Calendar API Key

    Before We Begin

    To start off, we need to create a Google Project and enable the Google Calendar …

    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} …
    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Understanding Callbacks Asynchronous JavaScript: Understanding Callbacks

    By design, JavaScript is a synchronous scripting language. In fact, many of the widely used asynchronous functions in JavaScript are not part of the core language. Understanding how asynchronous features work in the JavaScript ecosystem, including the role played by external APIs, is an essential part of using the language effectively.

    This post will show you how to use asynchronous functionality in JavaScript. It’s also going to explain an important difference between the way code execution works in JavaScript and other languages and frameworks. Understanding this difference is essential to understanding how to do asynchronous programming with JavaScript.

    Understanding JavaScript asynchronous code

    JavaScript programs rely on a JavaScript runtime environment for execution. Browsers, like Chrome and Firefox, and application servers, like Node.js, include a runtime environment as part of the application. This enables websites to run JavaScript in client browsers and standalone JavaScript applications to run in Node.js.

    While Chrome …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Organizing Callbacks for Readability and Reusability cxgwWEzJkPC0ZPM2fWcHu3BrGZXaMUO2Z0tUwOu9UTctbND9UrJpqwisJe7EOp9UZlf6sUZhhnH80lvOQadVfLyAfaswgFqm0BB9rs6FD9beeFkQYLMHSwNBo1kNwgkMMrBcHX4l

    Asynchronous programming is an essential part of being a complete JavaScript programmer. Understanding the code execution flow in JavaScript is the foundation of understanding how it can handle asynchronous tasks. And being able to program asynchronous tasks enables you to take advantage of the extensive array of functions provided by JavaScript runtime engines and external APIs. With those tools you can connect your JavaScript programs with web APIs across the internet and effectively manage those—sometimes tenuous—connections.

    With power comes complexity. Using JavaScript callbacks to implement asynchronous functionality can quickly create a series of deeply nested function calls. This post will show you how to write and organize your JavaScript callbacks to maximize the readability, maintainability, and reusability of your asynchronous functions.

    As an old programming saying goes:

    Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

    The first part of this …

    Read More
  • By AJ Saulsberry
    JavaScript Deep Dive: Building Scalable and Secure Microservices with Node.js A3hJWCs53xJOPBLkV9uN1QhaMsozG5ArjvE8QRGXj4wd_RQaLd_CpiIJGPbUZPD4ZqiNEuI533eiSqY8xMhWG5NIwRYw7mIsYJj7kdyNUA2u4GDISuFIexd65OKq0Cv0t5ROY2aS

    Many of the posts here on the Twilio blog provide just-in-time learning to help you accomplish a specific software development task, like integrating Twilio Verify into ASP.NET Core Identity. These posts give you the information to get a task done quickly.

    We also publish other posts that, taken collectively, help you make architectural decisions and build whole systems of software, not just individual modules. These related posts can rightfully be considered “long reads”. You’ll want to set aside time to get the most out of reading the posts and building their case study projects.

    We’re introducing Deep Dive posts to make it easier for you to access these professional development resources. Sometimes a Deep Dive will be a series of posts by a single author. On other occasions we’ll curate a list of posts from a variety of internal and external sources. On every occasion they’ll provide an extensive …

    Read More
  • By Phil Nash
    An introduction to the MediaRecorder API Copy of Photo blog Header 1-2.png

    On the web we can capture media streams from the user's camera, microphone and even desktop. We can use those media streams for real time video chat over WebRTC and with the MediaRecorder API we can also record and save audio or video from our users directly in a web browser.

    To explore the MediaRecorder API let's build a simple audio recorder app with just HTML, CSS and JavaScript.

    Getting started

    To build this application all we need is a text editor and a browser that supports the MediaRecorded API. At the time of writing, supported browsers include Firefox, Chrome and Opera. There is also work ongoing to bring this API to Edge and Safari.

    To get started, create a folder to work in and save this HTML file and this CSS file to give us something to start with. Make sure they are in the same folder …

    Read More
  • By Maciej Treder
    Protecting JavaScript Microservices on Node.js with JSON Web Tokens and Twilio Authy Copy of Product Template - Authy.png

    Building a JavaScript application on Node.js with a microservices architecture gives you the ability to scale your app: you can respond to varying load levels by adding and removing instances of a service. When multiple instances of a service access the same data, your application can use a common persistence layer, a database, to share information between instances and maintain consistency between them.

    In many applications you'll also want to limit access to some data and functions to particular users. While you could do this directly in your service APIs, there's a better way.

    This post will show you how to add two-factor authentication (2FA) with Twilio Authy and an authorization web service using JSON Web Tokens (JWTs), a standard for securely storing and transmitting sensitive data.

    Authentication with Twilio Authy

    Twilio Authy uses push authentications to verify a user's identity. Push authentications are better than passwords because they require …

    Read More
  • By Dominik Kundel
    When Not to Use Lock Files with Node.js Decorative header image "When Not to Use Lock Files with Node.js"

    Probably one of the most common situations that you encounter when debugging a problem is the "works on my machine" scenario. This is often the result of different underlying dependencies on the system of the person with the bug and your own system. As a result both yarn and npm introduced so called "lock files" at one point that keep track of the exact versions of your dependencies. However, when you are developing a package that will be published to npm, you should avoid using such lock files. In this blog post we'll discuss why this is the case.

    Quick Summary (tl;dr)

    Lock files are super useful if you build an application like a web server. However, if you publish a library or CLI to npm, lock files are never published. Meaning your users and you might use different versions of dependencies if you use lock files. 

    What's a …

    Read More
  • By Stefan Judis
    How to control and record voice calls with Node.js serverless functions Graphic showing Twilio call flow with serverless functions

    There are many ways to communicate with your friends and family. You might use good old SMS, Whatsapp, emails and of course phone calls. Recently, I came across a surprising new way of communication. It all started with my friend Michaela asking a question on Twitter.

    Would it be possible to generate an RSS feed out of Twilio voice calls?

    What she was looking for was a way to transform phone calls into an RSS feed referencing the recorded phone call. Why? Because she listens to many podcasts and sends very long voice messages to one of her friends via Whatsapp. As these messages usually don’t need a timely response, they both would prefer all the voice messages appear in their podcatchers rather than Whatsapp.

    Let me introduce you to the idea of “PodBot - the surprise podcast from your friends”.

    Podbot preview in a browser window

    The idea is a follows: All you have …

    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');
    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>',

    Let's walk through how to get this running step …

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