{"id":19820189,"url":"https://github.com/jorge-jrzz/pynani","last_synced_at":"2025-05-01T11:33:34.266Z","repository":{"id":244308794,"uuid":"814343921","full_name":"jorge-jrzz/Pynani","owner":"jorge-jrzz","description":"Open source python wrapper to Messenger API","archived":false,"fork":false,"pushed_at":"2024-07-12T06:47:50.000Z","size":347,"stargazers_count":7,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-14T04:07:37.152Z","etag":null,"topics":["messenger","messenger-api","messenger-bot","python-api","wrapper-api"],"latest_commit_sha":null,"homepage":"https://pynani-docs.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jorge-jrzz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-12T20:31:32.000Z","updated_at":"2024-10-13T08:05:49.000Z","dependencies_parsed_at":"2024-07-12T06:58:02.255Z","dependency_job_id":null,"html_url":"https://github.com/jorge-jrzz/Pynani","commit_stats":null,"previous_names":["jorge-jrzz/pynani"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorge-jrzz%2FPynani","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorge-jrzz%2FPynani/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorge-jrzz%2FPynani/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorge-jrzz%2FPynani/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jorge-jrzz","download_url":"https://codeload.github.com/jorge-jrzz/Pynani/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224254578,"owners_count":17281176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["messenger","messenger-api","messenger-bot","python-api","wrapper-api"],"created_at":"2024-11-12T10:22:05.238Z","updated_at":"2024-11-12T10:22:05.882Z","avatar_url":"https://github.com/jorge-jrzz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/jorge-jrzz/Pynani/main/docs/_static/banner-pynani-github.png\" alt=\"banner Pynani\"\u003e\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\u003e [!IMPORTANT]\n\u003e 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! 👍🏽\")\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! 👍🏽\")\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorge-jrzz%2Fpynani","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjorge-jrzz%2Fpynani","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorge-jrzz%2Fpynani/lists"}