Since 2009, has enabled developers to seamlessly build SMS and Voice technology into their apps, handling everything from basic user notifications, connecting drivers and passengers in apps like Uber and Lyft, to conference calling and more. If you haven’t had a chance to incorporate Twilio’s services into your product yet, here’s your chance to start! We’re happy to team up with Twilio’s functionality to show you how to bring Voice + SMS into your product or company in only a couple of minutes with StdLib! Twilio Maybe you’ve used Twilio before, or maybe you haven’t but you’re extremely interested in playing with programmable telephony and bringing it to your team or company. With the past success of our “Build” articles (like ), we’re excited to share StdLib’s quickest article yet — we’re happy to introduce how you can build a Twilio Messaging Hub in only 7 Minutes with StdLib! Build a Slack Bot in 9 Minutes If you haven’t used StdLib before you’re in for a treat — . It’s effectively a package manager for APIs that’s built upon new “serverless” architecture, meaning you never have to worry about managing servers or allocating resources for scale. Write a function, deploy, and you’re ready to go! We also have a growing ecosystem of integrations contributed by other developers that are extremely easy to plug in to. StdLib is the fastest way to ship business value via code Once you’ve created your StdLib service in , you’ll get a file that shows you how to hack your Twilio + StdLib Messaging Hub to your own needs. Minute 4 README.md What You’ll Need Beforehand 1x Twilio Account 1x Command Line Terminal 7x Minutes (or 420x Seconds) Minute 1: Create Your Twilio Phone Number The first thing you’ll want to do to get your Stdlib + Twilio messaging hub operational is grab a new phone number for your Twilio Account. First, make sure you’re logged in to your Twilio Account at . https://www.twilio.com/login Log In to Twilio From here, you’ll be at your . If this is your first time with Twilio, you’ll see a screen that looks like this (below). On the left menu, hit the button with the circle and ellipsis “ ” inside: Twilio Console (…) You want to select “All Products and Services” on the grey bar on the left From here, a slider menu will pop out. You want to select under the heading: Phone Numbers Super Network Click “# Phone Numbers” To add your first phone number, hit “ ”: Get Started And then “ ”: Get Your First Twilio Phone Number You’ll see a popup suggesting a random number for your geolocation, in this case, 415 is San Francisco. Click “ ” to continue quickly. (You can buy other numbers later.) Choose this Number You’ll be greeted with a success message. Awesome! Minute 2: StdLib Account Setup In order to create a robust messaging hub, you’ll next need to set up your Account. You’ll use StdLib to host your Twilio Hub using infinitely scalable “serverless” architecture from a single, maintainable codebase, and to hook into other integrations on StdLib (for example, using to format images you receive via MMS or using to see income ranges for the zip code associated with an incoming phone number). Simply visit and click “Sign Up Free” to create your account. StdLib utils.image devin.income-predictor https://stdlib.com Click “Sign Up” to Create an Account Minute 3: Create a StdLib Workspace so to ensure there are no compatibility issues you’ll likely want to run it (though Node 6 and 7 will work for this example). You can install the latest version of Node from the . Once complete, open up your Terminal or Command Line and install the with the following: StdLib natively runs Node.js 8.0.0 (yes, the newest version) Official Node.js Website StdLib Command Line Tools $ npm install lib.cli -g This gives you access to the command for service management and execution. Next, create a directory for your StdLib services. lib stdlib $ mkdir stdlib$ cd stdlib$ lib init Log in using the credentials you created in the previous step. That’s it! Minute 4: StdLib Service Creation Next you’ll create your StdLib service from the command line. We’ve created a special template to allow you to ship a prototype of your own Twilio Hub in only a few seconds. twilio $ lib create -t twilio You’ll be asked to enter a , we recommend for the purposes of this tutorial. You’ll see some NPM packages being installed locally and your service directory being created: Service Name twilio-hub Once complete, you’ll be told to enter your service directory. Do so with the command: $ cd user/twilio-hub Where is, of course, your StdLib username. (In my case, it’s .) user keith From here, you can try running some SMS commands (these will be the responses for or sent to your Twilio number) with: “more” “whoami” $ lib .messaging.more And see the result: The SMS response to people who message your number with the text “more.” Or, alternatively, turn on debug mode with to see what’s going on behind the scenes: -d $ lib .messaging.whoami -d Since this isn’t actually being triggered by Twilio’s webhook, execution information (zipcode, city) reads as , so this is expected. undefined Minute 5: Configure Your StdLib Environment As a next step, we’ll want to make sure StdLib knows all of our Twilio Account details. To set this up properly, first open up in the StdLib service directory you just created, where, again, is your username. env.json user/twilio-hub/env.json user You can see three different environments: , and . These are intended for different execution contexts — when running locally, the environment variables in are used, you can deploy to a environment in the cloud, or a production environment. We generally recommend at least using a different phone number. local dev release local dev release Make sure, for the purposes of this tutorial, you fill in the **dev** and **local** variables with the same values. To fill in visit , log in, click on the left, then to reveal your token. Copy and paste it into your environment variables. "STDLIB_TOKEN" https://dashboard.stdlib.com/dashboard/ Library Tokens Show Token Click “Show Token” to reveal your token, then copy it. Next, , , and — these are all available from your Twilio Console at . Copy your directly, and click the eyeball beside your to reveal it and copy it as well. "TWILIO_ACCOUNT_SID" "TWILIO_AUTH_TOKEN" "TWILIO_NUMBER" https://www.twilio.com/console ACCOUNT SID AUTH TOKEN Copy your Account SID and your Twilio Auth Token into your Environment Variables To find your Twilio Phone Number you previously created, visit . Click on the red, highlighted number you created in . https://www.twilio.com/console/phone-numbers/incoming Minute 1 Click on the Red Text to Configure Your Number From the next screen, copy and paste the value in the format to your value. PHONE NUMBER +1234567890 "TWILIO_NUMBER" Copy the “PHONE NUMBER” value , the value can be filled in with . Use the format again (make sure it’s in quotes). Best bet is to use a personal phone number for demonstration purposes. Finally "CALL_FORWARD_NUMBER" any phone number of your choosing, it is the number that your Twilio Hub will automatically redirect incoming calls to +1234567890 Minute 6: Deploy and Configure Webhooks You’re almost done! The very last step is to deploy your StdLib Twilio Hub (with the appropriate environment variables set above) and then configure Twilio Webhooks to point to StdLib. To deploy your StdLib Twilio Hub in a environment, simply open up your command line in your service directory and type: dev $ lib up dev You’ll see the progress of your service deploying to a development environment, and be greeted with a list of available HTTP endpoints corresponding to everything in your directory. functions/ Now that your service is live, go back to the Twilio Manage Numbers dashboard and select your phone number again. Scroll down to first: https://www.twilio.com/console/phone-numbers/incoming Voice & Fax Enter in your “voice” endpoint to Voice & Fax On this form, beside , make sure is selected in the dropdown and use the value (where is of course, your username). Note that the hostname is our functions gateway, where all of your services and functions will be deployed to. A CALL COMES IN Webhook https://<user>.api.stdlib.com/twilio-hub@dev/voice/ <user> api.stdlib.com Next, scroll down to and enter in in the Webhook handler. Messaging https://<user>.api.stdlib.com/twilio-hub@dev/messaging/ A MESSAGE COMES IN Enter in your Messaging Handler details, and hit Save Finally, hit in the bottom left. Save Minute 7: Add Verified Phone Numbers If this is your first time signing up with Twilio, you’ll be using a trial account. Trial accounts have limitations on numbers they can send messages to or forward calls from. To make sure your Twilio Messaging Hub on StdLib works as you expect it, use the list to add any phone numbers that you want to forward calls or send messages to. verified phone numbers https://twilio.com/user/account/phone-numbers/verified By default, the phone number you registered your account with should already be listed here. That’s It! Your Twilio Messaging Hub on StdLib is live! You can now send SMS messages to your Twilio Number to receive an automated response and make calls to your number to have them forwarded. Otherwise, you’re good to go! If you’re using a Twilio trial account, make sure you’ve added verified numbers in Minute 7. A Twilio Bot Interaction using StdLib You can modify the behavior of your SMS Bot by visiting the directory in your StdLib service. The default responses are are to “whoami” and “more.” This messaging hub also handles MMS (media, picture) uploads. /functions/messaging/ Gotchas and Production Releases If at any point you lose track of your StdLib username or what your webhook callbacks should be, they’re listed when you deploy a service with . $ lib up dev If you’re not getting the expected responses when you play, Twilio has an amazing debugger at . https://www.twilio.com/console/dev-tools/debugger To ship a bot / messaging hub to production, we recommend using a different phone number. Configure your environment variables in to the appropriate settings, set your in to (or whatever you’d like, really), ship a release with and then you can use and as your voice and messaging endpoints for your production phone number. release env.json version package.json 1.0.0 $ lib release https://<user>.api.stdlib.com/twilio-hub@1.0.0/voice/ https://<user>.api.stdlib.com/twilio-hub@1.0.0/messaging/ Thank You! If you’d like to keep track of future StdLib updates and more Twilio fun, please follow us on Twitter at — or you can follow me, specifically at Thanks for reading! @StdLibHQ @keithwhor. At StdLib we’re focused on making the lives of software developers easier by getting them back to doing what they love best — writing code and building awesome products. If you’d like to help us on our mission, please reach out to careers@stdlib.com with a little bit about yourself!