Skip to main content

A Python library for Facebook Messenger API

Project description

pymes

A simple, lightweight Python wrapper for the Facebook Messenger API.

Installation

No installation command is available yet as this package is not yet published to PyPI. Once published, you will be able to install it via pip:

pip install pymes-api

Usage

Basic Example

from pymes import MessengerClient, Text, Attachment

# Initialize the client
sender = MessengerClient(page_access_token="YOUR_PAGE_ACCESS_TOKEN")

# Send a text message
sender.send(recipient_id="USER_ID", message=Text("Hello, world!"))

# Send an attachment (Image)
sender.send("USER_ID", Attachment("image", "https://example.com/image.jpg"))

# Mark as seen
sender.send("USER_ID", action="mark_seen")

Supported Message Types

  • Text: Simple text messages.
  • Attachment: Images, files, audio, video.
  • QuickReply: Messages with quick reply buttons.
  • GenericTemplate: Carousel-like templates with images and buttons.

Django Support (New)

You can easily handle incoming messages using the MessengerView.

# views.py
from pymes.adapter.django import MessengerView

class BotView(MessengerView):
    verify_token = "YOUR_VERIFY_TOKEN"
    app_id = "YOUR_PAGE_ID" # Optional verification

    def handle_message(self, metadata):
        sender_id = metadata['sender_id']
        message = metadata['payload']
        print(f"Message from {sender_id}: {message}")

    # handle any event defining a method with the event name like handle_{event name}
    

# urls.py
from django.urls import path
from .views import BotView

urlpatterns = [
    path("webhook/", BotView.as_view()),
]

Requirements

  • Python 3.10+
  • requests library

License

MIT License

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

pymes_api-0.2.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

pymes_api-0.2.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file pymes_api-0.2.2.tar.gz.

File metadata

  • Download URL: pymes_api-0.2.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pymes_api-0.2.2.tar.gz
Algorithm Hash digest
SHA256 8012b574dbdd60397e7a007a92cd32725138640f2489c9ac815445b9984c9a94
MD5 4f55652924df31f956e6a2fc641b6a0d
BLAKE2b-256 5adfa6ea22f985e8ae3121a991650a4e18e8587fd7d9d43a71f11e9465ca8aa4

See more details on using hashes here.

File details

Details for the file pymes_api-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pymes_api-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pymes_api-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bed7cdde1a154beef54cced1ea4936158407e4f1b9994d91c35eb56682a7869f
MD5 34ddc4b37c2a42b33dcdd35c49d93209
BLAKE2b-256 5467fc5745390673bf59691ef807848e555521a33b666e36b82b1660fa7619fd

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