fca-surya-sahil
v1.0.1
Published
Advanced Facebook Chat API automation package for Node.js with enhanced features and reliability
Maintainers
Readme
🚀 fca-surya-sahil
Advanced Facebook Chat API for Node.js
🤔 What is fca-surya-sahil?
fca-surya-sahil is a powerful Node.js package for automating Facebook Messenger bots with advanced features and enhanced reliability.
Disclaimer: Use responsibly. We are not liable for account bans due to spammy activities, such as sending excessive messages, rapid logins/logouts, or sharing suspicious URLs. Be a responsible Facebook user.
📖 Table of Contents
✨ Features
- Automatic Re-login: Detects errors and automatically re-logs in using the cookie. If the cookie is logged out, it prompts for re-submission or refreshes automatically.
- Account Lock/Suspension Detection: Stops the login process and displays details if an account is locked or suspended.
- Token Refresh: Automatically refreshes
fb_dtsg(Facebook's dynamic token) daily at 12:00 AM (GMT+8 PH time). - Random User Agent: Experimental feature to reduce logouts (
setOptions). - Bypass Region: Choose regions like PRN, PNB, HKG, SYD, VLL, LLA, SIN (experimental).
- Optimized User Agent: For fewer account logouts.
- High Compatibility: Works seamlessly with various bot frameworks.
🚀 Installation
Install the latest version of fca-surya-sahil via npm:
npm install fca-surya-sahil🛠 Usage
Below is an example of creating a simple echo bot that repeats messages sent to it:
const api = require("fca-surya-sahil");
api.login('Provide your cookie here',
{ /* setOptions here */ },
(err, api) => {
if (err) return console.error(err);
api.listenMqtt((err, event) => {
if (err) return console.error(err);
api.sendMessage(event.body, event.threadID);
});
}
);💡 Fun fact: You can also use header string based cookie.
🔧 Main Functionality
Sending Messages
api.sendMessage(message, threadID[, callback][, messageID])
Send various types of messages:
- Regular: Use
bodyfor text messages. - Sticker: Set
stickerto a sticker ID. - File/Image: Set
attachmentto a readable stream or array of streams. - URL: Set
urlto a link. - Emoji: Set
emojito an emoji string andemojiSize(small,medium,large).
Note: A message can include a body (optional) and one of: sticker, attachment, or URL. Find your userID in cookies under c_user.
Example (Basic Message):
const api = require("fca-surya-sahil");
api.login('Provide your cookie here', (err, api) => {
if (err) return console.error(err);
const yourID = "000000000000000";
const msg = "Hey!";
api.sendMessage(msg, yourID);
});Example (File Upload):
const fs = require("fs");
const api = require("fca-surya-sahil");
api.login('Provide your cookie here', (err, api) => {
if (err) return console.error(err);
const yourID = "000000000000000";
const msg = {
body: "Hey!",
attachment: fs.createReadStream(__dirname + "/image.jpg"),
};
api.sendMessage(msg, yourID);
});Saving Sessions
Save the cookie to avoid re-entering credentials:
const fs = require("fs");
const api = require("fca-surya-sahil");
const cookie = 'Provide your cookie here';
api.login(cookie, (err, api) => {
if (err) return console.error(err);
fs.writeFileSync("cookie.txt", cookie, "utf-8");
});Listening to Chats
api.listenMqtt(callback)
Listens for incoming messages. Enable events (e.g., join/leave, title changes) with api.setOptions({ listenEvents: true }). To include your own messages, use api.setOptions({ selfListen: true }).
Example (Echo Bot with Stop Command):
const fs = require("fs");
const api = require("fca-surya-sahil");
api.login(fs.readFileSync("cookie.txt", "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, (err) => {
if (err) console.error(err);
});
switch (event.type) {
case "message":
if (event.body === "/stop") {
api.sendMessage("Goodbye…", event.threadID);
return stopListening();
}
api.sendMessage("TEST BOT: " + event.body, event.threadID);
break;
case "event":
console.log(event);
break;
}
});
});❓ FAQ
Q: How do I handle Promise rejection errors?
Add this code to your index.js to log unhandled rejections:
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
});Q: How do I get a cookie?
Use a cookie editor extension on browsers like Firefox, Kiwi, Edge, or Chrome to extract your Facebook cookie.
Q: What if I encounter errors?
Check the documentation or reach out for support.
📝 License
This project is licensed under the MIT License. See the LICENSE file for details.
Made with ❤️ by Surya Sahil
