Last active
September 29, 2018 17:50
-
-
Save ishan-marikar/7ac09907828260b2efb1251f7e18d4ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const facebook = require("facebook-chat-api"); | |
const birthdayWishes = require("./birthday-wishes.json"); | |
const schedule = require("node-schedule"); | |
const fs = require("fs"); | |
function sendGreetings() { | |
facebook( | |
{ email: process.env.USERNAME, password: process.env.PASSWORD }, | |
(error, api) => { | |
if (error) throw error; | |
// fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState())); | |
api.getFriendsList((error, friends) => { | |
if (error) throw error; | |
let friendsWithBirthdays = friends.filter(friend => { | |
return friend.isBirthday === true && friend.userID !== "0"; | |
}); | |
console.log(friendsWithBirthdays); | |
friendsWithBirthdays.forEach(friend => { | |
api.sendMessage( | |
{ | |
body: birthdayWishes[0] | |
}, | |
friend.userID, | |
(error, messageInfo) => { | |
if (error) throw error; | |
console.log( | |
"Sent birthday greeting to", | |
friend.fullName, | |
messageInfo | |
); | |
} | |
); | |
}); | |
}); | |
} | |
); | |
} | |
let notifier = schedule.scheduleJob("0 10 * * *", sendGreetings); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!!!
Assuming
birthday-wishes.json
ismodules.export(['text'])
?