@mostakim-fca/v2
v2.2.3
Published
Unofficial Facebook Chat API for Node.js with Auto-Update System - Enhanced by : md mostakim Islam sagor
Maintainers
Keywords
Readme
@mostakim-fca/v2
Unofficial Facebook Chat API for Node.js Interact with Facebook Messenger programmatically — Enhanced & Maintained by md mostakim Islam sagor
🔐 Includes End-to-End Encryption (E2EE) Support
🌟 Features
- ✨ Enhanced MQTT connection with colorful ASCII art banner (figlet)
- 🔄 Auto-reconnect with configurable intervals
- 📊 Real-time connection status display (region, reconnect state)
- 🔐 End-to-End Encryption (E2EE) — full encrypted messaging support
- 🚀 Automatic update checking & installation on startup
- 💡 Improved error handling and debugging
- 🎨 Colorful ANSI terminal output
📦 Installation
npm install @mostakim-fca/v2yarn add @mostakim-fca/v2🚀 Basic Usage
1. Login & Simple Echo Bot
const login = require("@mostakim-fca/v2");
login({ appState: [] }, (err, api) => {
if (err) return console.error(err);
api.listenMqtt((err, event) => {
if (err) return console.error(err);
api.sendMessage(event.body, event.threadID);
});
});2. Send a Text Message
const login = require("@mostakim-fca/v2");
login({ appState: [] }, (err, api) => {
if (err) return console.error("Login Error:", err);
const threadID = "000000000000000"; // Replace with actual Facebook ID
api.sendMessage("Hey!", threadID, err => {
if (err) console.error("Send Error:", err);
else console.log("Message sent!");
});
});Tip: Find your Facebook ID from cookies under the name
c_user.
3. Send File / Image
const fs = require("fs");
const login = require("@mostakim-fca/v2");
login({ appState: [] }, (err, api) => {
if (err) return console.error("Login Error:", err);
const msg = {
body: "Here's an image!",
attachment: fs.createReadStream(__dirname + "/image.jpg")
};
api.sendMessage(msg, "000000000000000", err => {
if (err) console.error("Send Error:", err);
});
});💾 AppState (Session Management)
Save AppState
const fs = require("fs");
const login = require("@mostakim-fca/v2");
login({ appState: [] }, (err, api) => {
if (err) return console.error(err);
fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState(), null, 2));
console.log("✅ AppState saved!");
});Use Saved AppState
const fs = require("fs");
const login = require("@mostakim-fca/v2");
login(
{ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
(err, api) => {
if (err) return console.error(err);
console.log("✅ Logged in!");
// Your bot code here
}
);👂 Listening for Messages
Echo Bot with Stop Command
const fs = require("fs");
const login = require("@mostakim-fca/v2");
login(
{ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
(err, api) => {
if (err) return console.error(err);
api.setOptions({ listenEvents: true });
const stopListening = api.listenMqtt((err, event) => {
if (err) return console.error(err);
api.markAsRead(event.threadID, () => {});
switch (event.type) {
case "message":
if (event.body?.toLowerCase() === "/stop") {
api.sendMessage("Goodbye!", event.threadID);
stopListening();
return;
}
api.sendMessage(`Echo: ${event.body}`, event.threadID);
break;
case "event":
console.log("Event:", event);
break;
}
});
}
);Listen Options
api.setOptions({
listenEvents: true, // Receive join/leave/rename events
selfListen: true, // Receive own messages
logLevel: "silent" // silent | error | warn | info | verbose
});📝 Message Types
| Type | Usage |
|------|-------|
| Text | { body: "message" } |
| Sticker | { sticker: "sticker_id" } |
| File / Image | { attachment: fs.createReadStream(path) } or array of streams |
| URL | { url: "https://example.com" } |
| Large Emoji | { emoji: "👍", emojiSize: "large" } (small / medium / large) |
A message can be regular text plus one of: sticker, attachment, or URL — not multiple at once.
🔐 End-to-End Encryption (E2EE)
@mostakim-fca/v2 includes full E2EE support — messages encrypted on sender's device, decrypted only on recipient's.
E2EE Features
| Feature | Status | |---------|--------| | Encrypted messages | ✅ | | Encrypted attachments | ✅ | | Message reactions | ✅ | | Message editing | ✅ | | Typing indicators | ✅ | | Device key persistence | ✅ | | Auto-routing E2EE ↔ standard | ✅ |
E2EE Quick Start
const fs = require("fs");
const login = require("@mostakim-fca/v2");
login(
{ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
{ enableE2EE: true, listenEvents: true, autoMarkRead: true },
(err, api) => {
if (err) return console.error(err);
api.connectE2EE(err => {
if (err) return console.error("E2EE failed:", err);
console.log("✓ E2EE connected!");
});
api.listenMqtt((err, event) => {
if (err) return console.error(err);
if (event.type === "e2ee_message") {
console.log("🔐 Encrypted message:", event.body);
api.sendMessage("Received!", event.threadID);
}
});
}
);E2EE Event Types
// Encrypted message
{ type: "e2ee_message", body: "...", threadID: "...", isE2EE: true }
// Encrypted reaction
{ type: "e2ee_message_reaction", reaction: "❤️", messageID: "...", isE2EE: true }
// Encrypted edit
{ type: "e2ee_message_edit", body: "...", messageID: "...", isE2EE: true }E2EE API Methods
api.connectE2EE(callback); // Connect E2EE bridge
api.getE2EEDeviceData(callback); // Get device keys
api.sendMessage(msg, e2eeThreadID, callback); // Send encrypted message
api.setMessageReaction(emoji, messageID, cb); // React to encrypted message
api.editMessage(msg, messageID, callback); // Edit encrypted message
api.unsendMessage(messageID, callback); // Unsend encrypted message
api.sendTypingE2EE(threadID, callback); // Typing indicator (E2EE)
api.downloadE2EEMedia(messageID, callback); // Download encrypted media
api.resolveE2EEAttachment(attachment); // Resolve encrypted attachment URLE2EE Connection Flow
E2EE Message Listening
E2EE Configuration
// In login options
{
enableE2EE: true,
e2eeMemoryOnly: false,
enableTypingIndicator: true,
typingDuration: 4000,
autoReconnect: true,
listenEvents: true
}🎯 Quick API Reference
api.sendMessage(message, threadID, callback); // Send message
api.sendTypingIndicator(threadID, callback); // Typing indicator
api.markAsRead(threadID, callback); // Mark as read
api.getUserInfo(userID, callback); // Get user info
api.getThreadInfo(threadID, callback); // Get thread info
api.getThreadList(limit, timestamp, tags, callback); // Get thread list
api.changeThreadColor(color, threadID, callback); // Change thread color
api.changeThreadEmoji(emoji, threadID, callback); // Change thread emoji
api.changeNickname(name, threadID, userID, callback); // Change nickname
api.setMessageReaction(reaction, messageID, callback); // React to message
api.unsendMessage(messageID, callback); // Unsend message
api.deleteMessage(messageIDs, callback); // Delete messages
api.addUserToGroup(userID, threadID, callback); // Add to group
api.removeUserFromGroup(userID, threadID, callback); // Remove from group
api.changeAdminStatus(threadID, userID, admin, cb); // Set admin status
api.createPoll(title, options, threadID, callback); // Create poll
api.getAppState(); // Get current session
api.getCurrentUserID(); // Get bot's user ID🔄 Auto-Update System
On every startup, @mostakim-fca/v2 automatically:
- 🔍 Checks npm registry for a newer version
- 📋 Shows recent changelog entries
- 📦 Runs
npm install @mostakim-fca/v2@latestif update found - 🔄 Restarts the bot to apply changes
Manual update:
npm install @mostakim-fca/v2@latestProgrammatic check:
const { checkForFCAUpdate } = require("@mostakim-fca/v2/checkUpdate.js");
await checkForFCAUpdate();Updates are non-blocking — a failed update check will never crash your bot.
⚠️ Disclaimer
This is an unofficial API and is not supported by Facebook/Meta. Use responsibly:
- Do not send mass messages to people you don't know
- Do not send messages at an abnormally high rate
- Do not spam URLs or automated content
- Comply with Facebook Terms of Service
We are not responsible for any account restrictions or bans resulting from misuse.
🤝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/MyFeature - Commit your changes:
git commit -m 'Add MyFeature' - Push to the branch:
git push origin feature/MyFeature - Open a Pull Request
📄 License
MIT License — See LICENSE for details.
👨💻 Author
md mostakim Islam sagor GitHub · Instagram · Facebook
