-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
34 lines (30 loc) · 1.27 KB
/
app.js
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
var ApiBuilder = require('claudia-api-builder'), api = new ApiBuilder(),
twilio = require('twilio')('TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN');
module.exports = api;
api.post('/sms-updates', function(req) {
// This logic is just here to handle if a location was not included with your
// tracking number that you are requesting.
var body = req.body,
trackingStatus = body.tracking_status,
trackingLocation = 'UNKNOWN';
if (trackingStatus.location && trackingStatus.location.city) {
trackingLocation =
trackingStatus.location.city + ', ' + trackingStatus.location.state
}
return twilio
.sendMessage({
to: '+1-TEST_NUMBER', // This should be your destination number
from: '+1-TWILIO_NUMBER', // This is your Twilio number in your account
body: 'Tracking #: ' + body.tracking_number + '\nStatus: ' +
trackingStatus.status + '\nLocation: ' + trackingLocation
})
.then(function(
success) { // We are using a promise here to help Claudiajs
// make sure the request is executed, otherwise
// our function will exit before it executes
console.log(success);
})
.catch(function(error) {
console.log(error);
});
});