-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendSMS.js
More file actions
54 lines (45 loc) · 1.6 KB
/
sendSMS.js
File metadata and controls
54 lines (45 loc) · 1.6 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
const AWS = require("aws-sdk");
const sns = new AWS.SNS({ apiVersion: "2010-03-31" });
var params = {
Message: "Unknown user is alerting you" /* required */,
TopicArn: "arn:aws:sns:us-east-1:179183100440:TestGD"
};
exports.handler = (event, context, callback) => {
console.log(event);
console.log(event.body);
var serialNumber = event.serialNumber
var latitude = 40.7628380
var longitude = -73.9824649
if (event.body !== undefined) {
console.log("using body serialNumber")
var data = JSON.parse(event.body)
serialNumber = data.serialNumber
latitude = data.latitude
longitude = data.longitude
}
var uri = "https://www.google.com/maps/dir/?api=1&destination="+encodeURIComponent(latitude)
+"%2C"+encodeURIComponent(longitude)
console.log(serialNumber);
switch(serialNumber) {
case "G030JF057167EF4S":
params.Message = "Gary health condition is good and location: "+uri
params.TopicArn = "arn:aws:sns:us-east-1:179183100440:GaryTopic"
break;
case "G030JF056136X7W8":
params.Message = "Omkar health condition is good and location: "+uri;
params.TopicArn = "arn:aws:sns:us-east-1:179183100440:OmkarTopic"
break;
default:
}
sns.publish(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
callback(null, { statusCode: 500, body: JSON.stringify(err) });
}
else{
console.log(data); // successful response
callback(null, { statusCode: 200, body: JSON.stringify(params) });
}
});
};