Skip to content

Instantly share code, notes, and snippets.

@ishan-marikar
Last active September 29, 2018 17:50
Show Gist options
  • Save ishan-marikar/7ac09907828260b2efb1251f7e18d4ac to your computer and use it in GitHub Desktop.
Save ishan-marikar/7ac09907828260b2efb1251f7e18d4ac to your computer and use it in GitHub Desktop.
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);
@ishan-marikar
Copy link
Author

@bsodmike birthday-wishes.json would just be [ "text" ].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment