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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@xnil6x/fca-unofficial

v1.0.7

Published

A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.

Readme

20241210_183831

Disclaimer: We are not responsible if your account gets banned for spammy activities such as sending lots of messages to people you don't know, sending messages very quickly, sending spammy looking URLs, logging in and out very quickly... Be responsible Facebook citizens.

We the @dongdev/fca-unofficiala team/contributors are recommending you to use the Firefox app for less logout, or use this website if you have no access on these browsers specially iOS user.

If you encounter errors on fca, you can contact me here

</div>

Facebook now has an official API for chat bots here.

This API is the only way to automate chat functionalities on a user account. We do this by emulating the browser. This means doing the exact same GET/POST requests and tricking Facebook into thinking we're accessing the website normally. Because we're doing it this way, this API won't work with an auth token but requires the credentials of a Facebook account.

Install

If you just want to use @dongdev/fca-unofficial, you should use this command:

npm install @xnil6x/fca-unofficial

It will download @xnil6x/fca-unofficial from NPM repositories

Example Usage


const login = require("@xnil6x/fca-unofficial");

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);
    });
});

Result:

Main Functionality

Sending a message

api.sendMessage(message, threadID[, callback][, messageID])

Various types of message can be sent:

  • Regular: set field body to the desired message as a string.
  • Sticker: set a field sticker to the desired sticker ID.
  • File or image: Set field attachment to a readable stream or an array of readable streams.
  • URL: set a field url to the desired URL.
  • Emoji: set field emoji to the desired emoji as a string and set field emojiSize with size of the emoji (small, medium, large)

Note that a message can only be a regular message (which can be empty) and optionally one of the following: a sticker, an attachment or a url.

Tip: to find your own ID, you can look inside the cookies. The userID is under the name c_user.

Example (Basic Message)

const login = require("@xnil6x/fca-unofficial");

login({ appState: [] }, (err, api) => {
    if (err) {
        console.error("Login Error:", err);
        return;
    }

    let yourID = "000000000000000"; // Replace with actual Facebook ID
    let msg = "Hey!";
    
    api.sendMessage(msg, yourID, (err) => {
        if (err) console.error("Message Sending Error:", err);
        else console.log("Message sent successfully!");
    });
});

Example (File upload)

const login = require("@xnil6x/fca-unofficial");
const fs = require("fs"); // ✅ Required the fs module

login({ appState: [] }, (err, api) => {
    if (err) {
        console.error("Login Error:", err);
        return;
    }

    let yourID = "000000000000000"; // Replace with actual Facebook ID
    let imagePath = __dirname + "/image.jpg";

    // Check if the file exists before sending
    if (!fs.existsSync(imagePath)) {
        console.error("Error: Image file not found!");
        return;
    }

    let msg = {
        body: "Hey!",
        attachment: fs.createReadStream(imagePath)
    };

    api.sendMessage(msg, yourID, (err) => {
        if (err) console.error("Message Sending Error:", err);
        else console.log("Message sent successfully!");
    });
});

Saving session.

To avoid logging in every time you should save AppState (cookies etc.) to a file, then you can use it without having password in your scripts.

Example

const fs = require("fs");
const login = require("@xnil6x/fca-unofficial");

const credentials = { appState: [] };

login(credentials, (err, api) => {
    if (err) {
        console.error("Login Error:", err);
        return;
    }

    try {
        const appState = JSON.stringify(api.getAppState(), null, 2); // Pretty print for readability
        fs.writeFileSync("appstate.json", appState);
        console.log("✅ AppState saved successfully!");
    } catch (error) {
        console.error("Error saving AppState:", error);
    }
});

Alternative: Use c3c-fbstate to get fbstate.json (appstate.json)


Listening to a chat

api.listenMqtt(callback)

Listen watches for messages sent in a chat. By default this won't receive events (joining/leaving a chat, title change etc…) but it can be activated with api.setOptions({listenEvents: true}). This will by default ignore messages sent by the current account, you can enable listening to your own messages with api.setOptions({selfListen: true}).

Example

const fs = require("fs");
const login = require("@xnil6x/fca-unofficial");

// Simple echo bot: Repeats everything you say. Stops when you say "/stop".
login({ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) }, (err, api) => {
    if (err) {
        console.error("Login Error:", err);
        return;
    }

    api.setOptions({ listenEvents: true });

    const stopListening = api.listenMqtt((err, event) => {
        if (err) {
            console.error("Listen Error:", err);
            return;
        }

        // Mark message as read
        api.markAsRead(event.threadID, (err) => {
            if (err) console.error("Mark as read error:", err);
        });

        // Handle different event types
        switch (event.type) {
            case "message":
                if (event.body && event.body.trim().toLowerCase() === "/stop") {
                    api.sendMessage("Goodbye…", event.threadID);
                    stopListening();
                    return;
                }
                api.sendMessage(`TEST BOT: ${event.body}`, event.threadID);
                break;

            case "event":
                console.log("Event Received:", event);
                break;
        }
    });
});

<a name="projects-using-this-api"></a>

Projects using this API:

  • c3c - A bot that can be customizable using plugins. Support Facebook & Discord.
  • Miraiv2 - A simple Facebook Messenger Bot made by CatalizCS and SpermLord.

Projects using this API (original repository, facebook-chat-api):

  • Messer - Command-line messaging for Facebook Messenger
  • messen - Rapidly build Facebook Messenger apps in Node.js
  • Concierge - Concierge is a highly modular, easily extensible general purpose chat bot with a built in package manager
  • Marc Zuckerbot - Facebook chat bot
  • Marc Thuckerbot - Programmable lisp bot
  • MarkovsInequality - Extensible chat bot adding useful functions to Facebook Messenger
  • AllanBot - Extensive module that combines the facebook api with firebase to create numerous functions; no coding experience is required to implement this.
  • Larry Pudding Dog Bot - A facebook bot you can easily customize the response
  • fbash - Run commands on your computer's terminal over Facebook Messenger
  • Klink - This Chrome extension will 1-click share the link of your active tab over Facebook Messenger
  • Botyo - Modular bot designed for group chat rooms on Facebook
  • matrix-puppet-facebook - A facebook bridge for matrix
  • facebot - A facebook bridge for Slack.
  • Botium - The Selenium for Chatbots
  • Messenger-CLI - A command-line interface for sending and receiving messages through Facebook Messenger.
  • AssumeZero-Bot – A highly customizable Facebook Messenger bot for group chats.
  • Miscord - An easy-to-use Facebook bridge for Discord.
  • chat-bridge - A Messenger, Telegram and IRC chat bridge.
  • messenger-auto-reply - An auto-reply service for Messenger.
  • BotCore – A collection of tools for writing and managing Facebook Messenger bots.
  • mnotify – A command-line utility for sending alerts and notifications through Facebook Messenger.