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+
requestslibrary
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymes_api-0.2.4.tar.gz.
File metadata
- Download URL: pymes_api-0.2.4.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fb86796f49cdcc16a4608f4ed10134d77e0671f425992d072b1580c9b43b04e
|
|
| MD5 |
695233f9698283454b71c5c983b94961
|
|
| BLAKE2b-256 |
17577ab47da45123dee08a943c7e28cc379be11d8cbeed326b1c260f56dc2e3f
|
File details
Details for the file pymes_api-0.2.4-py3-none-any.whl.
File metadata
- Download URL: pymes_api-0.2.4-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.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8668bda1fa99e99082ef68f4a3e1218c3fbdd4037f97bd07545eccb024cd1876
|
|
| MD5 |
7def7c27f053ac10c3c76af597087ec1
|
|
| BLAKE2b-256 |
149aa7327e39e55daab4867d74dd8a49b9884f64ff0d09c4ec77e291b7f21ad8
|