Skip to main content

Facebook Messenger for Python.

Project description

Project version Supported python versions: 3.6, 3.7 and 3.8 License: BSD 3-Clause

A powerful and efficient library to interact with Facebook’s Messenger, using just your email and password. This is an asyncio fork of the fbchat library.

This is not an official API, Facebook has that over here for chat bots. This library differs by using a normal Facebook account instead.

fbchat currently support:

  • Sending many types of messages, with files, stickers, mentions, etc.

  • Fetching all messages, threads and images in threads.

  • Searching for messages and threads.

  • Creating groups, setting the group emoji, changing nicknames, creating polls, etc.

  • Listening for, an reacting to messages and other events in real-time.

  • Type hints, and it has a modern codebase (e.g. only Python 3.5 and upwards).

  • async/await (COMING).

Essentially, everything you need to make an amazing Facebook bot!

Caveats

fbchat works by imitating what the browser does, and thereby tricking Facebook into thinking it’s accessing the website normally.

However, there’s a catch! Using this library may not comply with Facebook’s Terms Of Service!, so be responsible Facebook citizens! We are not responsible if your account gets banned!

Additionally, the APIs the library is calling is undocumented! In theory, this means that your code could break tomorrow, without the slightest warning! If this happens to you, please report it, so that we can fix it as soon as possible!

With that out of the way, you may go to Read The Docs to see the full documentation!

Installation

$ pip install fbchat-asyncio

If you don’t have pip, this guide can guide you through the process.

You can also install directly from source, provided you have pip>=19.0:

$ pip install git+https://github.com/tulir/fbchat-asyncio.git#egg=fbchat

Examples

All examples are available here.

Basic example: basic_usage.py

If login using email and password doesn’t work, you can create a file in the working directory called “session.json” with the following format:

{
        "c_user": "[15 digits]",
        "xs": "[variable]"
}

These values are from the cookies stored by your browser after logging in your account. You can get these values this way:

On Firefox:

  1. Open messenger.com, login and press F12

  2. Go to “Storage”

  3. Go to “Cookies”

  4. Select “https://messenger.com” and copy the values from there.

On Chrome:

The process is the same, the only difference is “Storage” is called “Application” in Chrome.

KEEP IN MIND: These values can be used by someone else to login to your account, so keep them private!

After that you can use this code: session_handling.py

Depending on the domain you’re logging into, you have to set the “domain” argument appropriately (either facebook.com or messenger.com). Here’s an example:

await fbchat.Session.from_cookies(cookies, domain="messenger.com")

Maintainer

Acknowledgements

This project was originally inspired by facebook-chat-api.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fbchat-asyncio-kvgx12-0.6.24.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

fbchat_asyncio_kvgx12-0.6.24-py3-none-any.whl (67.0 kB view details)

Uploaded Python 3

File details

Details for the file fbchat-asyncio-kvgx12-0.6.24.tar.gz.

File metadata

File hashes

Hashes for fbchat-asyncio-kvgx12-0.6.24.tar.gz
Algorithm Hash digest
SHA256 c31e8f6f79783073a2fbf321ff17e741c7d7f1cae22ca56b274b27985ce0cc7f
MD5 01341fed4857badc049f560293d75ca1
BLAKE2b-256 6f4d5569c73754a26c8a3c06a9512e8ccf24626db51a6d6f20167e5e154bb919

See more details on using hashes here.

File details

Details for the file fbchat_asyncio_kvgx12-0.6.24-py3-none-any.whl.

File metadata

File hashes

Hashes for fbchat_asyncio_kvgx12-0.6.24-py3-none-any.whl
Algorithm Hash digest
SHA256 f97ba359affe8a8b922b0d708284e8d71a495920bfe91dabfaf803243f15e80d
MD5 752ece5a629e35292ff878f2bdc85b21
BLAKE2b-256 b27b9e30069f9b726b5633208fd814fc851711079da1de01534972639ea2a251

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page