Discover how to use Typescript and Deno to build a CLI.

Twilio Programmable SMS includes an HTTP REST API that makes it easy to interact with the SMS API. Once an SMS message request is created with the REST API, its status can be retrieved using another endpoint. By incorporating that REST API you can build a Deno CLI application that sends the message and reports on its delivery.

Deno is a new runtime environment for JavaScript that provides the capabilities of Node.js without the heavyweight package deployment and complex package management required for Node.js applications.

Deno provides new features to support the wide range of contemporary server-side applications being developed with JavaScript, a range that wasn’t envisioned when Node.js was developed.

Deno includes native support for TypeScript; no additional components are required. An application written with Deno can also be launched “remotely” - the user can execute the script specified by the URI pointing to a file hosted on the web. Deno will automatically download the script and other required dependencies to run the program.

Thanks to Deno modularity, you can build a program that utilizes existing code to create an SMS message request and monitor its status. Like other programming languages, Deno supports command line arguments, so you can create a CLI program to achieve anything you want.

Important compliance note: There are rules for using SMS messaging and they vary between countries. Familiarize yourself with the countries’ rules in which you’ll be sending messages with the Twilio Regulatory Guidelines for SMS.

Understanding the tutorial project

This tutorial will show you how to create a CLI program using Deno. To demo Deno features, you’ll be writing a CLI program that sends an SMS message to a phone number and reports the message delivery status. Unlike the Twilio CLI, this program will report the message delivery status without the need to execute another command. You’ll use the TwilioSMSHelper, which utilizes Twilio Programmable SMS to send the messages with Twilio’s REST API.

You’ll learn how to read command line arguments in Deno using the yargs library. You’ll find out how to register the arguments alias shortcuts (–argument, -a). You’ll also learn how to fallback to environment variables if the user doesn’t provide some of the arguments - for this purpose you will use lodash. You will also learn how to utilize the difference() method from lodash to compare two object keys and verify that the provided input doesn’t miss any values.

#typescript #deno #javascript

How to Use TypeScript and Deno to Build a CLI
3.80 GEEK