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

prince-convo

v1.0.0

Published

A node.js package for automating Facebook Messenger bot, and is one of the most advanced next-generation Facebook Chat API by Prince Malhotra

Readme

🚀 prince-convo version 2 is here!

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.

🤔 What is the purpose of this package?

prince-convo is a Node.js package for automating Facebook Messenger bot. Developed by Prince Malhotra.

📖 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.
    Lock Detection
    Suspension Info
    Error Details
  • 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: Contributed by jonellcc for fewer account logouts.
  • Compatibility: Tested with Mirai and autobot.

🚀 Installation

Install the latest version of prince-convo via npm:

npm install prince-convo@latest

🛠 Usage

Below is an example of creating a simple echo bot that repeats messages sent to it:

const wiegine = require("prince-convo");

wiegine.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.

🤔 How to get it? Head over to FAQ section below.

Result:
Echo Bot Example

🔧 Main Functionality

Sending Messages

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

Send various types of messages:

  • Regular: Use body for text messages.
  • Sticker: Set sticker to a sticker ID.
  • File/Image: Set attachment to a readable stream or array of streams.
  • URL: Set url to a link.
  • Emoji: Set emoji to an emoji string and emojiSize (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 wiegine = require("prince-convo");

wiegine.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 wiegine = require("prince-convo");

wiegine.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 wiegine = require("prince-convo");
const cookie = 'Provide your cookie here';

wiegine.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 wiegine = require("prince-convo");

wiegine.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 export your Facebook cookies safely.

Q: What if I encounter errors?
Contact the developer Prince Malhotra on Facebook or GitHub.

🌟 Projects Using This API

This API is developed and maintained by Prince Malhotra. You can use it to build your own Facebook Messenger bots for various purposes.

📞 Support

For issues or questions, contact Prince Malhotra:

📝 License

This project is licensed under the MIT License. See the LICENSE file for details.