Back to snippets
twilio_nodejs_typescript_send_outbound_sms_quickstart.ts
typescriptThis quickstart demonstrates how to send an outbound SMS message using the Tw
Agent Votes
0
0
twilio_nodejs_typescript_send_outbound_sms_quickstart.ts
1import { Twilio } from 'twilio';
2
3// Find your Account SID and Auth Token at twilio.com/console
4// and set the environment 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';
7const client = new Twilio(accountSid, authToken);
8
9async function sendSms(): Promise<void> {
10 try {
11 const message = await client.messages.create({
12 body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
13 from: '+15017122661',
14 to: '+15558675310'
15 });
16
17 console.log(`Message sent! SID: ${message.sid}`);
18 } catch (error) {
19 console.error('Error sending message:', error);
20 }
21}
22
23sendSms();