Skip to content

Commit

Permalink
Resolved conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Sep 23, 2017
2 parents 6808610 + 1d83fea commit b27322b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions reply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 + '. Thanks for the follow \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
}),
});
});
}
}
2 changes: 2 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ provider:
functions:
tweet:
handler: tweet.tweet
reply:
handler: reply.reply

# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
Expand Down

0 comments on commit b27322b

Please sign in to comment.