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.5.tar.gz (5.0 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.5-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pymes_api-0.2.5.tar.gz
Algorithm Hash digest
SHA256 4c71f6ac97d228211082022ef1688732f095ecfe40fd84500ec25fb5c0159a63
MD5 e81f8adc4125a4e7326dacb3a53b53b6
BLAKE2b-256 abb2d5069d2b24bdf140722dbc74dc8712f76f35c1d57251f58913718a5cb585

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pymes_api-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7b29ce43826a1682e9933d6d121ac544ff809512ab54422cadf04e206ed6210c
MD5 4618168189d51a325442403242b8753d
BLAKE2b-256 73de7849770454114950648ac7b59dbecea458977f210603eea79a0eff754e59

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