Last active
August 20, 2023 22:27
-
-
Save khalidx/2cb91fe4a4e5c719bd438a2561c17aa5 to your computer and use it in GitHub Desktop.
Quickly send an SMS message using the Twilio API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// make sure you `npm install twilio` before you run | |
const config = { | |
// get your credentials from the twilio console: www.twilio.com/console | |
// can also be configured as environment variables instead | |
accountSid: '<twilio account sid>', | |
authToken: '<twilio auth token>', | |
// on a twilio trial account, you can only send from and to confirmed or purchased numbers | |
// upgrade your account to send to any number | |
from: '+10000000000', | |
to: '+10000000000', | |
// the message you want to send | |
body: 'Hey there!' | |
} | |
const client = require('twilio')(config.accountSid, config.authToken, { lazyLoading: true }) | |
const message = () => { | |
const { from, to, body } = config | |
return client.messages.create({ from, to, body }) | |
.then(message => console.log('sent', message.sid)) | |
.catch(error => console.error('error', error)) | |
} | |
// you could also easily send messages on an interval (p.s. don't, this is spam-like) | |
// setInterval(message, config.seconds * 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment