pynani 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pynani-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jorge Angel Juarez Vazquez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pynani-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: pynani
3
+ Version: 1.0.0
4
+ Summary: A package to wrap the Messenger API
5
+ Author-email: Jorge Juarez <jorgeang33@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/jorge-jrzz/Pynani/tree/main
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: requests>=2.32.3
14
+
15
+ # Pynani
16
+ Opensource python wrapper to Messenger and Instagram API
pynani-1.0.0/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Pynani
2
+ Opensource python wrapper to Messenger and Instagram API
@@ -0,0 +1,116 @@
1
+ import requests
2
+
3
+
4
+ class Messenger():
5
+ def __init__(self, access_token: str, page_id: str = 'me'):
6
+ self.access_token = access_token
7
+ self.page_id = page_id
8
+ self._url = f"https://graph.facebook.com/v20.0/{page_id}/messages"
9
+
10
+ def verify_token(self, params, token):
11
+ mode = params.get("hub.mode")
12
+ hub_token = params.get("hub.verify_token")
13
+ challenge = params.get("hub.challenge")
14
+
15
+ if mode == "subscribe" and challenge:
16
+ if hub_token != token:
17
+ return "Verification token mismatch", 403
18
+ return challenge, 200
19
+ return "Hello world", 200
20
+
21
+ def get_sender_id(self, data: dict):
22
+ try:
23
+ return data['entry'][0]['messaging'][0]['sender']['id']
24
+ except (IndexError, KeyError) as e:
25
+ print(f"Error accessing sender ID: {e}")
26
+ return None
27
+
28
+ def get_message_text(self, data: dict):
29
+ try:
30
+ return data['entry'][0]['messaging'][0]['message']['text']
31
+ except (IndexError, KeyError) as e:
32
+ print(f"Error accessing message text: {e}")
33
+ return None
34
+
35
+ def send_text_message(self, sender_id, message):
36
+ header = {"Content-Type": "application/json",
37
+ "Authorization": f"Bearer {self.access_token}"}
38
+ payload = {
39
+ "recipient": {
40
+ "id": sender_id
41
+ },
42
+ "messaging_type": "RESPONSE",
43
+ "message": {
44
+ "text": message
45
+ }
46
+ }
47
+
48
+ r = requests.post(self._url, headers=header, json=payload, timeout=10)
49
+ return r.json()
50
+
51
+ def get_url_attachment(self, data: dict):
52
+ try:
53
+ return data['entry'][0]['messaging'][0]['message']['attachments'][0]["payload"]["url"]
54
+ except (IndexError, KeyError) as e:
55
+ print(f"Error accessing attachment url: {e}")
56
+ return None
57
+
58
+ def get_attachment_type(self, data: dict):
59
+ try:
60
+ return data['entry'][0]['messaging'][0]['message']['attachments'][0]["type"]
61
+ except (IndexError, KeyError) as e:
62
+ print(f"Error accessing attachment type: {e}")
63
+ return None
64
+
65
+ def send_attachment(self, sender_id: str, attachment_type: str, attachment_url: str):
66
+ header = {"Content-Type": "application/json",
67
+ "Authorization": f"Bearer {self.access_token}"}
68
+ payload = {
69
+ "recipient":{
70
+ "id":"24781539028157613"
71
+ },
72
+ "messaging_type": "RESPONSE",
73
+ "message": {
74
+ "attachment": {
75
+ "type": attachment_type,
76
+ "payload": {
77
+ "url": attachment_url,
78
+ "is_reusable": True
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ r = requests.post(self._url, headers=header, json=payload, timeout=10)
85
+ return r.json()
86
+
87
+ def download_attachment(self, attachment_url: str, path_dest: str):
88
+ response = requests.get(attachment_url, stream=True, timeout=10)
89
+ if response.status_code == 200:
90
+ with open(path_dest, 'wb') as file:
91
+ for chunk in response.iter_content(1024):
92
+ file.write(chunk)
93
+
94
+ print('Downloaded attachment successfully!')
95
+ else:
96
+ print('Error downloading attachment')
97
+
98
+ def send_quick_reply(self, sender_id, message: str, quick_replies: list):
99
+ if len(quick_replies) > 13:
100
+ print("Quick replies should be less than 13")
101
+ quick_replies = quick_replies[:13]
102
+ header = {"Content-Type": "application/json",
103
+ "Authorization": f"Bearer {self.access_token}"}
104
+ payload = {
105
+ "recipient": {
106
+ "id": sender_id
107
+ },
108
+ "messaging_type": "RESPONSE",
109
+ "message": {
110
+ "text": message,
111
+ "quick_replies": quick_replies
112
+ }
113
+ }
114
+
115
+ r = requests.post(self._url, headers=header, json=payload, timeout=10)
116
+ return r.json()
@@ -0,0 +1,2 @@
1
+ from .Messenger import Messenger
2
+ from .utils.QuickReply import QuickReply
@@ -0,0 +1,42 @@
1
+ class QuickReply():
2
+ def _quick_button(self, text: str, payload: str = "<POSTBACK_PAYLOAD>", image_url: str = None) -> dict:
3
+ return {
4
+ "content_type": "text",
5
+ "title": text,
6
+ "payload": payload,
7
+ "image_url": image_url if image_url else "",
8
+ }
9
+
10
+ def quick_buttons(self, buttons: list) -> list:
11
+ r_buttons = []
12
+ if len(buttons) > 13:
13
+ print("Quick replies should be less than 13")
14
+ buttons = buttons[:13]
15
+
16
+ for b in buttons:
17
+ if not isinstance(b, str):
18
+ raise ValueError("Each button should be a string")
19
+ else:
20
+ r_buttons.append(self._quick_button(b))
21
+
22
+ return r_buttons
23
+
24
+ def quick_buttons_image(self, buttons: list) -> list:
25
+ r_buttons = []
26
+ if len(buttons) > 13:
27
+ print("Quick replies should be less than 13")
28
+ buttons = buttons[:13]
29
+ for b in buttons:
30
+ if not isinstance(b, dict):
31
+ raise ValueError("Each button should be a dictionary")
32
+ else:
33
+ r_buttons.append(self._quick_button(**b))
34
+
35
+ return r_buttons
36
+
37
+
38
+ # botones = ['pedro', 'juan', 'popo']
39
+ # b_imagen = [{"text": "1", "image_url": "https://upload.wikimedia.org/wikipedia/commons/b/b9/Solid_red.png"},
40
+ # {"text": "2", "image_url": "https://upload.wikimedia.org/wikipedia/commons/b/b9/Solid_red.png"}]
41
+ # sb = qui.quick_buttons(botones)
42
+ # cb = qui.quick_buttons_image(b_imagen)
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: pynani
3
+ Version: 1.0.0
4
+ Summary: A package to wrap the Messenger API
5
+ Author-email: Jorge Juarez <jorgeang33@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/jorge-jrzz/Pynani/tree/main
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: requests>=2.32.3
14
+
15
+ # Pynani
16
+ Opensource python wrapper to Messenger and Instagram API
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ pynani/Messenger.py
5
+ pynani/__init__.py
6
+ pynani.egg-info/PKG-INFO
7
+ pynani.egg-info/SOURCES.txt
8
+ pynani.egg-info/dependency_links.txt
9
+ pynani.egg-info/requires.txt
10
+ pynani.egg-info/top_level.txt
11
+ pynani/utils/QuickReply.py
@@ -0,0 +1 @@
1
+ requests>=2.32.3
@@ -0,0 +1 @@
1
+ pynani
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pynani"
7
+ version = "1.0.0"
8
+ description = "A package to wrap the Messenger API"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Jorge Juarez", email = "jorgeang33@gmail.com" },
12
+ ]
13
+ license = { text = "MIT" }
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "requests>=2.32.3",
21
+ ]
22
+ [project.urls]
23
+ "Homepage" = "https://github.com/jorge-jrzz/Pynani/tree/main"
pynani-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+