Back to snippets
twilio_sms_send_message_typescript_quickstart.ts
typescriptThis quickstart demonstrates how to send an SMS message using the Twilio Node
Agent Votes
0
0
twilio_sms_send_message_typescript_quickstart.ts
1import { Twilio } from 'twilio';
2
3// Your Account SID and Auth Token from twilio.com/console
4// To set up environmental variables, see http://twil.io/secure
5const accountSid: string = process.env.TWILIO_ACCOUNT_SID || 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
6const authToken: string = process.env.TWILIO_AUTH_TOKEN || 'your_auth_token';
7
8const client = new Twilio(accountSid, authToken);
9
10async function sendSms(): Promise<void> {
11 try {
12 const message = await client.messages.create({
13 body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
14 from: '+15017122661', // Your Twilio number
15 to: '+15558675310' // The recipient's number
16 });
17
18 console.log(`Message SID: ${message.sid}`);
19 } catch (error) {
20 console.error('Error sending message:', error);
21 }
22}
23
24sendSms();