Skip to content

Instantly share code, notes, and snippets.

@gartnera
Created May 18, 2017 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gartnera/913e3bda0acf68d2f0df7f942cbcac84 to your computer and use it in GitHub Desktop.
Save gartnera/913e3bda0acf68d2f0df7f942cbcac84 to your computer and use it in GitHub Desktop.
Delete garbage posts from a facebook messenger conversation
const fs = require("fs");
const login = require("facebook-chat-api");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.setOptions({selfListen: true});
api.listen((err, event) => {
if(err) return console.error(err);
console.log(event);
//only match group chat
if (event.type == "message" && event.threadID == '1072921849467619') {
let a = event.attachments;
if(a.length > 0 ) {
if (a[0].type == "animated_image") {
api.deleteMessage(event.messageID);
}
}
}
if (event.type == "share" && event.threadID == '1072921849467619') {
//if from luke
if (event.senderID == '100000179506731')
api.deleteMessage(event.messageID);
}
});
});
const fs = require("fs");
const login = require("facebook-chat-api");
const readline = require("readline-sync");
var email = readline.question("Enter your email: ");
var password = readline.question("Enter your password: ", {hideEchoBack: true});
var credentials = {email: email, password: password};
login(credentials, (err, api) => {
if(err) return console.error(err);
fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment