-
Notifications
You must be signed in to change notification settings - Fork 0
/
reply.js
42 lines (35 loc) · 1.06 KB
/
reply.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
37
38
39
40
41
42
'use strict';
const TwitterClient = require('twitter');
module.exports.reply = (event, context, callback) => {
const Twitter = new TwitterClient({
"consumer_key": process.env.CONSUMER_KEY,
"consumer_secret": process.env.CONSUMER_SECRET,
"access_token_key": process.env.TOKEN_KEY,
"access_token_secret": process.env.TOKEN_SECRET
});
const stream = Twitter.stream('user');
stream.on('follow', followed);
function followed(event) {
console.log('Follow Event is running');
const name = event.source.name;
const follower = event.source.screen_name;
tweetNow('Hey @' + follower + ' Who do you think inspires peace? \n\#PeaceDay \#PeaceHack');
}
function tweetNow(tweetTxt) {
const tweet = {
status: tweetTxt
}
Twitter.post('statuses/update', tweet, function (err, data, response) {
if (err) {
console.log("Error in Replying");
}
callback(null, {
statusCode: 200,
body: JSON.stringify({
tweet: tweet,
response: response
}),
});
});
}
}