This is an example project showing how to send an SMS message with the Twilio Programmable Messaging API and TypeScript.
You can read about how to send an SMS with TypeScript using Twilio on the Twilio blog.
Clone the repo and change into the send-sms
directory:
git clone https://github.com/philnash/twilio-typescript-examples.git
cd twilio-typescript-examples/send-sms
Install the dependencies:
npm install
Copy the .env.example
file to .env
:
cp .env.example .env
Fill in the variables with details from your Twilio account, or your own phone number.
Variable | Details |
---|---|
TWILIO_ACCOUNT_SID | Your Account SID, available on your Twilio Console |
TWILIO_AUTH_TOKEN | Your Auth Token, available on your Twilio Console |
TWILIO_PHONE_NUMBER | A Twilio phone number that can send SMS messages |
MY_NUMBER | Your own phone number, in e.164 format, so that you can receive the SMS that is sent |
Compile the index.ts
file:
npm run build
Note that this runs the TypeScript compiler, tsc
, you could also run npx tsc
to get the same output.
The TypeScript will be compiled into a JavaScript file in dist/index.js
.
Now send the message with:
npm run send
You should receive the message on your phone 🎉