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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fb_gapi-0.1.12.tar.gz
  • Upload date:
  • Size: 4.2 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.12.tar.gz
Algorithm Hash digest
SHA256 773d55f93b71c4e423b88adb1a7d933d39202dc58ea78d25138119dd9bc49217
MD5 61dc5ff3085fc552c27ac61092c88d01
BLAKE2b-256 497e776027006614b860313b5566f79deb761bdbc8e405656373fb3390faa2f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fb_gapi-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 4.7 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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 f56599b524a15c7f58e7fcd6f47097139faa9586a8b500869845811e2b867452
MD5 43091caab8c9645c3daeabc5d32c40ff
BLAKE2b-256 e108bfc1cb0e98d8da6d6d65455d9d2e77d662f3c718252cbb37a599746f9419

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