whatsapp-python 3.3.5.dev0__py3-none-any.whl → 3.3.9__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.
- whatsapp/__init__.py +386 -386
- whatsapp/constants.py +4 -4
- whatsapp/ext/_buttons.py +82 -82
- whatsapp/ext/_media.py +135 -135
- whatsapp/ext/_message.py +124 -124
- whatsapp/ext/_property.py +5 -5
- whatsapp/ext/_send_media.py +364 -267
- whatsapp/ext/_send_others.py +118 -86
- whatsapp/ext/_static.py +329 -329
- {whatsapp_python-3.3.5.dev0.dist-info → whatsapp_python-3.3.9.dist-info}/METADATA +1 -1
- whatsapp_python-3.3.9.dist-info/RECORD +13 -0
- {whatsapp_python-3.3.5.dev0.dist-info → whatsapp_python-3.3.9.dist-info}/licenses/LICENSE +21 -21
- whatsapp_python-3.3.5.dev0.dist-info/RECORD +0 -13
- {whatsapp_python-3.3.5.dev0.dist-info → whatsapp_python-3.3.9.dist-info}/WHEEL +0 -0
whatsapp/ext/_static.py
CHANGED
|
@@ -1,329 +1,329 @@
|
|
|
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
|
-
@staticmethod
|
|
184
|
-
def get_sticker(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
185
|
-
""" "
|
|
186
|
-
Extracts the sticker of the sender from the data received from the webhook.
|
|
187
|
-
|
|
188
|
-
Args:
|
|
189
|
-
data[dict]: The data received from the webhook
|
|
190
|
-
Returns:
|
|
191
|
-
dict: The sticker_id of an sticker sent by the sender
|
|
192
|
-
|
|
193
|
-
Example:
|
|
194
|
-
>>> from whatsapp import WhatsApp
|
|
195
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
196
|
-
>>> sticker_id = whatsapp.get_sticker(data)
|
|
197
|
-
"""
|
|
198
|
-
data = data["entry"][0]["changes"][0]["value"]
|
|
199
|
-
if "messages" in data:
|
|
200
|
-
if "sticker" in data["messages"][0]:
|
|
201
|
-
return data["messages"][0]["sticker"]
|
|
202
|
-
|
|
203
|
-
@staticmethod
|
|
204
|
-
def get_document(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
205
|
-
""" "
|
|
206
|
-
Extracts the document of the sender from the data received from the webhook.
|
|
207
|
-
|
|
208
|
-
Args:
|
|
209
|
-
data[dict]: The data received from the webhook
|
|
210
|
-
Returns:
|
|
211
|
-
dict: The document_id of an image sent by the sender
|
|
212
|
-
|
|
213
|
-
Example:
|
|
214
|
-
>>> from whatsapp import WhatsApp
|
|
215
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
216
|
-
>>> document_id = whatsapp.get_document(data)
|
|
217
|
-
"""
|
|
218
|
-
data = data["entry"][0]["changes"][0]["value"]
|
|
219
|
-
if "messages" in data:
|
|
220
|
-
if "document" in data["messages"][0]:
|
|
221
|
-
return data["messages"][0]["document"]
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
@staticmethod
|
|
225
|
-
def get_audio(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
226
|
-
"""
|
|
227
|
-
Extracts the audio of the sender from the data received from the webhook.
|
|
228
|
-
|
|
229
|
-
Args:
|
|
230
|
-
data[dict]: The data received from the webhook
|
|
231
|
-
|
|
232
|
-
Returns:
|
|
233
|
-
dict: The audio of the sender
|
|
234
|
-
|
|
235
|
-
Example:
|
|
236
|
-
>>> from whatsapp import WhatsApp
|
|
237
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
238
|
-
>>> whatsapp.get_audio(data)
|
|
239
|
-
"""
|
|
240
|
-
data = data["entry"][0]["changes"][0]["value"]
|
|
241
|
-
if "messages" in data:
|
|
242
|
-
if "audio" in data["messages"][0]:
|
|
243
|
-
return data["messages"][0]["audio"]
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
@staticmethod
|
|
247
|
-
def get_video(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
248
|
-
"""
|
|
249
|
-
Extracts the video of the sender from the data received from the webhook.
|
|
250
|
-
|
|
251
|
-
Args:
|
|
252
|
-
data[dict]: The data received from the webhook
|
|
253
|
-
|
|
254
|
-
Returns:
|
|
255
|
-
dict: Dictionary containing the video details sent by the sender
|
|
256
|
-
|
|
257
|
-
Example:
|
|
258
|
-
>>> from whatsapp import WhatsApp
|
|
259
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
260
|
-
>>> whatsapp.get_video(data)
|
|
261
|
-
"""
|
|
262
|
-
data = data["entry"][0]["changes"][0]["value"]
|
|
263
|
-
if "messages" in data:
|
|
264
|
-
if "video" in data["messages"][0]:
|
|
265
|
-
return data["messages"][0]["video"]
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
@staticmethod
|
|
269
|
-
def get_message_type(data: Dict[Any, Any]) -> Union[str, None]:
|
|
270
|
-
"""
|
|
271
|
-
Gets the type of the message sent by the sender from the data received from the webhook.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
Args:
|
|
275
|
-
data [dict]: The data received from the webhook
|
|
276
|
-
|
|
277
|
-
Returns:
|
|
278
|
-
str: The type of the message sent by the sender
|
|
279
|
-
|
|
280
|
-
Example:
|
|
281
|
-
>>> from whatsapp import WhatsApp
|
|
282
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
283
|
-
>>> whatsapp.get_message_type(data)
|
|
284
|
-
"""
|
|
285
|
-
data = data["entry"][0]["changes"][0]["value"]
|
|
286
|
-
if "messages" in data:
|
|
287
|
-
return data["messages"][0]["type"]
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
@staticmethod
|
|
291
|
-
def get_delivery(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
292
|
-
"""
|
|
293
|
-
Extracts the delivery status of the message from the data received from the webhook.
|
|
294
|
-
Args:
|
|
295
|
-
data [dict]: The data received from the webhook
|
|
296
|
-
|
|
297
|
-
Returns:
|
|
298
|
-
dict: The delivery status of the message and message id of the message
|
|
299
|
-
"""
|
|
300
|
-
data = data["entry"][0]["changes"][0]["value"]
|
|
301
|
-
if "statuses" in data:
|
|
302
|
-
return data["statuses"][0]["status"]
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
@staticmethod
|
|
306
|
-
def changed_field(data: Dict[Any, Any]) -> str:
|
|
307
|
-
"""
|
|
308
|
-
Helper function to check if the field changed in the data received from the webhook.
|
|
309
|
-
|
|
310
|
-
Args:
|
|
311
|
-
data [dict]: The data received from the webhook
|
|
312
|
-
|
|
313
|
-
Returns:
|
|
314
|
-
str: The field changed in the data received from the webhook
|
|
315
|
-
|
|
316
|
-
Example:
|
|
317
|
-
>>> from whatsapp import WhatsApp
|
|
318
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
319
|
-
>>> whatsapp.changed_field(data)
|
|
320
|
-
"""
|
|
321
|
-
return data["entry"][0]["changes"][0]["field"]
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
@staticmethod
|
|
325
|
-
def get_author(data: Dict[Any, Any]) -> Union[str, None]:
|
|
326
|
-
try:
|
|
327
|
-
return data["entry"][0]["changes"][0]["value"]["messages"][0]["from"]
|
|
328
|
-
except Exception:
|
|
329
|
-
return None
|
|
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
|
+
@staticmethod
|
|
184
|
+
def get_sticker(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
185
|
+
""" "
|
|
186
|
+
Extracts the sticker of the sender from the data received from the webhook.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
data[dict]: The data received from the webhook
|
|
190
|
+
Returns:
|
|
191
|
+
dict: The sticker_id of an sticker sent by the sender
|
|
192
|
+
|
|
193
|
+
Example:
|
|
194
|
+
>>> from whatsapp import WhatsApp
|
|
195
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
196
|
+
>>> sticker_id = whatsapp.get_sticker(data)
|
|
197
|
+
"""
|
|
198
|
+
data = data["entry"][0]["changes"][0]["value"]
|
|
199
|
+
if "messages" in data:
|
|
200
|
+
if "sticker" in data["messages"][0]:
|
|
201
|
+
return data["messages"][0]["sticker"]
|
|
202
|
+
|
|
203
|
+
@staticmethod
|
|
204
|
+
def get_document(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
205
|
+
""" "
|
|
206
|
+
Extracts the document of the sender from the data received from the webhook.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
data[dict]: The data received from the webhook
|
|
210
|
+
Returns:
|
|
211
|
+
dict: The document_id of an image sent by the sender
|
|
212
|
+
|
|
213
|
+
Example:
|
|
214
|
+
>>> from whatsapp import WhatsApp
|
|
215
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
216
|
+
>>> document_id = whatsapp.get_document(data)
|
|
217
|
+
"""
|
|
218
|
+
data = data["entry"][0]["changes"][0]["value"]
|
|
219
|
+
if "messages" in data:
|
|
220
|
+
if "document" in data["messages"][0]:
|
|
221
|
+
return data["messages"][0]["document"]
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
@staticmethod
|
|
225
|
+
def get_audio(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
226
|
+
"""
|
|
227
|
+
Extracts the audio of the sender from the data received from the webhook.
|
|
228
|
+
|
|
229
|
+
Args:
|
|
230
|
+
data[dict]: The data received from the webhook
|
|
231
|
+
|
|
232
|
+
Returns:
|
|
233
|
+
dict: The audio of the sender
|
|
234
|
+
|
|
235
|
+
Example:
|
|
236
|
+
>>> from whatsapp import WhatsApp
|
|
237
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
238
|
+
>>> whatsapp.get_audio(data)
|
|
239
|
+
"""
|
|
240
|
+
data = data["entry"][0]["changes"][0]["value"]
|
|
241
|
+
if "messages" in data:
|
|
242
|
+
if "audio" in data["messages"][0]:
|
|
243
|
+
return data["messages"][0]["audio"]
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
@staticmethod
|
|
247
|
+
def get_video(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
248
|
+
"""
|
|
249
|
+
Extracts the video of the sender from the data received from the webhook.
|
|
250
|
+
|
|
251
|
+
Args:
|
|
252
|
+
data[dict]: The data received from the webhook
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
dict: Dictionary containing the video details sent by the sender
|
|
256
|
+
|
|
257
|
+
Example:
|
|
258
|
+
>>> from whatsapp import WhatsApp
|
|
259
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
260
|
+
>>> whatsapp.get_video(data)
|
|
261
|
+
"""
|
|
262
|
+
data = data["entry"][0]["changes"][0]["value"]
|
|
263
|
+
if "messages" in data:
|
|
264
|
+
if "video" in data["messages"][0]:
|
|
265
|
+
return data["messages"][0]["video"]
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@staticmethod
|
|
269
|
+
def get_message_type(data: Dict[Any, Any]) -> Union[str, None]:
|
|
270
|
+
"""
|
|
271
|
+
Gets the type of the message sent by the sender from the data received from the webhook.
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
data [dict]: The data received from the webhook
|
|
276
|
+
|
|
277
|
+
Returns:
|
|
278
|
+
str: The type of the message sent by the sender
|
|
279
|
+
|
|
280
|
+
Example:
|
|
281
|
+
>>> from whatsapp import WhatsApp
|
|
282
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
283
|
+
>>> whatsapp.get_message_type(data)
|
|
284
|
+
"""
|
|
285
|
+
data = data["entry"][0]["changes"][0]["value"]
|
|
286
|
+
if "messages" in data:
|
|
287
|
+
return data["messages"][0]["type"]
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
@staticmethod
|
|
291
|
+
def get_delivery(data: Dict[Any, Any]) -> Union[Dict, None]:
|
|
292
|
+
"""
|
|
293
|
+
Extracts the delivery status of the message from the data received from the webhook.
|
|
294
|
+
Args:
|
|
295
|
+
data [dict]: The data received from the webhook
|
|
296
|
+
|
|
297
|
+
Returns:
|
|
298
|
+
dict: The delivery status of the message and message id of the message
|
|
299
|
+
"""
|
|
300
|
+
data = data["entry"][0]["changes"][0]["value"]
|
|
301
|
+
if "statuses" in data:
|
|
302
|
+
return data["statuses"][0]["status"]
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
@staticmethod
|
|
306
|
+
def changed_field(data: Dict[Any, Any]) -> str:
|
|
307
|
+
"""
|
|
308
|
+
Helper function to check if the field changed in the data received from the webhook.
|
|
309
|
+
|
|
310
|
+
Args:
|
|
311
|
+
data [dict]: The data received from the webhook
|
|
312
|
+
|
|
313
|
+
Returns:
|
|
314
|
+
str: The field changed in the data received from the webhook
|
|
315
|
+
|
|
316
|
+
Example:
|
|
317
|
+
>>> from whatsapp import WhatsApp
|
|
318
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
319
|
+
>>> whatsapp.changed_field(data)
|
|
320
|
+
"""
|
|
321
|
+
return data["entry"][0]["changes"][0]["field"]
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
@staticmethod
|
|
325
|
+
def get_author(data: Dict[Any, Any]) -> Union[str, None]:
|
|
326
|
+
try:
|
|
327
|
+
return data["entry"][0]["changes"][0]["value"]["messages"][0]["from"]
|
|
328
|
+
except Exception:
|
|
329
|
+
return None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: whatsapp-python
|
|
3
|
-
Version: 3.3.
|
|
3
|
+
Version: 3.3.9
|
|
4
4
|
Summary: Open source Python wrapper for the WhatsApp Cloud API
|
|
5
5
|
Project-URL: Homepage, https://github.com/filipporomani/whatsapp-python
|
|
6
6
|
Project-URL: Docs, https://github.com/filipporomani/whatsapp-python/wiki
|