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

1. Import the client

from facebook_messenger import MessengerClient

2. 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"Facebook API Error: {e}")

Error Output Example:

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

📄 Requirements

  • Python 3.6+
  • requests

Install requirements using:

pip install -r requirements.txt

🛠️ TODO

  • Add support for more attachment types (video, audio, file)
  • Support for templates, quick replies, and buttons
  • Webhook integration

📃 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.1.tar.gz (3.7 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.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fb_gapi-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 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.1.tar.gz
Algorithm Hash digest
SHA256 086b3456a5df89eea097b424ac42f55db57542c2ab8c147b9e55cbd948b80f31
MD5 12d091a3dc3bf3b7921510898b32f871
BLAKE2b-256 c0d0896f11228387521fba593f995724a2501ba86563c11a828ffda3fcbbdf39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fb_gapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b351e48f6cdf3f078ee355e3e134760dc3d52796b89db46145d3b7fdebe38fd9
MD5 60816c6e3c2f80da1e644e1664d3d2f1
BLAKE2b-256 70c7a8895ff55f7f1fc0d34c4a3ab688b5f733540dee0a1955a6e6f85822d66a

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