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_others.py
CHANGED
|
@@ -1,86 +1,118 @@
|
|
|
1
|
-
from typing import Any, Dict, List
|
|
2
|
-
import requests
|
|
3
|
-
import logging
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def send_custom_json(self, data: dict, recipient_id: str = ""):
|
|
7
|
-
"""
|
|
8
|
-
Sends a custom json to a WhatsApp user. This can be used to send custom objects to the message endpoint.
|
|
9
|
-
|
|
10
|
-
Args:
|
|
11
|
-
data[dict]: Dictionary that should be send
|
|
12
|
-
recipient_id[str]: Phone number of the user with country code wihout +
|
|
13
|
-
Example:
|
|
14
|
-
>>> from whatsapp import WhatsApp
|
|
15
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
16
|
-
>>> whatsapp.send_custom_json({
|
|
17
|
-
"messaging_product": "whatsapp",
|
|
18
|
-
"type": "audio",
|
|
19
|
-
"audio": {"id": audio}}, "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
|
-
|
|
1
|
+
from typing import Any, Dict, List
|
|
2
|
+
import requests
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def send_custom_json(self, data: dict, recipient_id: str = "", sender= None):
|
|
7
|
+
"""
|
|
8
|
+
Sends a custom json to a WhatsApp user. This can be used to send custom objects to the message endpoint.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
data[dict]: Dictionary that should be send
|
|
12
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
13
|
+
Example:
|
|
14
|
+
>>> from whatsapp import WhatsApp
|
|
15
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
16
|
+
>>> whatsapp.send_custom_json({
|
|
17
|
+
"messaging_product": "whatsapp",
|
|
18
|
+
"type": "audio",
|
|
19
|
+
"audio": {"id": audio}}, "5511999999999")
|
|
20
|
+
"""
|
|
21
|
+
try:
|
|
22
|
+
sender = dict(self.l)[sender]
|
|
23
|
+
print(self.l)
|
|
24
|
+
print(sender)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
print(12)
|
|
28
|
+
|
|
29
|
+
except:
|
|
30
|
+
print(22)
|
|
31
|
+
sender = self.phone_number_id
|
|
32
|
+
|
|
33
|
+
if sender == None:
|
|
34
|
+
sender = self.phone_number_id
|
|
35
|
+
|
|
36
|
+
url = f"https://graph.facebook.com/v18.0/{sender}/messages"
|
|
37
|
+
|
|
38
|
+
if recipient_id:
|
|
39
|
+
if "to" in data.keys():
|
|
40
|
+
data_recipient_id = data["to"]
|
|
41
|
+
logging.info(
|
|
42
|
+
f"Recipient Id is defined in data ({data_recipient_id}) and recipient_id parameter ({recipient_id})")
|
|
43
|
+
else:
|
|
44
|
+
data["to"] = recipient_id
|
|
45
|
+
|
|
46
|
+
logging.info(f"Sending custom json to {recipient_id}")
|
|
47
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
48
|
+
if r.status_code == 200:
|
|
49
|
+
logging.info(f"Custom json sent to {recipient_id}")
|
|
50
|
+
return r.json()
|
|
51
|
+
logging.info(f"Custom json not sent to {recipient_id}")
|
|
52
|
+
logging.info(f"Status code: {r.status_code}")
|
|
53
|
+
logging.error(f"Response: {r.json()}")
|
|
54
|
+
return r.json()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def send_contacts(
|
|
58
|
+
self, contacts: List[Dict[Any, Any]], recipient_id: str, sender=None
|
|
59
|
+
) -> Dict[Any, Any]:
|
|
60
|
+
"""send_contacts
|
|
61
|
+
|
|
62
|
+
Send a list of contacts to a user
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
contacts(List[Dict[Any, Any]]): List of contacts to send
|
|
66
|
+
recipient_id(str): Phone number of the user with country code wihout +
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
>>> from whatsapp import WhatsApp
|
|
70
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
71
|
+
>>> contacts = [{
|
|
72
|
+
"addresses": [{
|
|
73
|
+
"street": "STREET",
|
|
74
|
+
"city": "CITY",
|
|
75
|
+
"state": "STATE",
|
|
76
|
+
"zip": "ZIP",
|
|
77
|
+
"country": "COUNTRY",
|
|
78
|
+
"country_code": "COUNTRY_CODE",
|
|
79
|
+
"type": "HOME"
|
|
80
|
+
},
|
|
81
|
+
....
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
REFERENCE: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages#contacts-object
|
|
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
|
+
|
|
104
|
+
data = {
|
|
105
|
+
"messaging_product": "whatsapp",
|
|
106
|
+
"to": recipient_id,
|
|
107
|
+
"type": "contacts",
|
|
108
|
+
"contacts": contacts,
|
|
109
|
+
}
|
|
110
|
+
logging.info(f"Sending contacts to {recipient_id}")
|
|
111
|
+
r = requests.post(url, headers=self.headers, json=data)
|
|
112
|
+
if r.status_code == 200:
|
|
113
|
+
logging.info(f"Contacts sent to {recipient_id}")
|
|
114
|
+
return r.json()
|
|
115
|
+
logging.info(f"Contacts not sent to {recipient_id}")
|
|
116
|
+
logging.info(f"Status code: {r.status_code}")
|
|
117
|
+
logging.error(f"Response: {r.json()}")
|
|
118
|
+
return r.json()
|