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 🙏

© 2024 – Pkg Stats / Ryan Hefner

josh-fca

v1.0.4

Published

---

Downloads

290

Readme


josh-fca - Unofficial Facebook Chat API

This is a fork of the original fca-unofficial repository. This version includes new features and updates that are bundled faster than the main repository. However, be aware that new features may also come with some bugs.


Overview

This API allows you to automate Facebook chat functionalities by emulating the browser's GET/POST requests. It does not work with an auth token and requires a Facebook account's AppState (session information), which is obtained via third-party tools.


Important Notes

The api.getAppState() function no longer works!

As of recent changes, Facebook no longer supports retrieving session information directly from the API using api.getAppState(). Instead, you must use a previously obtained AppState from external tools like Kiwi Browser and the c3c-ufc-utility extension.

We strongly recommend being responsible when using this API to avoid issues like account bans. Avoid spamming messages, sending large amounts of requests, or using excessive automation.


New Features

1. BypassAutomationBehavior

This feature is designed to bypass certain behavior detection mechanisms from Facebook, which may otherwise flag your actions as automated. By enabling this, your bot's activity will appear more like human interaction, helping reduce the risk of account limitations.

  • Configuration: Can be toggled on or off in the josh-fca.json configuration file.

2. AutoRefreshFbDtsg

This feature automatically refreshes the fb_dtsg token, which is used for secure communication with Facebook. Since fb_dtsg tokens expire periodically, this feature ensures your session stays active by refreshing the token automatically without requiring a manual login.

  • Configuration: Can be toggled on or off in the josh-fca.json configuration file.

How to Get AppState

  1. Kiwi Browser & c3c-ufc-utility Extension
    • Install the Kiwi Browser and the c3c-ufc-utility extension.
    • Use the extension to extract your AppState (session cookies) from your Facebook login.
    • The AppState will be saved as a appstate.json file, which you will load for logging in.

For more details, refer to the official c3c-ufc-utility GitHub release.


Install

To install josh-fca-api, use the following npm command:

npm install josh-fca

To install the bleeding-edge version directly from GitHub:

npm install josh-fca/josh-fca

Example Usage

Here’s how to log in using the AppState:

const fs = require('fs');
const login = require('josh-fca');

// Load your appState from the saved file
const appState = JSON.parse(fs.readFileSync('appstate.json', 'utf8'));

// Use the appState for login
login({ appState: appState }, (err, api) => {
    if (err) return console.error('Login failed:', err);

    console.log('Successfully logged in!');

    // Example of listening for new messages
    api.listen((err, message) => {
        if (err) return console.error(err);

        // Respond to the received message
        api.sendMessage(message.body, message.threadID);
    });
});

Configuration (josh-fca-api.json)

The following options can be configured in your josh-fca.json file:

{
  "BypassAutomationBehavior": true,  // Set to false to disable this feature
  "AutoRefreshFbDtsg": true         // Set to false to disable this feature
}
  • BypassAutomationBehavior: Enables or disables the feature to bypass Facebook's automated behavior detection.
  • AutoRefreshFbDtsg: Enables or disables automatic refreshing of the fb_dtsg token to keep your session active.

Main Functionality

  • Sending Messages:

    • Regular Text Messages
    • Sticker Messages
    • Image/File Attachments
    • URLs
    • Emojis
  • Listening to Messages:

    • Listen to messages in real-time
    • Option to listen to events like user joining or leaving a chat

FAQ

  1. Why doesn’t api.getAppState() work anymore?

    • The api.getAppState() function was deprecated. You now need to use the AppState from external tools, such as the Kiwi Browser and the c3c-ufc-utility extension.
  2. How can I log in without credentials?

    • After logging in through a browser, extract your AppState using the c3c-ufc-utility extension. This is now the only way to authenticate.
  3. Can I listen to messages from the bot?

    • Yes, by default, the bot listens to incoming messages and can respond automatically. You can configure it to respond with specific actions based on the message content.
  4. Is there a way to send media like images or files?

    • Yes, you can send files or images by passing them as attachments. The example provided demonstrates how to send an image along with a text message.
  5. How do I keep my session alive?

    • You do not need to log in repeatedly once you have your AppState saved. Simply load the appState.json each time you initialize the API.
  6. Can I send messages as a Facebook Page?

    • Yes, you can configure the login to use a Facebook Page ID for sending messages as a Page. This is done during the login step.

Projects Using This API

  • c3c - A customizable bot with Facebook and Discord support.
  • Messenger-CLI - Command-line interface for Facebook Messenger.

License

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


Contact & Community

If you have a problem with this FCA, you can contact us by clicking here:

Join our group ChatBot Community:


Note: This project is an unofficial Facebook chat API. Use it responsibly and follow Facebook’s terms of service.