npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mostakim-fca/v2

v2.2.3

Published

Unofficial Facebook Chat API for Node.js with Auto-Update System - Enhanced by : md mostakim Islam sagor

Readme

@mostakim-fca/v2

npm version npm downloads License: MIT GitHub

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/v2
yarn 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 URL

E2EE 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:

  1. 🔍 Checks npm registry for a newer version
  2. 📋 Shows recent changelog entries
  3. 📦 Runs npm install @mostakim-fca/v2@latest if update found
  4. 🔄 Restarts the bot to apply changes

Manual update:

npm install @mostakim-fca/v2@latest

Programmatic 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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/MyFeature
  3. Commit your changes: git commit -m 'Add MyFeature'
  4. Push to the branch: git push origin feature/MyFeature
  5. Open a Pull Request

📄 License

MIT License — See LICENSE for details.


👨‍💻 Author

md mostakim Islam sagor GitHub · Instagram · Facebook

🔗 Links