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

fca-mmtat

v1.0.0

Published

FCA-MMTAT - Facebook Chat API nâng cao cho Node.js | Tích hợp AI, Rate Limiting, Plugin System, Event Bus và nhiều tính năng mới

Readme

FCA-MMTAT

Facebook Chat API nâng cao cho Node.js — Được xây dựng dựa trên fca-unofficial với nhiều tính năng mới mạnh mẽ.

  ███████╗ ██████╗ █████╗       ███╗   ███╗███╗   ███╗████████╗ █████╗ ████████╗
  ██╔════╝██╔════╝██╔══██╗      ████╗ ████║████╗ ████║╚══██╔══╝██╔══██╗╚══██╔══╝
  █████╗  ██║     ███████║█████╗██╔████╔██║██╔████╔██║   ██║   ███████║   ██║
  ██╔══╝  ██║     ██╔══██║╚════╝██║╚██╔╝██║██║╚██╔╝██║   ██║   ██╔══██║   ██║
  ██║     ╚██████╗██║  ██║      ██║ ╚═╝ ██║██║ ╚═╝ ██║   ██║   ██║  ██║   ██║
  ╚═╝      ╚═════╝╚═╝  ╚═╝      ╚═╝     ╚═╝╚═╝     ╚═╝   ╚═╝   ╚═╝  ╚═╝   ╚═╝

✨ Tính năng mới so với fca-unofficial

| Tính năng | fca-unofficial | FCA-MMTAT | |---|---|---| | Rate Limiter tích hợp | ❌ | ✅ | | Cache user/thread info | ❌ | ✅ | | Plugin System động | ❌ | ✅ | | CommandRouter | ❌ | ✅ | | EventBus nội bộ | ❌ | ✅ | | AntiSpam | ❌ | ✅ | | Multi-Account Manager | ❌ | ✅ | | broadcastMessage | ❌ | ✅ | | sendMessageWithRetry | ❌ | ✅ | | Log levels + file log | ❌ | ✅ | | Banner đẹp | ❌ | ✅ | | getSystemStats() | ❌ | ✅ |


📦 Cài đặt

npm install fca-mmtat
# hoặc sao chép thư mục trực tiếp

Yêu cầu: Node.js >= 14.0.0


🚀 Bắt đầu nhanh

const fcaMMTAT = require("fca-mmtat");
const fs = require("fs");

const appState = JSON.parse(fs.readFileSync("appstate.json", "utf8"));

fcaMMTAT({ appState }, (err, api) => {
  if (err) return console.error(err);

  // Bắt đầu lắng nghe
  api.listen((err, event) => {
    if (err) return;
    if (event.type === "message" && event.body === "!ping") {
      api.sendMessage("🏓 Pong!", event.threadID);
    }
  });
});

⚙️ Cấu hình (fca-config.json)

Sao chép fca-config.example.json thành fca-config.json:

{
  "rateLimiter": {
    "enabled": true,
    "globalRps": 5,
    "globalRpm": 100,
    "minDelay": 300
  },
  "cache": {
    "enabled": true,
    "defaultTtl": 300000
  },
  "antiSpam": {
    "enabled": true,
    "maxMessages": 5,
    "windowMs": 5000,
    "timeoutMs": 30000
  },
  "logger": {
    "level": "info",
    "showBanner": true
  }
}

📚 API Mới

api.createCommandRouter(options)

Tạo bộ xử lý lệnh tự động với prefix, cooldown, phân quyền.

const router = api.createCommandRouter({
  prefix: "!",
  cooldown: 2000,
  adminUIDs: ["UID_ADMIN"],
});

router.command({
  name: "ping",
  description: "Kiểm tra bot",
  execute: async (event, args, api) => {
    api.sendMessage("Pong!", event.threadID);
  },
});

// Xây dựng text help tự động
router.buildHelpText("📋 Danh sách lệnh");

// Dùng trong listen
api.listen((err, event) => {
  router.handle(event, api);
});

api.broadcastMessage(message, threadIDs, options)

Gửi tin nhắn đến nhiều threads cùng lúc.

const result = await api.broadcastMessage(
  "Thông báo tới tất cả!",
  ["thread1", "thread2", "thread3"],
  {
    delay: 500,         // ms giữa các tin
    stopOnError: false, // tiếp tục khi lỗi
    onSuccess: (tid) => console.log("Gửi thành công:", tid),
    onError: (tid, err) => console.log("Lỗi:", tid, err),
  }
);
console.log(result.success, result.failed);

api.sendMessageWithRetry(message, threadID, options)

Gửi tin với tự động retry khi thất bại.

await api.sendMessageWithRetry("Tin quan trọng", threadID, {
  maxRetries: 3,
  retryDelay: 2000,
  backoff: 1.5, // tăng delay: 2s, 3s, 4.5s
  onRetry: (attempt, err, delay) => console.log(`Retry #${attempt} sau ${delay}ms`),
});

