A modified & improved Facebook Chat API — Fixed and maintained by @mahmudx7
mahmud-fca is a Facebook Chat API modified with bug fixes, stability improvements, and extra features for Facebook Messenger bots.
npm install mahmud-fcaOr install directly from GitHub:
npm install github:mahmudx7/mahmud-fcaconst login = require("mahmud-fca");
const fs = require("fs");
login({
appState: JSON.parse(fs.readFileSync("appstate.json", "utf8"))
}, (err, api) => {
if (err) return console.error(err);
api.listenMqtt((err, event) => {
if (err) return console.error(err);
if (event.type === "message") {
api.sendMessage("Echo: " + event.body, event.threadID);
}
});
});- ✅ Auto relogin — Automatically relogins when an error is detected
- ✅ Auto dismiss behavior — Detects and dismisses Facebook's automated behavior checkpoint
- ✅ Added
api.relogin()— Manually trigger relogin - ✅ Added
api.stopListenMqtt()— Stop listening to MQTT - ✅ Added
api.getRegion()— Get the server region - ✅ Fixed
api.follow()and other API functions - ✅ Replaced npmlog with normal
console.logto fix render log issues - ✅ Supports cookie string, cookie array, and JSON appstate
Send a message to a thread. Message types:
| Type | Field |
|---|---|
| Text | body |
| Sticker | sticker |
| File/Image | attachment (readable stream) |
| URL | url |
| Emoji | emoji + emojiSize |
Listen for messages and events. Enable events with:
api.setOptions({ listenEvents: true });Enable self-listen:
api.setOptions({ selfListen: true });Returns the current appstate (cookies). Save it to avoid logging in every time:
fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState()));Stops listening to MQTT.
Manually triggers a relogin.
Returns the current Facebook server region (e.g. PRN, LLA).
Pass options as the second argument to login():
login({ appState: [...] }, {
selfListen: false,
listenEvents: true,
autoMarkRead: true,
autoMarkDelivery: false,
userAgent: "Mozilla/5.0 ...",
online: true,
autoReconnect: true
}, callback);const fs = require("fs");
const login = require("mahmud-fca");
login({ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) }, (err, api) => {
if (err) return console.error(err);
fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState()));
});This API is not affiliated with or endorsed by Facebook. Misuse may result in account bans. Use responsibly.