Skip to content

yoshijava/fb-messenger-cli

Repository files navigation

Terminal Facebook Messenger

A lightweight, terminal-based Facebook Messenger client built with Python and Textual. This mini-project allows you to chat with your Facebook contacts directly from your command line.

Features

  • Terminal UI: Built with Textual for a clean, responsive command-line interface.
  • Real-time Messaging: Send and receive messages in real-time.
  • Embedded API: Uses a modified, embedded version of fbchat to handle the underlying Facebook API communication.

Important Note on fbchat

This project uses an embedded and modified version of the fbchat library. The original, publicly available fbchat package on PyPI is obsolete and no longer actively maintained. Our embedded version includes critical fixes necessary to interact with the modern Facebook API. Do not run pip install fbchat, as it will conflict with the local version and break the application.

Prerequisites

  • Python 3.9+
  • A valid Facebook account

Installation

  1. Clone this repository:

    git clone <your-repo-url>
    cd <your-repo-directory>
  2. Create and activate a virtual environment (recommended):

    python3 -m venv venv
    source venv/bin/activate  # On Windows use: venv\Scripts\activate
  3. Install the required dependencies:

    pip install -r requirements.txt

Authentication Setup (Getting Cookies)

Facebook's automated login and bot-detection systems are very aggressive and often block automated login scripts (generating ReCAPTCHAs that headless scripts cannot solve). Therefore, the most reliable way to authenticate this application is by manually extracting your session cookies from your own web browser.

You only need to do this once, and the cookies usually remain valid for several months.

Step-by-Step Instructions to Extract Cookies:

  1. Log in to Facebook: Open your preferred desktop web browser (Chrome, Edge, Safari, or Firefox) and log in to Facebook.com.
  2. Open Developer Tools: Press F12 on your keyboard (or right-click anywhere on the page and select "Inspect").
  3. Navigate to the Application/Storage Tab:
    • Chrome/Edge: Click on the Application tab at the top of the Developer Tools panel.
    • Firefox: Click on the Storage tab.
  4. Locate the Cookies list: On the left sidebar, expand the Cookies section and click on https://www.facebook.com.
  5. Find c_user: Look at the table on the right. Find the row where the "Name" column is exactly c_user. Double-click the corresponding text in the "Value" column and copy it.
  6. Find xs: Similarly, find the row where the "Name" column is exactly xs. Double-click its "Value" and copy it.
  7. Create fb_cookies.json: In the root directory of this project, create a new file named fb_cookies.json.
  8. Paste the values: Paste your copied values into fb_cookies.json using the following exact JSON format:
    {
      "c_user": "YOUR_C_USER_VALUE_HERE",
      "xs": "YOUR_XS_VALUE_HERE"
    }
    Make sure not to include any extra spaces or quotes inside the values themselves.

Usage

Once you have set up your fb_cookies.json file, you can start the application:

python app.py

Use your keyboard to navigate through threads, switch conversations, and send messages.

Disclaimer

This is an unofficial, community-driven project and is not affiliated with, endorsed by, or sponsored by Meta/Facebook. Use it responsibly and at your own risk. Automated interaction with Facebook may sometimes trigger security checkpoints or account temporary suspensions.

About

A mini toy to use messenger in CLI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages