-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (25 loc) · 937 Bytes
/
index.js
File metadata and controls
27 lines (25 loc) · 937 Bytes
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
require("env2")(".env");
const debug = require("./lib/debug.js");
const send = require("./lib/send.js");
const parse = require('./lib/parse.js');
const http_request = require('./lib/http_request');
const bounce_list = ["nelson@gmail.com", "test@gmail.com"];
exports.handler = function handler (event, context, callback) {
debug(event);
if (event.ping || (event.email && bounce_list.indexOf(event.email) > -1)) {
return callback(null, event);
}
else if (event.email) {
send(event, function send_cb (error, data) { // send the email
const json = {...event, ...parse(data)};
http_request(json, function http_cb (_status, response) { // save to API
const merged = {...json, ...response};
return callback(error, merged);
});
});
}
else {
const json = {...event, ...parse(event)}; // parse sns event
return http_request(json, callback); // POST parsed data to Email App
}
}