-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tweet.js
36 lines (25 loc) · 805 Bytes
/
tweet.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
35
36
require('dotenv').config();
const jwt = require('jsonwebtoken');
const { parsePayloadContent, validateRequest, handleSuccess, handleError } = require('../lib/request');
const { buildTweet, tweet } = require('../lib/twitter');
/**
* handler
* @description Lambda handler
*/
function handler({ headers, body}, context, callback) {
try {
validateRequest(process, headers);
} catch(e) {
handleError(callback, e);
}
const content = parsePayloadContent(body);
let options = {};
options.config = jwt.verify(headers.authorization, process.env.APP_SECRET);
options = Object.assign({}, options, {
...buildTweet(content)
})
tweet(options).then(response => {
handleSuccess(callback, 'Ok');
}).catch(error => handleError(callback, error));
}
exports.handler = handler;