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

fca-aryan

v0.0.5

Published

Advanced Facebook Chat API (FCA) for Node.js - Automate Facebook Messenger with real-time messaging, AI theme generation, and comprehensive bot features

Readme


Overview

FCA-ARYAN is a powerful, modern Facebook Chat API client built for reliable, real-time, and modular interaction with Facebook Messenger. This project offers full control over Messenger automation through a clean, stable interface.


Installation

Requirements: Node.js v18.0.0 or higher

npm install fca-aryan

Or install the latest version:

npm install fca-aryan@latest

Features

| Feature | Description | |---------|-------------| | Secure Login | Dynamic form scraping with secure token authentication | | Real-time Messaging | Send/receive messages, attachments, stickers, replies | | Message Editing | Edit bot messages in-place | | Typing Indicators | Detect and send typing status | | Message Status | Mark as delivered, read, or seen | | Thread Management | Get thread details, history, lists, pin/unpin messages | | User Info | Access name, ID, profile picture, mutual context | | Sticker API | Search stickers, list packs, AI-generated stickers | | Post Interaction | Comment and reply to public posts | | AI Themes | Generate custom AI-powered chat themes | | Proxy Support | Full support for custom proxies | | Modular Design | Organized into pluggable modules | | Error Handling | Retry logic, logging, graceful failovers |


Security Warning

IMPORTANT: appstate.json contains your Facebook session credentials!

| Warning | Description | |---------|-------------| | Never commit | Do not add appstate.json to version control | | Never share | Keep your session file private | | Use .gitignore | Already configured in this project | | Environment-specific | Use separate credentials for production |


Quick Start

Step 1: Generate appstate.json

  1. Install a cookie export extension:

    • Chrome/Edge: C3C FbState or CookieEditor
    • Firefox: Cookie-Editor
  2. Log in to Facebook in your browser

  3. Export cookies and save as appstate.json:

[
  { "key": "c_user", "value": "your-user-id" },
  { "key": "xs", "value": "your-xs-value" }
]

Tutorial: Getting AppState Guide


Step 2: Create Your Bot

const fs = require("fs");
const path = require("path");
const { login } = require("fca-aryan");

let credentials;
try {
  credentials = { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) };
} catch (err) {
  console.error("appstate.json is missing or malformed.", err);
  process.exit(1);
}

console.log("Logging in...");

login(credentials, {
  online: true,
  updatePresence: true,
  selfListen: false,
  randomUserAgent: false
}, async (err, api) => {
  if (err) return console.error("LOGIN ERROR:", err);

  console.log(`Logged in as: ${api.getCurrentUserID()}`);

  const commandsDir = path.join(__dirname, "modules", "commands");
  const commands = new Map();

  if (!fs.existsSync(commandsDir)) fs.mkdirSync(commandsDir, { recursive: true });

  for (const file of fs.readdirSync(commandsDir).filter(f => f.endsWith(".js"))) {
    const command = require(path.join(commandsDir, file));
    if (command.name && typeof command.execute === "function") {
      commands.set(command.name, command);
      console.log(`Loaded command: ${command.name}`);
    }
  }

  api.listenMqtt(async (err, event) => {
    if (err || !event.body || event.type !== "message") return;

    const prefix = "/";
    if (!event.body.startsWith(prefix)) return;

    const args = event.body.slice(prefix.length).trim().split(/ +/);
    const commandName = args.shift().toLowerCase();

    const command = commands.get(commandName);
    if (!command) return;

    try {
      await command.execute({ api, event, args });
    } catch (error) {
      console.error(`Error executing ${commandName}:`, error);
      api.sendMessageMqtt("An error occurred.", event.threadID, event.messageID);
    }
  });
});

AI Features

AI Stickers

const aiStickers = await api.getAiStickers({ limit: 10 });
console.log(aiStickers);

AI Themes

const aiThemes = await api.createAITheme("vibrant purple pink ocean sunset");

if (aiThemes && aiThemes.length > 0) {
  console.log(`Generated theme ID: ${aiThemes[0].id}`);
  await api.setThreadThemeMqtt(threadID, aiThemes[0].id);
  console.log("AI theme applied!");
}

Standard Themes

const themes = await api.getTheme(threadID);
console.log(`Found ${themes.length} themes`);

await api.setThreadThemeMqtt(threadID, themes[0].id);

Check Current Theme

const currentTheme = await api.getThemeInfo(threadID);
console.log(`Thread: ${currentTheme.threadName}`);
console.log(`Color: ${currentTheme.color}`);
console.log(`Emoji: ${currentTheme.emoji}`);

API Reference

Core Methods

| Method | Description | |--------|-------------| | login(credentials, options, callback) | Login to Facebook | | api.getCurrentUserID() | Get current user ID | | api.getAppState() | Get session cookies | | api.listenMqtt(callback) | Listen for messages | | api.logout() | Logout from Facebook |

Messaging

| Method | Description | |--------|-------------| | api.sendMessage(msg, threadID) | Send a message | | api.sendMessageMqtt(msg, threadID) | Send via MQTT | | api.editMessage(text, messageID) | Edit a message | | api.unsendMessage(messageID) | Unsend a message | | api.setMessageReaction(reaction, messageID) | React to message |

Thread Management

| Method | Description | |--------|-------------| | api.getThreadInfo(threadID) | Get thread info | | api.getThreadList(limit, timestamp, tags) | List threads | | api.getThreadHistory(threadID, amount) | Get message history | | api.changeThreadColor(color, threadID) | Change thread color | | api.changeGroupImage(image, threadID) | Change group image |

User Management

| Method | Description | |--------|-------------| | api.getUserInfo(userID) | Get user info | | api.getFriendsList() | Get friends list | | api.addUserToGroup(userID, threadID) | Add user to group | | api.removeUserFromGroup(userID, threadID) | Remove from group |


Project Structure

fca-aryan/
├── index.js              # Main entry point
├── src/
│   ├── nix/              # API methods (70+ functions)
│   ├── storage/          # Session & cache management
│   ├── database/         # Database models
│   ├── engine/           # Login engine
│   ├── types/            # TypeScript definitions
│   └── utils/            # Utility functions
├── examples/             # Usage examples
└── README.md

Examples

Check the examples/ directory:

| File | Description | |------|-------------| | simple-bot.js | Basic bot setup | | test-bot.js | Full-featured test bot | | apply-ai-theme.js | AI theme generation | | theme-usage-example.js | Theme management |


Login Options

{
  online: true,           // Show online status
  selfListen: false,      // Listen to own messages
  listenEvents: true,     // Listen to events
  updatePresence: true,   // Update presence
  forceLogin: false,      // Force new login
  autoMarkDelivery: true, // Auto mark delivered
  autoMarkRead: false,    // Auto mark read
  listenTyping: false,    // Listen to typing
  proxy: null,            // Proxy URL
  autoReconnect: true,    // Auto reconnect
  randomUserAgent: false, // Random user agent
  bypassRegion: null      // Bypass region
}

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.


Credits

  • Aryan - Lead Developer
  • Aryan Team - Development & Maintenance

License

MIT License - Free to use, modify, and distribute.