wazzup 0.0.1__py3-none-any.whl

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.
wazzup/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .messaging import Messaging
2
+
3
+ __all__ = ["Messaging"]
wazzup/messaging.py ADDED
@@ -0,0 +1,66 @@
1
+ from src.wazzup import models
2
+ from src.wazzup.models.template_message import TemplateMessage
3
+
4
+ from .whatsapp import WhatsAppDriver
5
+
6
+
7
+ class Messaging:
8
+ def __init__(self, access_token, phone_number_id):
9
+ self.whatsapp_driver = WhatsAppDriver(access_token, phone_number_id)
10
+
11
+ def send_text_message(self, text_message: 'models.TextMessage'):
12
+ """
13
+ Send a text message using the WhatsApp API
14
+ """
15
+ response = self.whatsapp_driver.send_text_message(
16
+ text_message=text_message,
17
+ )
18
+
19
+ return response
20
+
21
+ def reply_message(
22
+ self,
23
+ text_message: models.TextMessage,
24
+ message_id,
25
+ ):
26
+ """
27
+ Reply to a message using the WhatsApp API
28
+ """
29
+ response = self.whatsapp_driver.reply_message(text_message, message_id)
30
+
31
+ return response
32
+
33
+ def react_to_message(
34
+ self,
35
+ message_reaction: models.MessageReaction,
36
+ ):
37
+ """
38
+ React to a message using the WhatsApp API
39
+ """
40
+ response = self.whatsapp_driver.react_to_message(message_reaction)
41
+
42
+ return response
43
+
44
+ def send_image_message(self, image_message: models.ImageMessage):
45
+ """
46
+ Send an image message using the WhatsApp API
47
+ """
48
+ response = self.whatsapp_driver.send_image_message(image_message)
49
+
50
+ return response
51
+
52
+ def send_location_message(self, location_message: models.LocationMessage):
53
+ response = self.whatsapp_driver.send_location_message(location_message)
54
+
55
+ return response
56
+
57
+ def send_template_message(self, template: TemplateMessage):
58
+ """
59
+ Send a template message using the WhatsApp API
60
+
61
+ :param recipient_phone_number: The phone number of the recipient.
62
+ :param template_name: The name of the template to be sent.
63
+ """
64
+ response = self.whatsapp_driver.send_template_message(template)
65
+
66
+ return response
@@ -0,0 +1,13 @@
1
+ from .image_message import ImageMessage
2
+ from .location_message import LocationMessage
3
+ from .message_reaction import MessageReaction
4
+ from .template_message import TemplateMessage
5
+ from .text_message import TextMessage
6
+
7
+ __all__ = [
8
+ "ImageMessage",
9
+ "LocationMessage",
10
+ "MessageReaction",
11
+ "TemplateMessage",
12
+ "TextMessage",
13
+ ]
@@ -0,0 +1,23 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class ImageMessage:
6
+
7
+ to: str
8
+ image: dict[str, str]
9
+ messaging_product: str = "whatsapp"
10
+ recipient_type: str = "individual"
11
+ type: str = "image"
12
+
13
+ def __init__(self, id: str, to: str):
14
+ """
15
+ Args:
16
+ message_id: The ID of the message to react to.
17
+ emoji: The emoji to use for the image.
18
+ to: The recipient's phone number in the format 1234567890'.
19
+ """
20
+ self.to = to
21
+ self.image = {
22
+ "id": id,
23
+ }
@@ -0,0 +1,32 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class LocationMessage:
6
+
7
+ to: str
8
+ location: dict[str, str]
9
+ messaging_product: str = "whatsapp"
10
+ type: str = "location"
11
+
12
+ def __init__(
13
+ self,
14
+ to: str,
15
+ longitude: str,
16
+ latitude: str,
17
+ name: str,
18
+ address: str,
19
+ ):
20
+ """
21
+ Args:
22
+ message_id: The ID of the message to react to.
23
+ emoji: The emoji to use for the image.
24
+ to: The recipient's phone number in the format 1234567890'.
25
+ """
26
+ self.to = to
27
+ self.location = {
28
+ 'latitude': latitude,
29
+ 'longitude': longitude,
30
+ 'name': name,
31
+ 'address': address,
32
+ }
@@ -0,0 +1,24 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class MessageReaction:
6
+
7
+ to: str
8
+ reaction: dict[str, str]
9
+ messaging_product: str = "whatsapp"
10
+ recipient_type: str = "individual"
11
+ type: str = "reaction"
12
+
13
+ def __init__(self, message_id: str, emoji, to: str):
14
+ """
15
+ Args:
16
+ message_id: The ID of the message to react to.
17
+ emoji: The emoji to use for the reaction.
18
+ to: The recipient's phone number in the format 1234567890'.
19
+ """
20
+ self.to = to
21
+ self.reaction = {
22
+ "message_id": message_id,
23
+ "emoji": emoji,
24
+ }
@@ -0,0 +1,49 @@
1
+ from dataclasses import asdict, dataclass
2
+
3
+
4
+ @dataclass
5
+ class ComponentHeader:
6
+ parameters: list[dict[str, str]]
7
+ type: str = 'header'
8
+
9
+ def __init__(self, parameters):
10
+ self.parameters = [asdict(parameter) for parameter in parameters]
11
+
12
+
13
+ @dataclass
14
+ class ComponentBody:
15
+ parameters: list[dict[str, str]]
16
+ type: str = 'body'
17
+
18
+ def __init__(self, parameters):
19
+ self.parameters = [asdict(parameter) for parameter in parameters]
20
+
21
+
22
+ @dataclass
23
+ class ComponentFooter:
24
+ parameters: list[dict[str, str]]
25
+ type: str = 'footer'
26
+
27
+ def __init__(self, parameters):
28
+ self.parameters = [asdict(parameter) for parameter in parameters]
29
+
30
+
31
+ @dataclass
32
+ class ComponentButton:
33
+ parameters: list[dict[str, str]]
34
+ sub_type: str = 'quick_reply'
35
+ index: str = '0'
36
+ type: str = 'button'
37
+
38
+ def __init__(self, parameters):
39
+ self.parameters = [asdict(parameter) for parameter in parameters]
40
+
41
+
42
+ @dataclass
43
+ class TemplateComponent:
44
+ type: str
45
+ parameters: list[dict[str, str]]
46
+
47
+ def __init__(self, type: str, parameters):
48
+ self.type = type
49
+ self.parameters = [asdict(parameter) for parameter in parameters]
@@ -0,0 +1,24 @@
1
+ from dataclasses import asdict, dataclass
2
+
3
+ from .template_componenets import TemplateComponent
4
+
5
+
6
+ @dataclass
7
+ class TemplateMessage:
8
+ to: str
9
+ template: dict[str, str]
10
+ messaging_product: str = "whatsapp"
11
+ type: str = "template"
12
+
13
+ def __init__(
14
+ self,
15
+ to: str,
16
+ template_name: str,
17
+ components: list[TemplateComponent],
18
+ ):
19
+ self.to = to
20
+ self.template = {
21
+ 'name': template_name,
22
+ "language": {"code": "pt_BR"},
23
+ 'components': [asdict(component) for component in components]
24
+ }
@@ -0,0 +1,39 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class PayloadParameter:
6
+ payload: str
7
+ type: str = 'payload'
8
+
9
+ def __init__(self, payload: str):
10
+ self.payload = payload
11
+
12
+
13
+ @dataclass
14
+ class ImageParameter:
15
+ image: dict[str, str]
16
+ type: str = 'image'
17
+
18
+ def __init__(self, image_link: str):
19
+ self.image = {'link': image_link}
20
+
21
+
22
+ @dataclass
23
+ class TextParameter:
24
+ text: dict[str, str]
25
+ type: str = 'text'
26
+
27
+ def __init__(self, text_content: str):
28
+ self.text = text_content
29
+
30
+
31
+ @dataclass
32
+ class NamedTextParameter:
33
+ parameter_name: str
34
+ text: str
35
+ type: str = 'text'
36
+
37
+ def __init__(self, parameter_name: str, value: str):
38
+ self.parameter_name = parameter_name
39
+ self.text = value
@@ -0,0 +1,32 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class TextMessage:
6
+ """
7
+ Represents a text message in the WhatsApp application
8
+
9
+ Attributes:
10
+ sender (str): The sender of the message.
11
+ recipient (str): The recipient of the message.
12
+ content (str): The content of the message.
13
+ timestamp (str): The time when the message was sent.
14
+ """
15
+
16
+ to: str
17
+ text: dict[str, str]
18
+ messaging_product: str = "whatsapp"
19
+ recipient_type: str = "individual"
20
+ type: str = "text"
21
+
22
+ def __init__(self, message_content: str, to: str):
23
+ """
24
+ Args:
25
+ message_content: The content of the message.
26
+ to: The recipient of the message.
27
+ """
28
+ self.to = to
29
+ self.text = {
30
+ 'preview_url': False,
31
+ 'body': message_content
32
+ }
wazzup/whatsapp.py ADDED
@@ -0,0 +1,117 @@
1
+ from dataclasses import asdict
2
+ from urllib.parse import urljoin
3
+
4
+ import requests
5
+
6
+ from src.wazzup import models
7
+
8
+
9
+ class WhatsAppDriver:
10
+ BASE_URL = "https://graph.facebook.com/v22.0/"
11
+ RESOURCE_PATH = "{phone_number}/messages"
12
+
13
+ def __init__(self, access_token, phone_number_id):
14
+ self.access_token = access_token
15
+ self.url = urljoin(
16
+ self.BASE_URL,
17
+ self.RESOURCE_PATH.format(phone_number=phone_number_id),
18
+ )
19
+
20
+ def _get_common_headers(self) -> dict[str, str]:
21
+ """
22
+ Get standard headers for json response
23
+ """
24
+ headers = {
25
+ "Accept": "application/json",
26
+ "Content-Type": "application/json",
27
+ "Authorization": f"Bearer {self.access_token}",
28
+ }
29
+
30
+ return headers
31
+
32
+ def _make_request(
33
+ self,
34
+ method: str,
35
+ url: str,
36
+ data: dict[str, str],
37
+ ) -> None:
38
+ """
39
+ Perform requests to PagBank API endpoints
40
+ """
41
+ headers = self._get_common_headers()
42
+ response = requests.request(method, url, json=data, headers=headers)
43
+ response.raise_for_status()
44
+ return response
45
+
46
+ def send_text_message(self, text_message: models.TextMessage):
47
+ payload = asdict(text_message)
48
+
49
+ response = self._make_request(
50
+ method="POST",
51
+ url=self.url,
52
+ data=payload,
53
+ )
54
+
55
+ return response
56
+
57
+ def reply_message(
58
+ self,
59
+ text_message: models.TextMessage,
60
+ message_id,
61
+ ):
62
+ payload = asdict(text_message)
63
+ payload["context"] = {"message_id": message_id}
64
+
65
+ response = self._make_request(
66
+ method="POST",
67
+ url=self.url,
68
+ data=payload,
69
+ )
70
+
71
+ return response
72
+
73
+ def react_to_message(
74
+ self,
75
+ message_reactoin: models.MessageReaction,
76
+ ):
77
+ payload = asdict(message_reactoin)
78
+ response = self._make_request(
79
+ method="POST",
80
+ url=self.url,
81
+ data=payload,
82
+ )
83
+
84
+ return response
85
+
86
+ def send_image_message(self, image_message: models.ImageMessage):
87
+ payload = asdict(image_message)
88
+
89
+ response = self._make_request(
90
+ method="POST",
91
+ url=self.url,
92
+ data=payload,
93
+ )
94
+
95
+ return response
96
+
97
+ def send_location_message(self, location_message: models.LocationMessage):
98
+ payload = asdict(location_message)
99
+
100
+ response = self._make_request(
101
+ method="POST",
102
+ url=self.url,
103
+ data=payload,
104
+ )
105
+
106
+ return response
107
+
108
+ def send_template_message(self, template: models.TemplateMessage):
109
+ payload = asdict(template)
110
+
111
+ response = self._make_request(
112
+ method="POST",
113
+ url=self.url,
114
+ data=payload,
115
+ )
116
+
117
+ return response
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: wazzup
3
+ Version: 0.0.1
4
+ Summary: A python package for sending messages using the official Whatsapp API
5
+ Author-email: Rafael model <rafael.model@d7.dev>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/7ws/wazzup
8
+ Project-URL: Issues, https://github.com/7ws/wazzup/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENCE
14
+ Dynamic: license-file
15
+
16
+ # WaZZup
17
+
18
+
@@ -0,0 +1,16 @@
1
+ wazzup/__init__.py,sha256=ozt_ApCbHm8Gc4DMFpeM_DXy8it_E3xO_uzsQ06PVgU,57
2
+ wazzup/messaging.py,sha256=CeAoq9EnAjlxNid6qV9fROugnHzU4Nyrk3BLm7DfZvQ,1933
3
+ wazzup/whatsapp.py,sha256=Gvdmom3S-68I5En-A4tK04Dxs781jSWzmXUXSVDQ29U,2885
4
+ wazzup/models/__init__.py,sha256=GF7gr47OX_mwa_oGbob7DphsNpGS9vuO5VYhWt4JsgI,339
5
+ wazzup/models/image_message.py,sha256=5qtVUQ-XSsK-Ba3q47KTMLGDH7huDfNYxiNmF3nH1Y0,548
6
+ wazzup/models/location_message.py,sha256=HUT4CSCvyY5Mwjkphv5NHrRT1W2qZ5XJuUSi13CXs8k,729
7
+ wazzup/models/message_reaction.py,sha256=DppTC3xPnsxqvaZG6PFFw3eX5GCSfFxMvzDQtEE5Ats,622
8
+ wazzup/models/template_componenets.py,sha256=ICDPwNuV2unQq5pnYHPlsG67R9WXmTPcBoHrxV9Ftcw,1165
9
+ wazzup/models/template_message.py,sha256=S5_GAjfKJeEWG_X40eV9d7bfnINzlgIyzoLyF9U5waE,578
10
+ wazzup/models/template_parameters.py,sha256=u6JXBpygYCRwiWAi626LExTBlQJYH0T9rJ1hm9KAtbc,741
11
+ wazzup/models/text_message.py,sha256=Q5XNUi42a9Yw4FaxietVELd0_1-TTr9sIx-r2rPjrqA,833
12
+ wazzup-0.0.1.dist-info/licenses/LICENCE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
13
+ wazzup-0.0.1.dist-info/METADATA,sha256=HwlzrY32IclzyHdcq795fd0WeUjaf6NY_uVUnS1Kn8A,527
14
+ wazzup-0.0.1.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
15
+ wazzup-0.0.1.dist-info/top_level.txt,sha256=owQnVeVrCHW8uD_uN5FRgB5IZQBbSMitr99xW122GvY,7
16
+ wazzup-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (79.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ wazzup