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.
@@ -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
- if recipient_id:
23
- if "to" in data.keys():
24
- data_recipient_id = data["to"]
25
- logging.info(
26
- f"Recipient Id is defined in data ({data_recipient_id}) and recipient_id parameter ({recipient_id})")
27
- else:
28
- data["to"] = recipient_id
29
-
30
- logging.info(f"Sending custom json to {recipient_id}")
31
- r = requests.post(self.url, headers=self.headers, json=data)
32
- if r.status_code == 200:
33
- logging.info(f"Custom json sent to {recipient_id}")
34
- return r.json()
35
- logging.info(f"Custom json not sent to {recipient_id}")
36
- logging.info(f"Status code: {r.status_code}")
37
- logging.error(f"Response: {r.json()}")
38
- return r.json()
39
-
40
-
41
- def send_contacts(
42
- self, contacts: List[Dict[Any, Any]], recipient_id: str
43
- ) -> Dict[Any, Any]:
44
- """send_contacts
45
-
46
- Send a list of contacts to a user
47
-
48
- Args:
49
- contacts(List[Dict[Any, Any]]): List of contacts to send
50
- recipient_id(str): Phone number of the user with country code wihout +
51
-
52
- Example:
53
- >>> from whatsapp import WhatsApp
54
- >>> whatsapp = WhatsApp(token, phone_number_id)
55
- >>> contacts = [{
56
- "addresses": [{
57
- "street": "STREET",
58
- "city": "CITY",
59
- "state": "STATE",
60
- "zip": "ZIP",
61
- "country": "COUNTRY",
62
- "country_code": "COUNTRY_CODE",
63
- "type": "HOME"
64
- },
65
- ....
66
- }
67
- ]
68
-
69
- REFERENCE: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages#contacts-object
70
- """
71
-
72
- data = {
73
- "messaging_product": "whatsapp",
74
- "to": recipient_id,
75
- "type": "contacts",
76
- "contacts": contacts,
77
- }
78
- logging.info(f"Sending contacts to {recipient_id}")
79
- r = requests.post(self.url, headers=self.headers, json=data)
80
- if r.status_code == 200:
81
- logging.info(f"Contacts sent to {recipient_id}")
82
- return r.json()
83
- logging.info(f"Contacts not sent to {recipient_id}")
84
- logging.info(f"Status code: {r.status_code}")
85
- logging.error(f"Response: {r.json()}")
86
- return r.json()
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()