Skip to main content

A lightweight Python SDK for sending messages via Facebook Messenger

Project description

Facebook Messenger Graph API Python SDK

A lightweight Python SDK for sending messages (text and image attachments) using the Facebook Graph API.

🚀 Usage

📦 Import the client

from facebook_messenger import MessengerClient

🔒 Initialize with your Page Access Token

client = MessengerClient(access_token="YOUR_PAGE_ACCESS_TOKEN")

✉️ Sending a Text Message

response = client.send_text(recipient_id="USER_PSID", message_text="Hello, user!")
print(response)

🖼️ Sending an Image Attachment

image_url = "https://example.com/image.jpg"
response = client.send_attachment(recipient_id="USER_PSID", image_url=image_url)
print(response)

⚠️ Error Handling

This SDK will raise a MessengerAPIError when the Facebook API responds with an error.

Example:

from facebook_messenger import MessengerAPIError

try:
    client.send_text("invalid_user_id", "Hi!")
except MessengerAPIError as e:
    print(f"GAPI Error: {e}")

Error Output Example:

MessengerAPIError (HTTP 400): [OAuthException] Invalid OAuth access token. (code 190)

📄 Requirements

  • Python 3.6+

🛠️ TODO

  • Add support for other templates.
  • Support for quick replies, actions, and custom buttons.

📃 License

MIT License. Use freely and contribute!

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

fb_gapi-0.1.11.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fb_gapi-0.1.11-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file fb_gapi-0.1.11.tar.gz.

File metadata

  • Download URL: fb_gapi-0.1.11.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fb_gapi-0.1.11.tar.gz
Algorithm Hash digest
SHA256 cec64811e7cc7c37d9ace9fe85374b9f209e299cb36f4a2d213f61179e3a0485
MD5 4e920c99b961ffff295488db912aa264
BLAKE2b-256 0f44435d89aad5bd3eef504f2b9f58c325aaa94016aa14332ef722db16f901ec

See more details on using hashes here.

File details

Details for the file fb_gapi-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: fb_gapi-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fb_gapi-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 55cf18971397cce209b979d1750bad89cc4293cd0c2ff683bb0afabdb1ff4080
MD5 9709b044eb6efe9be368f4f9e780737f
BLAKE2b-256 eae378700f405d3ad78d85bb8ef46559b8083995e1df6eb26e0b5fcd002d26f5

See more details on using hashes here.

Supported by

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