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/_send_media.py
CHANGED
|
@@ -1,267 +1,364 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import requests
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def send_location(self, lat: str, long: str, name: str, address: str, recipient_id: str) -> dict:
|
|
6
|
-
"""
|
|
7
|
-
Sends a location message to a WhatsApp user
|
|
8
|
-
|
|
9
|
-
Args:
|
|
10
|
-
lat[str]: Latitude of the location
|
|
11
|
-
long[str]: Longitude of the location
|
|
12
|
-
name[str]: Name of the location
|
|
13
|
-
address[str]: Address of the location
|
|
14
|
-
recipient_id[str]: Phone number of the user with country code wihout +
|
|
15
|
-
|
|
16
|
-
Example:
|
|
17
|
-
>>> from whatsapp import WhatsApp
|
|
18
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
19
|
-
>>> whatsapp.send_location("-23.564", "-46.654", "My Location", "Rua dois, 123", "5511999999999")
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
data = {
|
|
167
|
-
"messaging_product": "whatsapp",
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
)
|
|
186
|
-
"
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
""
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
1
|
+
import logging
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def send_location(self, lat: str, long: str, name: str, address: str, recipient_id: str, sender = None) -> dict:
|
|
6
|
+
"""
|
|
7
|
+
Sends a location message to a WhatsApp user
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
lat[str]: Latitude of the location
|
|
11
|
+
long[str]: Longitude of the location
|
|
12
|
+
name[str]: Name of the location
|
|
13
|
+
address[str]: Address of the location
|
|
14
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
>>> from whatsapp import WhatsApp
|
|
18
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
19
|
+
>>> whatsapp.send_location("-23.564", "-46.654", "My Location", "Rua dois, 123", "5511999999999")
|
|
20
|
+
"""
|
|
21
|
+
try:
|
|
22
|
+
sender = dict(self.instance.l)[sender]
|
|
23
|
+
print(self.instance.l)
|
|
24
|
+
print(sender)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
print(12)
|
|
28
|
+
|
|
29
|
+
except:
|
|
30
|
+
print(22)
|
|
31
|
+
sender = self.instance.phone_number_id
|
|
32
|
+
|
|
33
|
+
if sender == None:
|
|
34
|
+
sender = self.instance.phone_number_id
|
|
35
|
+
|
|
36
|
+
url = f"https://graph.facebook.com/v18.0/{sender}/messages"
|
|
37
|
+
data = {
|
|
38
|
+
"messaging_product": "whatsapp",
|
|
39
|
+
"to": recipient_id,
|
|
40
|
+
"type": "location",
|
|
41
|
+
"location": {
|
|
42
|
+
"latitude": lat,
|
|
43
|
+
"longitude": long,
|
|
44
|
+
"name": name,
|
|
45
|
+
"address": address,
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
logging.info(f"Sending location to {recipient_id}")
|
|
49
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
50
|
+
if r.status_code == 200:
|
|
51
|
+
logging.info(f"Location sent to {recipient_id}")
|
|
52
|
+
return r.json()
|
|
53
|
+
logging.info(f"Location not sent to {recipient_id}")
|
|
54
|
+
logging.info(f"Status code: {r.status_code}")
|
|
55
|
+
logging.error(r.json())
|
|
56
|
+
return r.json()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def send_image(
|
|
60
|
+
self,
|
|
61
|
+
image: str,
|
|
62
|
+
recipient_id: str,
|
|
63
|
+
recipient_type: str = "individual",
|
|
64
|
+
caption: str = "",
|
|
65
|
+
link: bool = True,
|
|
66
|
+
sender = None
|
|
67
|
+
) -> dict:
|
|
68
|
+
"""
|
|
69
|
+
Sends an image message to a WhatsApp user
|
|
70
|
+
|
|
71
|
+
There are two ways to send an image message to a user, either by passing the image id or by passing the image link.
|
|
72
|
+
Image id is the id of the image uploaded to the cloud api.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
image[str]: Image id or link of the image
|
|
76
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
77
|
+
recipient_type[str]: Type of the recipient, either individual or group
|
|
78
|
+
caption[str]: Caption of the image
|
|
79
|
+
link[bool]: Whether to send an image id or an image link, True means that the image is an id, False means that the image is a link
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
>>> from whatsapp import WhatsApp
|
|
84
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
85
|
+
>>> whatsapp.send_image("https://i.imgur.com/Fh7XVYY.jpeg", "5511999999999")
|
|
86
|
+
"""
|
|
87
|
+
try:
|
|
88
|
+
sender = dict(self.l)[sender]
|
|
89
|
+
print(self.l)
|
|
90
|
+
print(sender)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
print(12)
|
|
94
|
+
|
|
95
|
+
except:
|
|
96
|
+
print(22)
|
|
97
|
+
sender = self.phone_number_id
|
|
98
|
+
|
|
99
|
+
if sender == None:
|
|
100
|
+
sender = self.phone_number_id
|
|
101
|
+
|
|
102
|
+
url = f"https://graph.facebook.com/v18.0/{sender}/messages"
|
|
103
|
+
if link:
|
|
104
|
+
data = {
|
|
105
|
+
"messaging_product": "whatsapp",
|
|
106
|
+
"recipient_type": recipient_type,
|
|
107
|
+
"to": recipient_id,
|
|
108
|
+
"type": "image",
|
|
109
|
+
"image": {"link": image, "caption": caption},
|
|
110
|
+
}
|
|
111
|
+
else:
|
|
112
|
+
data = {
|
|
113
|
+
"messaging_product": "whatsapp",
|
|
114
|
+
"recipient_type": recipient_type,
|
|
115
|
+
"to": recipient_id,
|
|
116
|
+
"type": "image",
|
|
117
|
+
"image": {"id": image, "caption": caption},
|
|
118
|
+
}
|
|
119
|
+
logging.info(f"Sending image to {recipient_id}")
|
|
120
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
121
|
+
if r.status_code == 200:
|
|
122
|
+
logging.info(f"Image sent to {recipient_id}")
|
|
123
|
+
return r.json()
|
|
124
|
+
logging.info(f"Image not sent to {recipient_id}")
|
|
125
|
+
logging.info(f"Status code: {r.status_code}")
|
|
126
|
+
logging.error(r.json())
|
|
127
|
+
return r.json()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def send_sticker(self, sticker: str, recipient_id: str, recipient_type: str = "individual", link: bool = True, sender = None) -> dict:
|
|
131
|
+
"""
|
|
132
|
+
Sends a sticker message to a WhatsApp user
|
|
133
|
+
|
|
134
|
+
There are two ways to send a sticker message to a user, either by passing the image id or by passing the sticker link.
|
|
135
|
+
Sticker id is the id of the sticker uploaded to the cloud api.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
sticker[str]: Sticker id or link of the sticker
|
|
139
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
140
|
+
recipient_type[str]: Type of the recipient, either individual or group
|
|
141
|
+
link[bool]: Whether to send an sticker id or an sticker link, True means that the sticker is an id, False means that the image is a link
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
Example:
|
|
145
|
+
>>> from whatsapp import WhatsApp
|
|
146
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
147
|
+
>>> whatsapp.send_sticker("170511049062862", "5511999999999", link=False)
|
|
148
|
+
"""
|
|
149
|
+
try:
|
|
150
|
+
sender = dict(self.l)[sender]
|
|
151
|
+
print(self.l)
|
|
152
|
+
print(sender)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
print(12)
|
|
156
|
+
|
|
157
|
+
except:
|
|
158
|
+
print(22)
|
|
159
|
+
sender = self.phone_number_id
|
|
160
|
+
|
|
161
|
+
if sender == None:
|
|
162
|
+
sender = self.phone_number_id
|
|
163
|
+
|
|
164
|
+
url = f"https://graph.facebook.com/v18.0/{sender}/messages"
|
|
165
|
+
if link:
|
|
166
|
+
data = {
|
|
167
|
+
"messaging_product": "whatsapp",
|
|
168
|
+
"recipient_type": recipient_type,
|
|
169
|
+
"to": recipient_id,
|
|
170
|
+
"type": "sticker",
|
|
171
|
+
"sticker": {"link": sticker},
|
|
172
|
+
}
|
|
173
|
+
else:
|
|
174
|
+
data = {
|
|
175
|
+
"messaging_product": "whatsapp",
|
|
176
|
+
"recipient_type": recipient_type,
|
|
177
|
+
"to": recipient_id,
|
|
178
|
+
"type": "sticker",
|
|
179
|
+
"sticker": {"id": sticker},
|
|
180
|
+
}
|
|
181
|
+
logging.info(f"Sending sticker to {recipient_id}")
|
|
182
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
183
|
+
if r.status_code == 200:
|
|
184
|
+
logging.info(f"Sticker sent to {recipient_id}")
|
|
185
|
+
return r.json()
|
|
186
|
+
logging.info(f"Sticker not sent to {recipient_id}")
|
|
187
|
+
logging.info(f"Status code: {r.status_code}")
|
|
188
|
+
logging.error(r.json())
|
|
189
|
+
return r.json()
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def send_audio(self, audio: str, recipient_id: str, link: bool = True, sender = None) -> dict:
|
|
193
|
+
"""
|
|
194
|
+
Sends an audio message to a WhatsApp user
|
|
195
|
+
Audio messages can either be sent by passing the audio id or by passing the audio link.
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
audio[str]: Audio id or link of the audio
|
|
199
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
200
|
+
link[bool]: Whether to send an audio id or an audio link, True means that the audio is an id, False means that the audio is a link
|
|
201
|
+
|
|
202
|
+
Example:
|
|
203
|
+
>>> from whatsapp import WhatsApp
|
|
204
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
205
|
+
>>> whatsapp.send_audio("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", "5511999999999")
|
|
206
|
+
"""
|
|
207
|
+
try:
|
|
208
|
+
sender = dict(self.l)[sender]
|
|
209
|
+
print(self.l)
|
|
210
|
+
print(sender)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
print(12)
|
|
214
|
+
|
|
215
|
+
except:
|
|
216
|
+
print(22)
|
|
217
|
+
sender = self.phone_number_id
|
|
218
|
+
|
|
219
|
+
if sender == None:
|
|
220
|
+
sender = self.phone_number_id
|
|
221
|
+
|
|
222
|
+
url = f"https://graph.facebook.com/v18.0/{sender}/messages"
|
|
223
|
+
if link:
|
|
224
|
+
data = {
|
|
225
|
+
"messaging_product": "whatsapp",
|
|
226
|
+
"to": recipient_id,
|
|
227
|
+
"type": "audio",
|
|
228
|
+
"audio": {"link": audio},
|
|
229
|
+
}
|
|
230
|
+
else:
|
|
231
|
+
data = {
|
|
232
|
+
"messaging_product": "whatsapp",
|
|
233
|
+
"to": recipient_id,
|
|
234
|
+
"type": "audio",
|
|
235
|
+
"audio": {"id": audio},
|
|
236
|
+
}
|
|
237
|
+
logging.info(f"Sending audio to {recipient_id}")
|
|
238
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
239
|
+
if r.status_code == 200:
|
|
240
|
+
logging.info(f"Audio sent to {recipient_id}")
|
|
241
|
+
return r.json()
|
|
242
|
+
logging.info(f"Audio not sent to {recipient_id}")
|
|
243
|
+
logging.info(f"Status code: {r.status_code}")
|
|
244
|
+
logging.error(f"Response: {r.json()}")
|
|
245
|
+
return r.json()
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def send_video(
|
|
249
|
+
self, video: str, recipient_id: str, caption: str = "", link: bool = True, sender = None
|
|
250
|
+
) -> dict:
|
|
251
|
+
""" "
|
|
252
|
+
Sends a video message to a WhatsApp user
|
|
253
|
+
Video messages can either be sent by passing the video id or by passing the video link.
|
|
254
|
+
|
|
255
|
+
Args:
|
|
256
|
+
video[str]: Video id or link of the video
|
|
257
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
258
|
+
caption[str]: Caption of the video
|
|
259
|
+
link[bool]: Whether to send a video id or a video link, True means that the video is an id, False means that the video is a link
|
|
260
|
+
|
|
261
|
+
example:
|
|
262
|
+
>>> from whatsapp import WhatsApp
|
|
263
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
264
|
+
>>> whatsapp.send_video("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "5511999999999")
|
|
265
|
+
"""
|
|
266
|
+
try:
|
|
267
|
+
sender = dict(self.l)[sender]
|
|
268
|
+
print(self.l)
|
|
269
|
+
print(sender)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
print(12)
|
|
273
|
+
|
|
274
|
+
except:
|
|
275
|
+
print(22)
|
|
276
|
+
sender = self.phone_number_id
|
|
277
|
+
|
|
278
|
+
if sender == None:
|
|
279
|
+
sender = self.phone_number_id
|
|
280
|
+
|
|
281
|
+
url = f"https://graph.facebook.com/v18.0/{sender}/messages"
|
|
282
|
+
if link:
|
|
283
|
+
data = {
|
|
284
|
+
"messaging_product": "whatsapp",
|
|
285
|
+
"to": recipient_id,
|
|
286
|
+
"type": "video",
|
|
287
|
+
"video": {"link": video, "caption": caption},
|
|
288
|
+
}
|
|
289
|
+
else:
|
|
290
|
+
data = {
|
|
291
|
+
"messaging_product": "whatsapp",
|
|
292
|
+
"to": recipient_id,
|
|
293
|
+
"type": "video",
|
|
294
|
+
"video": {"id": video, "caption": caption},
|
|
295
|
+
}
|
|
296
|
+
logging.info(f"Sending video to {recipient_id}")
|
|
297
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
298
|
+
if r.status_code == 200:
|
|
299
|
+
logging.info(f"Video sent to {recipient_id}")
|
|
300
|
+
return r.json()
|
|
301
|
+
logging.info(f"Video not sent to {recipient_id}")
|
|
302
|
+
logging.info(f"Status code: {r.status_code}")
|
|
303
|
+
logging.error(f"Response: {r.json()}")
|
|
304
|
+
return r.json()
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def send_document(
|
|
308
|
+
self, document: str, recipient_id: str, caption: str = "", link: bool = True
|
|
309
|
+
) -> dict:
|
|
310
|
+
""" "
|
|
311
|
+
Sends a document message to a WhatsApp user
|
|
312
|
+
Document messages can either be sent by passing the document id or by passing the document link.
|
|
313
|
+
|
|
314
|
+
Args:
|
|
315
|
+
document[str]: Document id or link of the document
|
|
316
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
317
|
+
caption[str]: Caption of the document
|
|
318
|
+
link[bool]: Whether to send a document id or a document link, True means that the document is an id, False means that the document is a link
|
|
319
|
+
|
|
320
|
+
Example:
|
|
321
|
+
>>> from whatsapp import WhatsApp
|
|
322
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
323
|
+
>>> whatsapp.send_document("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", "5511999999999")
|
|
324
|
+
"""
|
|
325
|
+
try:
|
|
326
|
+
sender = dict(self.l)[sender]
|
|
327
|
+
print(self.l)
|
|
328
|
+
print(sender)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
print(12)
|
|
332
|
+
|
|
333
|
+
except:
|
|
334
|
+
print(22)
|
|
335
|
+
sender = self.phone_number_id
|
|
336
|
+
|
|
337
|
+
if sender == None:
|
|
338
|
+
sender = self.phone_number_id
|
|
339
|
+
|
|
340
|
+
url = f"https://graph.facebook.com/v18.0/{sender}/messages"
|
|
341
|
+
if link:
|
|
342
|
+
data = {
|
|
343
|
+
"messaging_product": "whatsapp",
|
|
344
|
+
"to": recipient_id,
|
|
345
|
+
"type": "document",
|
|
346
|
+
"document": {"link": document, "caption": caption},
|
|
347
|
+
}
|
|
348
|
+
else:
|
|
349
|
+
data = {
|
|
350
|
+
"messaging_product": "whatsapp",
|
|
351
|
+
"to": recipient_id,
|
|
352
|
+
"type": "document",
|
|
353
|
+
"document": {"id": document, "caption": caption},
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
logging.info(f"Sending document to {recipient_id}")
|
|
357
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
358
|
+
if r.status_code == 200:
|
|
359
|
+
logging.info(f"Document sent to {recipient_id}")
|
|
360
|
+
return r.json()
|
|
361
|
+
logging.info(f"Document not sent to {recipient_id}")
|
|
362
|
+
logging.info(f"Status code: {r.status_code}")
|
|
363
|
+
logging.error(f"Response: {r.json()}")
|
|
364
|
+
return r.json()
|