whatsapp-python 3.0.2.post1__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.
@@ -0,0 +1,310 @@
1
+ from typing import Any, Dict, Union
2
+
3
+
4
+ @staticmethod
5
+ def is_message(data: Dict[Any, Any]) -> bool:
6
+ """is_message checks if the data received from the webhook is a message.
7
+
8
+ Args:
9
+ data (Dict[Any, Any]): The data received from the webhook
10
+
11
+ Returns:
12
+ bool: True if the data is a message, False otherwise
13
+ """
14
+ data = data["entry"][0]["changes"][0]["value"]
15
+ if "messages" in data:
16
+ return True
17
+ else:
18
+ return False
19
+
20
+
21
+ @staticmethod
22
+ def get_mobile(data: Dict[Any, Any]) -> Union[str, None]:
23
+ """
24
+ Extracts the mobile number of the sender from the data received from the webhook.
25
+
26
+ Args:
27
+ data[dict]: The data received from the webhook
28
+ Returns:
29
+ str: The mobile number of the sender
30
+
31
+ Example:
32
+ >>> from whatsapp import WhatsApp
33
+ >>> whatsapp = WhatsApp(token, phone_number_id)
34
+ >>> mobile = whatsapp.get_mobile(data)
35
+ """
36
+ data = data["entry"][0]["changes"][0]["value"]
37
+ if "contacts" in data:
38
+ return data["contacts"][0]["wa_id"]
39
+
40
+
41
+ @staticmethod
42
+ def get_name(data: Dict[Any, Any]) -> Union[str, None]:
43
+ """
44
+ Extracts the name of the sender from the data received from the webhook.
45
+
46
+ Args:
47
+ data[dict]: The data received from the webhook
48
+ Returns:
49
+ str: The name of the sender
50
+ Example:
51
+ >>> from whatsapp import WhatsApp
52
+ >>> whatsapp = WhatsApp(token, phone_number_id)
53
+ >>> mobile = whatsapp.get_name(data)
54
+ """
55
+ contact = data["entry"][0]["changes"][0]["value"]
56
+ if contact:
57
+ return contact["contacts"][0]["profile"]["name"]
58
+
59
+
60
+ @staticmethod
61
+ def get_message(data: Dict[Any, Any]) -> Union[str, None]:
62
+ """
63
+ Extracts the text message of the sender from the data received from the webhook.
64
+
65
+ Args:
66
+ data[dict]: The data received from the webhook
67
+ Returns:
68
+ str: The text message received from the sender
69
+ Example:
70
+ >>> from whatsapp import WhatsApp
71
+ >>> whatsapp = WhatsApp(token, phone_number_id)
72
+ >>> message = message.get_message(data)
73
+ """
74
+ data = data["entry"][0]["changes"][0]["value"]
75
+ if "messages" in data:
76
+ return data["messages"][0]["text"]["body"]
77
+
78
+
79
+ @staticmethod
80
+ def get_message_id(data: Dict[Any, Any]) -> Union[str, None]:
81
+ """
82
+ Extracts the message id of the sender from the data received from the webhook.
83
+
84
+ Args:
85
+ data[dict]: The data received from the webhook
86
+ Returns:
87
+ str: The message id of the sender
88
+ Example:
89
+ >>> from whatsapp import WhatsApp
90
+ >>> whatsapp = WhatsApp(token, phone_number_id)
91
+ >>> message_id = whatsapp.get_message_id(data)
92
+ """
93
+ data = data["entry"][0]["changes"][0]["value"]
94
+ if "messages" in data:
95
+ return data["messages"][0]["id"]
96
+
97
+
98
+ @staticmethod
99
+ def get_message_timestamp(data: Dict[Any, Any]) -> Union[str, None]:
100
+ """ "
101
+ Extracts the timestamp of the message from the data received from the webhook.
102
+
103
+ Args:
104
+ data[dict]: The data received from the webhook
105
+ Returns:
106
+ str: The timestamp of the message
107
+ Example:
108
+ >>> from whatsapp import WhatsApp
109
+ >>> whatsapp = WhatsApp(token, phone_number_id)
110
+ >>> whatsapp.get_message_timestamp(data)
111
+ """
112
+ data = data["entry"][0]["changes"][0]["value"]
113
+ if "messages" in data:
114
+ return data["messages"][0]["timestamp"]
115
+
116
+
117
+ @staticmethod
118
+ def get_interactive_response(data: Dict[Any, Any]) -> Union[Dict, None]:
119
+ """
120
+ Extracts the response of the interactive message from the data received from the webhook.
121
+
122
+ Args:
123
+ data[dict]: The data received from the webhook
124
+ Returns:
125
+ dict: The response of the interactive message
126
+
127
+ Example:
128
+ >>> from whatsapp import WhatsApp
129
+ >>> whatsapp = WhatsApp(token, phone_number_id)
130
+ >>> response = whatsapp.get_interactive_response(data)
131
+ >>> interactive_type = response.get("type")
132
+ >>> message_id = response[interactive_type]["id"]
133
+ >>> message_text = response[interactive_type]["title"]
134
+ """
135
+ data = data["entry"][0]["changes"][0]["value"]
136
+ if "messages" in data:
137
+ if "interactive" in data["messages"][0]:
138
+ return data["messages"][0]["interactive"]
139
+
140
+
141
+ @staticmethod
142
+ def get_location(data: Dict[Any, Any]) -> Union[Dict, None]:
143
+ """
144
+ Extracts the location of the sender from the data received from the webhook.
145
+
146
+ Args:
147
+ data[dict]: The data received from the webhook
148
+
149
+ Returns:
150
+ dict: The location of the sender
151
+
152
+ Example:
153
+ >>> from whatsapp import WhatsApp
154
+ >>> whatsapp = WhatsApp(token, phone_number_id)
155
+ >>> whatsapp.get_location(data)
156
+ """
157
+ data = data["entry"][0]["changes"][0]["value"]
158
+ if "messages" in data:
159
+ if "location" in data["messages"][0]:
160
+ return data["messages"][0]["location"]
161
+
162
+
163
+ @staticmethod
164
+ def get_image(data: Dict[Any, Any]) -> Union[Dict, None]:
165
+ """ "
166
+ Extracts the image of the sender from the data received from the webhook.
167
+
168
+ Args:
169
+ data[dict]: The data received from the webhook
170
+ Returns:
171
+ dict: The image_id of an image sent by the sender
172
+
173
+ Example:
174
+ >>> from whatsapp import WhatsApp
175
+ >>> whatsapp = WhatsApp(token, phone_number_id)
176
+ >>> image_id = whatsapp.get_image(data)
177
+ """
178
+ data = data["entry"][0]["changes"][0]["value"]
179
+ if "messages" in data:
180
+ if "image" in data["messages"][0]:
181
+ return data["messages"][0]["image"]
182
+
183
+
184
+ @staticmethod
185
+ def get_document(data: Dict[Any, Any]) -> Union[Dict, None]:
186
+ """ "
187
+ Extracts the document of the sender from the data received from the webhook.
188
+
189
+ Args:
190
+ data[dict]: The data received from the webhook
191
+ Returns:
192
+ dict: The document_id of an image sent by the sender
193
+
194
+ Example:
195
+ >>> from whatsapp import WhatsApp
196
+ >>> whatsapp = WhatsApp(token, phone_number_id)
197
+ >>> document_id = whatsapp.get_document(data)
198
+ """
199
+ data = data["entry"][0]["changes"][0]["value"]
200
+ if "messages" in data:
201
+ if "document" in data["messages"][0]:
202
+ return data["messages"][0]["document"]
203
+
204
+
205
+ @staticmethod
206
+ def get_audio(data: Dict[Any, Any]) -> Union[Dict, None]:
207
+ """
208
+ Extracts the audio of the sender from the data received from the webhook.
209
+
210
+ Args:
211
+ data[dict]: The data received from the webhook
212
+
213
+ Returns:
214
+ dict: The audio of the sender
215
+
216
+ Example:
217
+ >>> from whatsapp import WhatsApp
218
+ >>> whatsapp = WhatsApp(token, phone_number_id)
219
+ >>> whatsapp.get_audio(data)
220
+ """
221
+ data = data["entry"][0]["changes"][0]["value"]
222
+ if "messages" in data:
223
+ if "audio" in data["messages"][0]:
224
+ return data["messages"][0]["audio"]
225
+
226
+
227
+ @staticmethod
228
+ def get_video(data: Dict[Any, Any]) -> Union[Dict, None]:
229
+ """
230
+ Extracts the video of the sender from the data received from the webhook.
231
+
232
+ Args:
233
+ data[dict]: The data received from the webhook
234
+
235
+ Returns:
236
+ dict: Dictionary containing the video details sent by the sender
237
+
238
+ Example:
239
+ >>> from whatsapp import WhatsApp
240
+ >>> whatsapp = WhatsApp(token, phone_number_id)
241
+ >>> whatsapp.get_video(data)
242
+ """
243
+ data = data["entry"][0]["changes"][0]["value"]
244
+ if "messages" in data:
245
+ if "video" in data["messages"][0]:
246
+ return data["messages"][0]["video"]
247
+
248
+
249
+ @staticmethod
250
+ def get_message_type(data: Dict[Any, Any]) -> Union[str, None]:
251
+ """
252
+ Gets the type of the message sent by the sender from the data received from the webhook.
253
+
254
+
255
+ Args:
256
+ data [dict]: The data received from the webhook
257
+
258
+ Returns:
259
+ str: The type of the message sent by the sender
260
+
261
+ Example:
262
+ >>> from whatsapp import WhatsApp
263
+ >>> whatsapp = WhatsApp(token, phone_number_id)
264
+ >>> whatsapp.get_message_type(data)
265
+ """
266
+ data = data["entry"][0]["changes"][0]["value"]
267
+ if "messages" in data:
268
+ return data["messages"][0]["type"]
269
+
270
+
271
+ @staticmethod
272
+ def get_delivery(data: Dict[Any, Any]) -> Union[Dict, None]:
273
+ """
274
+ Extracts the delivery status of the message from the data received from the webhook.
275
+ Args:
276
+ data [dict]: The data received from the webhook
277
+
278
+ Returns:
279
+ dict: The delivery status of the message and message id of the message
280
+ """
281
+ data = data["entry"][0]["changes"][0]["value"]
282
+ if "statuses" in data:
283
+ return data["statuses"][0]["status"]
284
+
285
+
286
+ @staticmethod
287
+ def changed_field(data: Dict[Any, Any]) -> str:
288
+ """
289
+ Helper function to check if the field changed in the data received from the webhook.
290
+
291
+ Args:
292
+ data [dict]: The data received from the webhook
293
+
294
+ Returns:
295
+ str: The field changed in the data received from the webhook
296
+
297
+ Example:
298
+ >>> from whatsapp import WhatsApp
299
+ >>> whatsapp = WhatsApp(token, phone_number_id)
300
+ >>> whatsapp.changed_field(data)
301
+ """
302
+ return data["entry"][0]["changes"][0]["field"]
303
+
304
+
305
+ @staticmethod
306
+ def get_author(data: Dict[Any, Any]) -> Union[str, None]:
307
+ try:
308
+ return data["entry"][0]["changes"][0]["value"]["messages"][0]["from"]
309
+ except Exception:
310
+ return None
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.1
2
+ Name: whatsapp-python
3
+ Version: 3.0.2.post1
4
+ Summary: Open source Python wrapper for the WhatsApp Cloud API
5
+ Project-URL: Homepage, https://github.com/filipporomani/whatsapp
6
+ Project-URL: Bug Tracker, https://github.com/filipporomani/whatsapp/issues
7
+ Project-URL: Download, https://github.com/filipporomani/whatsapp/releases/latest
8
+ Author-email: Filippo Romani <mail@filipporomani.it>
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3.6
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Topic :: Software Development :: Build Tools
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+
23
+ # [whatsapp-python](https://pypi.org/project/whatsapp-python/)
24
+
25
+ ![Made in Italy](https://img.shields.io/badge/made%20in-italy-008751.svg?style=flat-square)
26
+ [![Downloads](https://static.pepy.tech/personalized-badge/whatsapp-python?period=total&units=none&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/whatsapp-python)
27
+ [![Downloads](https://pepy.tech/badge/whatsapp-python/month)](https://pepy.tech/project/whatsapp-python)
28
+ [![Downloads](https://pepy.tech/badge/whatsapp-python/week)](https://pepy.tech/project/whatsapp-python)
29
+
30
+ Free, open-source Python wrapper for the [WhatsApp Cloud API](https://developers.facebook.com/docs/whatsapp/cloud-api).
31
+
32
+ Forked from [Neurotech-HQ/heyoo](https://github.com/Neurotech-HQ/heyoo)
33
+
34
+ ## Supported features
35
+
36
+ 1. Listening to events (messages, media, etc.)
37
+ 2. Sending messages
38
+ 3. Marking messages as read
39
+ 4. Sending Media (images, audio, video and documents)
40
+ 5. Sending location
41
+ 6. Sending interactive buttons
42
+ 7. Sending template messages
43
+ 8. Parsing messages and media received
44
+
45
+ ## App events
46
+
47
+ Asynchronous app events are now available!
48
+
49
+ The docs are available in the [wiki](https://github.com/filipporomani/whatsapp/wiki/App-events)
50
+
51
+ Leave feedbacks/report issues freely on GitHub! I'll be glad to help you!
52
+
53
+
54
+ ## Installation
55
+
56
+ To install the library you can either use pip (latest release version):
57
+
58
+ ``pip install whatsapp-python``
59
+
60
+ or git (latest development version):
61
+
62
+ ```bash
63
+ git clone https://github.com/filipporomani/whatsapp.git
64
+ cd whatsapp
65
+ python3 setup.py install
66
+ ```
67
+
68
+ ## Documentation
69
+
70
+ The documentation for the library is available under the [**wiki**](https://github.com/filipporomani/whatsapp/wiki) section on GitHub.
71
+
72
+ ## Costs of the API
73
+
74
+ While using third-party API providers of the WhatsApp API may have some monthly fees, using the WhatsApp API provided directly by Facebook is way cheaper, even if the billing docs are pretty hard to understand.
75
+ The first 1000 chats created are free, then there is a pay-as-you-go fee that is paid for each conversation started.
76
+
77
+ **IMPORTANT**: it is now mandatory (at least it was for me) to add a credit card to the whatsapp account to use the service. I eventually got billed for using a non-test number (~1,20€), so be carefull using the API!
78
+
79
+ All the prices are available in the [**WhatsApp API docs**](https://developers.facebook.com/docs/whatsapp/pricing)
80
+
81
+ ## Switching from `Neurotech-HQ/heyoo`
82
+ Any version >1.1.2 is incompatible with the original `heyoo` library! Be careful updating! Read the docs first!
83
+ Any version <=1.1.2 is fully compatible with the original `heyoo` library and doesn't include any breaking change..
84
+ You can ignore this warning if it's your first time using the library.
85
+
86
+
87
+ Switching from heyoo to whatsapp-python doesn't require any change for versions up to 1.1.2: just uninstall `heyoo`, install `whatsapp-python==1.1.2` and change the import name from `heyoo` to `whatsapp`.
88
+ For version which are GREATER THEN 1.1.2, messages have became objects, so you need to change your code to use the new methods.
89
+
90
+ **Note**: docs for version 1.1.2 are available in the [**dedicated wiki page**](https://github.com/filipporomani/whatsapp/wiki/v1.1.2).
91
+
92
+
93
+
94
+
95
+ ## Issues
96
+
97
+ If you are facing any issues or have any questions, please open an issue on the [**GitHub repository**](https://github.com/filipporomani/whatsapp/issues)
98
+
99
+ ## Contributing
100
+
101
+ This is an opensource project published under the ```MIT License```: [**LICENSE**](LICENSE).
102
+
103
+ ## References
104
+
105
+ 1. [WhatsApp Cloud API official documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/)
@@ -0,0 +1,25 @@
1
+ setup.py,sha256=iYla9PqaVtjAQtMDnLvNixkoqpw_MHhAG9dN5Wk0OlU,1535
2
+ examples/example_hook_obj.py,sha256=jlw6kF-BX_ZoYZnUs5yqDqzklQm-wjXO8bQecIRH3U8,3053
3
+ examples/reply_to_message_obj.py,sha256=CNseOMXEDA9y5V8o0y4cQhwf9_vN5drsVg5xu3kYp3M,346
4
+ examples/sending_audio.py,sha256=AAjIgNobQqqmVqz_IlawR1qeX9JpLUeVE3XbZANFFqw,441
5
+ examples/sending_button.py,sha256=CULZ9kpnIn17e6__ZrYy-VGxuY87AU8zSqd4UqHqvdA,1088
6
+ examples/sending_document.py,sha256=C5ofmLuWrLLFnn-JSw4qqDciTd6b1Cg4Kcuiht2qWa4,436
7
+ examples/sending_image.py,sha256=Kw4Wo-HjRsHhBXoGxElPak2zmvEwZqTJFOmtvcN14lY,412
8
+ examples/sending_location.py,sha256=qyP5vMkPx7x97AZD4q7ptPz7aEF0QELN84Sx_p0GRsA,462
9
+ examples/sending_message.py,sha256=QYPM1JigdB7nIcSdZqzcJ_y9wCx5VB0vKSwHPMpCNUE,415
10
+ examples/sending_template_message.py,sha256=tXO8LPXdLq21m8RaLS4m0GArMFKi61N0mvbicGiAJow,388
11
+ examples/sending_video.py,sha256=LtlKf-GlMU36L_3WBf6XIcjQlaSK0GcIECTt_iRXgCg,423
12
+ examples/standalone_hook.py,sha256=9MGmLB92IUg5lj1sTpWs-0k_85E8IfHOOpffUsr-Aq8,5330
13
+ whatsapp/__init__.py,sha256=6UCaboat6usACDvLVolJZFrhXNzlM5ZIoUd1bu8RMPI,9526
14
+ whatsapp/constants.py,sha256=YJQsH6Ppwk6OxHMaF0YJSYUNvozTwIb_DgqBZYxobVc,46
15
+ whatsapp/ext/_buttons.py,sha256=GKgxDsansBf4dm4UtZWa-Y-P5ag0TCo36badqyS5fFU,2922
16
+ whatsapp/ext/_media.py,sha256=S8kLfFbZQ1zDCNjdFr5jQYBnuo7tp9FMGsZOGb-h23o,4511
17
+ whatsapp/ext/_message.py,sha256=_0E47iqKdP6YsFXSbSFHJ7TLzL5cSfUiHqbG17FN0Lg,3792
18
+ whatsapp/ext/_property.py,sha256=QS4FjWw21lyLuHnXGy7-2MCP-p0VoMw0gRpgu0OByO8,128
19
+ whatsapp/ext/_send_media.py,sha256=aLdq4a0CyYa_ZNy8KOXEdX2rwA79RbCPp-thMjVxvh0,10036
20
+ whatsapp/ext/_send_others.py,sha256=9Z2zV64Ygxu0LmN9Oy_oomwtgUbk3ZIFEF_3RWxkUDM,2934
21
+ whatsapp/ext/_static.py,sha256=6T9CmHD3XBAH3e2T-w9je1mOfC1HwdBIMaRQjBdR_cQ,9513
22
+ whatsapp_python-3.0.2.post1.dist-info/METADATA,sha256=wOvl_K_5U9peuR8peIRPSCcjsrMLnFCsobQ9qRKOGns,4583
23
+ whatsapp_python-3.0.2.post1.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
24
+ whatsapp_python-3.0.2.post1.dist-info/licenses/LICENSE,sha256=HnVLQg1StPmnEJfysP2uUtgEGJ2NsZjAT_5y1WsV8RU,1092
25
+ whatsapp_python-3.0.2.post1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.18.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 FILIPPO ROMANI
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.