-
Notifications
You must be signed in to change notification settings - Fork 0
/
twilio
36 lines (31 loc) · 951 Bytes
/
twilio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var http = require('http');
var twilioConfig = {
phone: '18557348525',
accountId: 'ACa5e50972f8cb80a4ed6b33fcd14d37eb',
secret: 'f66540840bd30a51c598e72b3f97b66f'
}
function Twilio() {
this.accountId = twilioConfig.accountId;
this.secret = twilioConfig.secret;
}
Twilio.prototype.send = function (message, number) {
console.log('send twilio message ' + JSON.stringify(message));
var post_data = {
To: number,
From: twilioConfig.phone,
Body: message
};
var options = {
url: 'https://api.twilio.com/2010-04-01/Accounts/ACa5e50972f8cb80a4ed6b33fcd14d37eb/Messages.json',
authCreds: [this.accountId, this.secret],
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
params: post_data
};
var response = http.request(options);
console.log('twilio response ' + JSON.stringify(response));
return response;
}
//new Twilio().send('hi', '12012130688')