fca-unofficial: Unofficial Facebook Chat API for Python
Project description
Using the Bot API (Group-only)
This guide shows developers how to use your bot and the underlying python_facebookapi to send messages to a Messenger group thread and connect using appstate.json.
If your deployment is currently group-only (commands work in group chats, not in 1:1 DMs), follow these steps.
1) Prepare appstate.json
The API logs in with cookies stored in appstate.json at the repository root. This is a JSON array of objects like:
[
{ "key": "c_user", "value": "..." },
{ "key": "xs", "value": "..." },
{ "key": "datr", "value": "..." },
{ "key": "sb", "value": "..." }
]
Ways to create it:
- If you have a cookie string, you can paste it on the first run and
a.py/bot.pywill writeappstate.jsonfor you. - Or set
FB_COOKIEbefore running:
$env:FB_COOKIE = "c_user=...; xs=...; datr=...; sb=..."
python a.py
The bot stores the parsed cookies in appstate.json automatically.
2) Run the bot (group commands)
To run the command-driven listener (recommended):
# Optional diagnostics
$env:DM_DEBUG = "1"
python a.py
In your group thread, send:
/ping→ bot repliespong/send group:<THREAD_ID> hello group→ bot sends "hello group" into the specified group thread/history <THREAD_ID> [amount]→ bot prints recent messages from that group
Notes:
- Use the
group:prefix to force group mode when using/send. - The bot ignores its own messages, and you can restrict who can trigger commands using
ALLOW_USER_IDS(comma-separated user IDs).
3) Send to a group programmatically
If you want to send a message from a Python script without using chat commands, use the API like this:
from python_facebookapi import login
import json
# Load appstate.json
with open("appstate.json", "r", encoding="utf-8") as f:
appstate = json.load(f)
# Login
api = login({"appState": appstate}, options={"autoSaveAppState": True, "logging": True})
# Send a message to a group thread
GROUP_THREAD_ID = "758202360604154" # replace with your group thread ID
res = api.sendMessage("Hello, group!", GROUP_THREAD_ID, isSingleUser=False)
print(res) # {"messageID": "...", "threadID": "...", "timestamp": ...}
Tips to find a group thread ID:
- Inspect logs printed by the bot when it receives messages (
threadIDfield). - Use API methods like
getThreadList()to enumerate threads and pick the group.
4) Example: minimal group bot
If you prefer a tiny "bot.js-like" Python bot, use bot.py. It supports:
/ping,/send group:<id> <msg>,/help- Logging in via
appstate.jsonorFB_COOKIE
Run it:
python bot.py
5) Troubleshooting (group-only)
-
The bot replies in group but not in DMs:
-
This is expected in a group-only deployment. DMs may require extra realtime parsing and/or fallback polling.
-
You can enable a polling fallback in
bot.pywith:$env:POLL_FALLBACK = "1" python bot.py
-
Or keep sending commands from a group thread.
-
-
Login errors / disconnects:
- Refresh cookies in
appstate.json(ensurec_user,xs,datr,sb). - Keep
DM_DEBUG=1to capture listener logs.
- Refresh cookies in
6) Security
appstate.jsoncontains session cookies—keep it private.- Use a dedicated account for testing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fca_unofficial-0.0.2.tar.gz.
File metadata
- Download URL: fca_unofficial-0.0.2.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c4874fe5e91382a007e242a03d766b821d4d5502234e552161732a674c776bd
|
|
| MD5 |
7e40bc1394fa46e1c01bf5ee4e552edb
|
|
| BLAKE2b-256 |
d5450ab8b97459c6af0639a1984e706afed255693d87c1218ab88ca95c08987e
|
File details
Details for the file fca_unofficial-0.0.2-py3-none-any.whl.
File metadata
- Download URL: fca_unofficial-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99bd56f23173f007db87e008a5d2e499d5c9af6472a4fa4daea565b7286e26f0
|
|
| MD5 |
c580b7332b9374eabdf4577f10be222f
|
|
| BLAKE2b-256 |
695106b60eaf3e69c6138e062996a47f750ef37366bec596fda63bcc43191af9
|