Name | pynani JSON |
Version |
1.4.0
JSON |
| download |
home_page | None |
Summary | A package to wrap the Messenger API |
upload_time | 2024-07-12 06:48:22 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT License Copyright (c) 2024 Jorge Angel Juarez Vazquez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
messenger
wrapper
meta
api
facebook
pynani
pymessenger
|
VCS |
|
bugtrack_url |
|
requirements |
requests
colorlog
sphinx
sphinx-book-theme
sphinx-copybutton
pynani
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<img align="center" src="https://raw.githubusercontent.com/jorge-jrzz/Pynani/main/docs/_static/banner-pynani-github.png" alt="banner Pynani">
---
Opensource python wrapper to Messenger API
## Features
### API
- Verify the webhook
- Send text messages
- Send attachments from a remote file (image, audio, video, file)
- Send attachments from a local file (image, audio, video, file)
- Send templates (generic, buttons, media, receipent)
- Send quick replies
### Other functionalities
- Get sender id
- Get type of message received
- Get text of the message received
- Get the url of the attachment received
- Get type of the attachment received
- Download attachments received
## Installation
Install Pynani with pip
```bash
pip install pynani
```
Or install with pipenv (requires pipenv installed)
```bash
pipenv install pynani
```
## Getting started
### Prerequisites
- **Python 3.8**+ installed
- To get started using this module, you will need **page access token** which you can get from the Facebook Developer Portal
### A simple echo bot
The Messenger class (defined in Messenger.py) encapsulates all API calls in a single class. It provides functions such as send_xyz (send_message, send_attachment etc.) and several ways to listen for incoming messages.
Create a file called echo_bot.py. Then, open the file and create an instance of the Messenger class.
```python
from pynani import Messenger
PAGE_ACCESS_TOKEN = 'EAAxxxxxxx...'
mess = Messenger(PAGE_ACCESS_TOKEN)
```
> [!IMPORTANT]
> Make sure to actually replace PAGE_ACCESS_TOKEN with your own page access token.
After that declaration, we need to register some message handlers. First, we need to create and verify a webhook with the help of _Flask_ or _FastAPI_.
```python
from flask import Flask, request, jsonify
app = Flask(__name__)
TOKEN = "abc123"
@app.get("/")
def meta_verify():
return mess.verify_token(request.args, TOKEN)
```
Now let's define a webhook that handles certain messages
```python
@app.post("/")
def meta_webhook():
data = request.get_json()
sender_id = mess.get_sender_id(data)
message = mess.get_message_text(data)
if message == "Hello":
mess.send_text_message(sender_id, "Hello, World!")
if message == "Bye":
mess.send_text_message(sender_id, "Nice to meet you! 👍🏽")
return jsonify({"status": "success"}), 200
```
We now have a basic bot which replies a static message to "hello" and "bye" messages. To start the bot, add the following to our source file:
```python
if __name__ =='__main__':
app.run(port=8080, debug=True)
```
Alright, that's it! Our source file now looks like this:
```python
from flask import Flask, request, jsonify
from pynani import Messenger
PAGE_ACCESS_TOKEN = 'EAAxxxxxxx...'
TOKEN = "abc123"
mess = Messenger(PAGE_ACCESS_TOKEN)
app = Flask(__name__)
@app.get("/")
def meta_verify():
return mess.verify_token(request.args, TOKEN)
@app.post("/")
def meta_webhook():
data = request.get_json()
sender_id = mess.get_sender_id(data)
message = mess.get_message_text(data)
if message == "Hello":
mess.send_text_message(sender_id, "Hello, World!")
if message == "Bye":
mess.send_text_message(sender_id, "Nice to meet you! 👍🏽")
return jsonify({"status": "success"}), 200
if __name__ =='__main__':
app.run(port=8080, debug=True)
```
To start the bot, simply open up a terminal and enter `python echo_bot.py` to run the bot! Test it by sending messages ("hello" and "bye").
## Related
Here are some related projects that I was inspired by them.
- [pyTelegramBotAPI](https://github.com/eternnoir/pyTelegramBotAPI?tab=readme-ov-file)
- [WhatsApp Cloud API Wrapper](https://github.com/Neurotech-HQ/heyoo)
- [Messenger API Python](https://github.com/krishna2206/messenger-api-python)
Raw data
{
"_id": null,
"home_page": null,
"name": "pynani",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "Messenger, wrapper, Meta, API, Facebook, Pynani, PyMessenger",
"author": null,
"author_email": "Jorge Juarez <jorgeang33@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/81/9f/c3ab002c67c160607830058b1b90bf4f99a73e80814159b929a47147f18f/pynani-1.4.0.tar.gz",
"platform": null,
"description": "<img align=\"center\" src=\"https://raw.githubusercontent.com/jorge-jrzz/Pynani/main/docs/_static/banner-pynani-github.png\" alt=\"banner Pynani\">\n\n---\n\nOpensource python wrapper to Messenger API\n\n## Features\n\n### API\n\n- Verify the webhook\n- Send text messages\n- Send attachments from a remote file (image, audio, video, file)\n- Send attachments from a local file (image, audio, video, file)\n- Send templates (generic, buttons, media, receipent)\n- Send quick replies\n\n### Other functionalities\n\n- Get sender id\n- Get type of message received\n- Get text of the message received\n- Get the url of the attachment received\n- Get type of the attachment received\n- Download attachments received\n\n## Installation\n\nInstall Pynani with pip\n\n```bash\n pip install pynani\n```\n\nOr install with pipenv (requires pipenv installed)\n\n```bash\n pipenv install pynani\n```\n\n## Getting started\n\n### Prerequisites\n\n- **Python 3.8**+ installed\n- To get started using this module, you will need **page access token** which you can get from the Facebook Developer Portal\n\n### A simple echo bot\n\nThe Messenger class (defined in Messenger.py) encapsulates all API calls in a single class. It provides functions such as send_xyz (send_message, send_attachment etc.) and several ways to listen for incoming messages.\n\nCreate a file called echo_bot.py. Then, open the file and create an instance of the Messenger class.\n\n```python\nfrom pynani import Messenger\n\nPAGE_ACCESS_TOKEN = 'EAAxxxxxxx...'\nmess = Messenger(PAGE_ACCESS_TOKEN)\n```\n\n> [!IMPORTANT]\n> Make sure to actually replace PAGE_ACCESS_TOKEN with your own page access token.\n\nAfter that declaration, we need to register some message handlers. First, we need to create and verify a webhook with the help of _Flask_ or _FastAPI_.\n\n```python\nfrom flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\nTOKEN = \"abc123\"\n\n@app.get(\"/\")\ndef meta_verify():\n return mess.verify_token(request.args, TOKEN)\n```\n\nNow let's define a webhook that handles certain messages\n\n```python\n@app.post(\"/\")\ndef meta_webhook():\n data = request.get_json()\n sender_id = mess.get_sender_id(data)\n message = mess.get_message_text(data)\n if message == \"Hello\":\n mess.send_text_message(sender_id, \"Hello, World!\")\n if message == \"Bye\":\n mess.send_text_message(sender_id, \"Nice to meet you! \ud83d\udc4d\ud83c\udffd\")\n\n return jsonify({\"status\": \"success\"}), 200\n```\n\nWe now have a basic bot which replies a static message to \"hello\" and \"bye\" messages. To start the bot, add the following to our source file:\n\n```python\nif __name__ =='__main__':\n app.run(port=8080, debug=True)\n```\n\nAlright, that's it! Our source file now looks like this:\n\n```python\nfrom flask import Flask, request, jsonify\nfrom pynani import Messenger\n\nPAGE_ACCESS_TOKEN = 'EAAxxxxxxx...'\nTOKEN = \"abc123\"\n\nmess = Messenger(PAGE_ACCESS_TOKEN)\napp = Flask(__name__)\n\n@app.get(\"/\")\ndef meta_verify():\n return mess.verify_token(request.args, TOKEN)\n\n@app.post(\"/\")\ndef meta_webhook():\n data = request.get_json()\n sender_id = mess.get_sender_id(data)\n message = mess.get_message_text(data)\n if message == \"Hello\":\n mess.send_text_message(sender_id, \"Hello, World!\")\n if message == \"Bye\":\n mess.send_text_message(sender_id, \"Nice to meet you! \ud83d\udc4d\ud83c\udffd\")\n\n return jsonify({\"status\": \"success\"}), 200\n\nif __name__ =='__main__':\n app.run(port=8080, debug=True)\n```\n\nTo start the bot, simply open up a terminal and enter `python echo_bot.py` to run the bot! Test it by sending messages (\"hello\" and \"bye\").\n\n## Related\n\nHere are some related projects that I was inspired by them.\n\n- [pyTelegramBotAPI](https://github.com/eternnoir/pyTelegramBotAPI?tab=readme-ov-file)\n- [WhatsApp Cloud API Wrapper](https://github.com/Neurotech-HQ/heyoo)\n- [Messenger API Python](https://github.com/krishna2206/messenger-api-python)\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Jorge Angel Juarez Vazquez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "A package to wrap the Messenger API",
"version": "1.4.0",
"project_urls": {
"Bug Tracker": "https://github.com/jorge-jrzz/Pynani/issues",
"Repository": "https://github.com/jorge-jrzz/Pynani"
},
"split_keywords": [
"messenger",
" wrapper",
" meta",
" api",
" facebook",
" pynani",
" pymessenger"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f04dd8c24c37d171b28bc0318a88c4cee81eed244551e997f33f5df2eb4542c8",
"md5": "d5ca7da1b6f095b17dd7a1e63127706e",
"sha256": "831cbf042cb8647609b19412a53b22b00ee9e385d0058af3e8c080c28872ef93"
},
"downloads": -1,
"filename": "pynani-1.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d5ca7da1b6f095b17dd7a1e63127706e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 15036,
"upload_time": "2024-07-12T06:48:20",
"upload_time_iso_8601": "2024-07-12T06:48:20.999228Z",
"url": "https://files.pythonhosted.org/packages/f0/4d/d8c24c37d171b28bc0318a88c4cee81eed244551e997f33f5df2eb4542c8/pynani-1.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "819fc3ab002c67c160607830058b1b90bf4f99a73e80814159b929a47147f18f",
"md5": "4ddf48593c5637f613bea62744aee6dd",
"sha256": "64d29206d54053436ca05457f190ffd74927362877960b94bf09ed2ed4ea287e"
},
"downloads": -1,
"filename": "pynani-1.4.0.tar.gz",
"has_sig": false,
"md5_digest": "4ddf48593c5637f613bea62744aee6dd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 14935,
"upload_time": "2024-07-12T06:48:22",
"upload_time_iso_8601": "2024-07-12T06:48:22.553016Z",
"url": "https://files.pythonhosted.org/packages/81/9f/c3ab002c67c160607830058b1b90bf4f99a73e80814159b929a47147f18f/pynani-1.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-12 06:48:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jorge-jrzz",
"github_project": "Pynani",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "requests",
"specs": [
[
"==",
"2.32.3"
]
]
},
{
"name": "colorlog",
"specs": [
[
"==",
"6.8.2"
]
]
},
{
"name": "sphinx",
"specs": [
[
"==",
"7.3.7"
]
]
},
{
"name": "sphinx-book-theme",
"specs": [
[
"==",
"1.1.3"
]
]
},
{
"name": "sphinx-copybutton",
"specs": [
[
"==",
"0.5.2"
]
]
},
{
"name": "pynani",
"specs": []
}
],
"lcname": "pynani"
}