api.eventBus

Bus sự kiện nội bộ để giao tiếp giữa các module.

// Lắng nghe tất cả tin nhắn
api.eventBus.on("message", (eventName, event) => {
  console.log("Tin mới:", event.body);
});

// Chỉ một lần
api.eventBus.once("message:event", (name, event) => {
  // xử lý sự kiện group
});

// Phát sự kiện tùy chỉnh
api.eventBus.emit("my:custom:event", { data: "hello" });

api.cache

Cache thông tin để giảm request tới Facebook.

// Lưu vào cache
api.cache.set("user", "12345", userInfo, 600000); // TTL 10 phút

// Lấy từ cache
const info = api.cache.get("user", "12345");

// Lấy hoặc fetch nếu không có
const info = await api.cache.getOrFetch("thread", threadID, () =>
  api.getThreadInfo(threadID)
);

// Thống kê
console.log(api.cache.getStats());

api.rateLimiter

Kiểm soát tốc độ gửi tin (tự động được áp dụng vào sendMessage).

// Xem thống kê
console.log(api.rateLimiter.getStats());

// Thay đổi cấu hình runtime
api.rateLimiter.setGlobalRps(3);
api.rateLimiter.setMinDelay(500);
api.rateLimiter.setEnabled(false); // tắt tạm

api.antiSpam

Hệ thống chống spam người dùng gửi quá nhiều tin.

// Thêm whitelist (admin bypass spam check)
api.antiSpam.whitelist("ADMIN_UID");

// Kiểm tra thủ công
const { spam, remaining } = api.antiSpam.check(event.senderID);

// Bọc handler tự động
const safeHandler = api.antiSpam.wrap((event) => {
  // Chỉ chạy nếu không spam
  handleEvent(event);
}, { spamMessage: "⚠️ Gửi chậm thôi!" });

// Bỏ block thủ công
api.antiSpam.unblock("USER_UID");

api.plugins

Hệ thống plugin động.

// Load plugin từ file
await api.plugins.load("./plugins/my-plugin.js");

// Load plugin inline
await api.plugins.load({
  name: "MyPlugin",
  version: "1.0",
  async setup({ api, logger, addHook }) {
    addHook("message", async (event) => {
      // xử lý sự kiện
    });
    return {
      async cleanup() { /* dọn dẹp */ }
    };
  }
});

// Load cả thư mục
await api.plugins.loadDir("./plugins");

// Unload plugin
await api.plugins.unload("MyPlugin");

// Xem danh sách
console.log(api.plugins.list());

SessionManager — Multi-Account

Quản lý nhiều tài khoản Facebook cùng lúc.

const { SessionManager } = require("fca-mmtat");

const manager = new SessionManager({ strategy: "round-robin" });

await manager.add("bot1", { appState: appState1 });
await manager.add("bot2", { appState: appState2 });

// Lắng nghe tất cả
manager.listenAll((event, api, session) => {
  console.log(`[${session.id}]`, event.body);
});

// Gửi tin (tự động chọn account)
await manager.sendMessage("Hello!", threadID);

// Thống kê
console.log(manager.getStats());

api.getSystemStats()

Xem toàn bộ thống kê hệ thống.

const stats = api.getSystemStats();
console.log(stats);
// {
//   version: "1.0.0",
//   name: "FCA-MMTAT",
//   userID: "...",
//   region: "SIN",
//   cache: { hitRate: "85.0%", totalItems: 42 },
//   rateLimiter: { globalQueueLength: 0 },
//   antiSpam: { total: 10, blocked: 1 },
//   plugins: [...]
// }

🔌 Viết Plugin

// plugins/my-plugin.js
module.exports = {
  name: "MyPlugin",
  version: "1.0.0",
  description: "Plugin mẫu",

  async setup({ api, eventBus, logger, options, addHook }) {
    logger("Plugin đang khởi động", "info");

    // Đăng ký hook xử lý message
    addHook("message", async (event) => {
      if (event.body === "hello") {
        api.sendMessage("World!", event.threadID);
      }
    });

    // Lắng nghe EventBus
    eventBus.on("message", (name, event) => {
      // xử lý sự kiện
    });

    return {
      // Được gọi khi unload plugin
      async cleanup() {
        logger("Plugin đang dừng");
      }
    };
  }
};

📝 Tất cả API gốc vẫn hoạt động

Tất cả API từ fca-unofficial đều được giữ nguyên: sendMessage, getThreadInfo, getUserInfo, changeNickname, setTitle, addUserToGroup, removeUserFromGroup, changeAdminStatus, createNewGroup, deleteMessage, editMessage, forwardAttachment, markAsRead, createPoll, setMessageReaction, listenMqtt, và nhiều hơn nữa.


📄 License

MIT — Tự do sử dụng, chỉnh sửa và phân phối.


Được xây dựng bởi FCA-MMTAT Team — Dựa trên fca-unofficial của DongDev "# FCA-MTAT"