-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbot.js
More file actions
33 lines (27 loc) · 1.07 KB
/
bot.js
File metadata and controls
33 lines (27 loc) · 1.07 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
console.log('The bot is starting ');
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
var seconds = 10 // Seconds waiting for DM
// Settig up a user stream
var stream = T.stream('user');
// Anytime Someone follows me
stream.on('follow', onFollowed);
/**
* Function onFollowed will be triggered when someone follows me
*
* @param { Object } eventTwit - Event that contains twitter values
* @param { String } eventTwit.source.screen_name - User's screen name
*/
function onFollowed(eventTwit) {
console.log('Follow event!');
var screenName = eventTwit.source.screen_name;
// the post request for direct messages > need to add a function to handle errors
setTimeout(function() { // wait 60 sec before sending direct message.
console.log("Direct Message sent");
T.post("direct_messages/new", {
screen_name: screenName,
text: 'Thanks for following' + ' ' + screenName + '! ' + ' What you want to be sent to a new follower '
});
}, 1000 * seconds); // will respond via direct message after a user follows.
};