Hardware Reference
In-Depth Information
Solution
There are a number of SMS services out there. This recipe uses Twilio because you can use
it for free, but you will need to
verify the number
to which you are texting. First, go to
Twilio's home page
and set up an account. Note your account SID and authorization token.
If you are using the free version, be sure to
verify your numbers
.
Next, install Trilio by using the following command:
bone#
npm install -g twilio
Finally, add the code in
Example 6-8
to a file named
twilio-test.js
and run it. Your text will
be sent.
Example 6-8. Sending SMS messages using Twilio (twilio-test.js)
#!/usr/bin/env node
// From: http://twilio.github.io/twilio-node/
// Twilio Credentials
var
accountSid
=
''
;
var
authToken
=
''
;
//require the Twilio module and create a REST client
var
client
=
require
(
'twilio'
)(
accountSid
,
authToken
);
client
.
messages
.
create
({
to
:
"812555121"
,
from
:
"+2605551212"
,
body
:
"This is a test"
,
},
function
(
err
,
message
) {
console
.
log
(
message
.
sid
);
});
// https://github.com/twilio/twilio-node/blob/master/LICENSE
// The MIT License (MIT)
// Copyright (c) 2010 Stephen Walters
// Copyright (c) 2012 Twilio Inc.
// Permission is hereby granted, free of charge, to any person obtaining
a copy of
// this software and associated documentation files (the "Software"), to
deal in
// the Software without restriction, including without limitation the