forked from green-api/whatsapp-api-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadFileAndSendFileByUrl.py
More file actions
35 lines (26 loc) · 907 Bytes
/
uploadFileAndSendFileByUrl.py
File metadata and controls
35 lines (26 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from os.path import basename
from urllib.parse import urlparse
from whatsapp_api_client_python import API
greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)
def main():
upload_file_response = greenAPI.sending.uploadFile(
"data/rates.png"
)
if upload_file_response.code == 200:
print(upload_file_response.data)
url_file = upload_file_response.data["urlFile"]
url = urlparse(url_file)
file_name = basename(url.path)
send_file_by_url_response = greenAPI.sending.sendFileByUrl(
"11001234567@c.us", url_file, file_name
)
if send_file_by_url_response.code == 200:
print(send_file_by_url_response.data)
else:
print(send_file_by_url_response.error)
else:
print(upload_file_response.error)
if __name__ == '__main__':
main()