whatsapp-python 3.3.5.dev0__py3-none-any.whl → 3.3.9b0__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.

Potentially problematic release.


This version of whatsapp-python might be problematic. Click here for more details.

whatsapp/__init__.py CHANGED
@@ -34,12 +34,10 @@ class WhatsApp(object):
34
34
  logging.getLogger(__name__).addHandler(logging.NullHandler())
35
35
 
36
36
  self.l = phone_number_id
37
- print(self.l)
38
37
 
39
38
  if isinstance(phone_number_id, dict):
40
39
  # use first phone number id as default
41
40
  phone_number_id = phone_number_id[list(phone_number_id.keys())[0]]
42
- print(phone_number_id)
43
41
 
44
42
  elif phone_number_id == "":
45
43
  logging.error("Phone number ID not provided")
@@ -48,7 +46,6 @@ class WhatsApp(object):
48
46
  elif isinstance(phone_number_id, str):
49
47
  logging.critical(
50
48
  "The phone number ID should be a dictionary of phone numbers and their IDs. Using strings is deprecated and will be removed in the next version.")
51
- print(phone_number_id)
52
49
  else:
53
50
  pass
54
51
 
@@ -305,11 +302,9 @@ class Message(object):
305
302
  logging.info(f"Replying to {self.id}")
306
303
  r = requests.post(self.url, headers=self.headers, json=payload)
307
304
  if r.status_code == 200:
308
- logging.info(f"Message sent to {
309
- self.instance.get_author(self.data)}")
305
+ logging.info(f"Message sent to {self.instance.get_author(self.data)}")
310
306
  return r.json()
311
- logging.info(f"Message not sent to {
312
- self.instance.get_author(self.data)}")
307
+ logging.info(f"Message not sent to {self.instance.get_author(self.data)}")
313
308
  logging.info(f"Status code: {r.status_code}")
314
309
  logging.error(f"Response: {r.json()}")
315
310
  return r.json()
@@ -335,14 +330,10 @@ class Message(object):
335
330
 
336
331
  try:
337
332
  sender = dict(self.instance.l)[sender]
338
- print(self.instance.l)
339
- print(sender)
340
333
 
341
334
 
342
- print(12)
343
335
 
344
336
  except:
345
- print(22)
346
337
  sender = self.instance.phone_number_id
347
338
 
348
339
  if sender == None:
@@ -357,7 +348,6 @@ class Message(object):
357
348
  "text": {"preview_url": preview_url, "body": self.content},
358
349
  }
359
350
  logging.info(f"Sending message to {self.to}")
360
- print(url)
361
351
  r = requests.post(url, headers=self.headers, json=data)
362
352
  if r.status_code == 200:
363
353
  logging.info(f"Message sent to {self.to}")
whatsapp/constants.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file contains the constants used in the project.
2
2
  # The VERSION constant is used to store the version of the project - it's not only used in the __init__.py file, but also in the pyproject.toml file.
3
3
 
4
- VERSION = "3.3.5.dev0"
4
+ VERSION = "3.3.9b"
whatsapp/ext/_message.py CHANGED
@@ -104,7 +104,6 @@ def mark_as_read(self) -> dict:
104
104
 
105
105
 
106
106
  def send(self, preview_url: bool = True) -> dict:
107
- print(self.sender)
108
107
  url = f"https://graph.facebook.com/v18.0/{self.sender}/messages"
109
108
  data = {
110
109
  "messaging_product": "whatsapp",
@@ -2,7 +2,7 @@ import logging
2
2
  import requests
3
3
 
4
4
 
5
- def send_location(self, lat: str, long: str, name: str, address: str, recipient_id: str) -> dict:
5
+ def send_location(self, lat: str, long: str, name: str, address: str, recipient_id: str, sender = None) -> dict:
6
6
  """
7
7
  Sends a location message to a WhatsApp user
8
8
 
@@ -18,6 +18,18 @@ def send_location(self, lat: str, long: str, name: str, address: str, recipient_
18
18
  >>> whatsapp = WhatsApp(token, phone_number_id)
19
19
  >>> whatsapp.send_location("-23.564", "-46.654", "My Location", "Rua dois, 123", "5511999999999")
20
20
  """
21
+ try:
22
+ sender = dict(self.instance.l)[sender]
23
+
24
+
25
+
26
+ except:
27
+ sender = self.instance.phone_number_id
28
+
29
+ if sender == None:
30
+ sender = self.instance.phone_number_id
31
+
32
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
21
33
  data = {
22
34
  "messaging_product": "whatsapp",
23
35
  "to": recipient_id,
@@ -30,7 +42,7 @@ def send_location(self, lat: str, long: str, name: str, address: str, recipient_
30
42
  },
31
43
  }
32
44
  logging.info(f"Sending location to {recipient_id}")
33
- r = requests.post(self.url, headers=self.headers, json=data)
45
+ r = requests.post(url, headers=self.headers, json=data)
34
46
  if r.status_code == 200:
35
47
  logging.info(f"Location sent to {recipient_id}")
36
48
  return r.json()
@@ -47,6 +59,7 @@ def send_image(
47
59
  recipient_type: str = "individual",
48
60
  caption: str = "",
49
61
  link: bool = True,
62
+ sender = None
50
63
  ) -> dict:
51
64
  """
52
65
  Sends an image message to a WhatsApp user
@@ -67,6 +80,18 @@ def send_image(
67
80
  >>> whatsapp = WhatsApp(token, phone_number_id)
68
81
  >>> whatsapp.send_image("https://i.imgur.com/Fh7XVYY.jpeg", "5511999999999")
69
82
  """
83
+ try:
84
+ sender = dict(self.l)[sender]
85
+
86
+
87
+
88
+ except:
89
+ sender = self.phone_number_id
90
+
91
+ if sender == None:
92
+ sender = self.phone_number_id
93
+
94
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
70
95
  if link:
71
96
  data = {
72
97
  "messaging_product": "whatsapp",
@@ -84,7 +109,7 @@ def send_image(
84
109
  "image": {"id": image, "caption": caption},
85
110
  }
86
111
  logging.info(f"Sending image to {recipient_id}")
87
- r = requests.post(self.url, headers=self.headers, json=data)
112
+ r = requests.post(url, headers=self.headers, json=data)
88
113
  if r.status_code == 200:
89
114
  logging.info(f"Image sent to {recipient_id}")
90
115
  return r.json()
@@ -94,7 +119,7 @@ def send_image(
94
119
  return r.json()
95
120
 
96
121
 
97
- def send_sticker(self, sticker: str, recipient_id: str, recipient_type: str = "individual", link: bool = True) -> dict:
122
+ def send_sticker(self, sticker: str, recipient_id: str, recipient_type: str = "individual", link: bool = True, sender = None) -> dict:
98
123
  """
99
124
  Sends a sticker message to a WhatsApp user
100
125
 
@@ -113,6 +138,18 @@ def send_sticker(self, sticker: str, recipient_id: str, recipient_type: str = "i
113
138
  >>> whatsapp = WhatsApp(token, phone_number_id)
114
139
  >>> whatsapp.send_sticker("170511049062862", "5511999999999", link=False)
115
140
  """
141
+ try:
142
+ sender = dict(self.l)[sender]
143
+
144
+
145
+
146
+ except:
147
+ sender = self.phone_number_id
148
+
149
+ if sender == None:
150
+ sender = self.phone_number_id
151
+
152
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
116
153
  if link:
117
154
  data = {
118
155
  "messaging_product": "whatsapp",
@@ -130,7 +167,7 @@ def send_sticker(self, sticker: str, recipient_id: str, recipient_type: str = "i
130
167
  "sticker": {"id": sticker},
131
168
  }
132
169
  logging.info(f"Sending sticker to {recipient_id}")
133
- r = requests.post(self.url, headers=self.headers, json=data)
170
+ r = requests.post(url, headers=self.headers, json=data)
134
171
  if r.status_code == 200:
135
172
  logging.info(f"Sticker sent to {recipient_id}")
136
173
  return r.json()
@@ -140,7 +177,7 @@ def send_sticker(self, sticker: str, recipient_id: str, recipient_type: str = "i
140
177
  return r.json()
141
178
 
142
179
 
143
- def send_audio(self, audio: str, recipient_id: str, link: bool = True) -> dict:
180
+ def send_audio(self, audio: str, recipient_id: str, link: bool = True, sender = None) -> dict:
144
181
  """
145
182
  Sends an audio message to a WhatsApp user
146
183
  Audio messages can either be sent by passing the audio id or by passing the audio link.
@@ -155,6 +192,18 @@ def send_audio(self, audio: str, recipient_id: str, link: bool = True) -> dict:
155
192
  >>> whatsapp = WhatsApp(token, phone_number_id)
156
193
  >>> whatsapp.send_audio("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", "5511999999999")
157
194
  """
195
+ try:
196
+ sender = dict(self.l)[sender]
197
+
198
+
199
+
200
+ except:
201
+ sender = self.phone_number_id
202
+
203
+ if sender == None:
204
+ sender = self.phone_number_id
205
+
206
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
158
207
  if link:
159
208
  data = {
160
209
  "messaging_product": "whatsapp",
@@ -170,7 +219,7 @@ def send_audio(self, audio: str, recipient_id: str, link: bool = True) -> dict:
170
219
  "audio": {"id": audio},
171
220
  }
172
221
  logging.info(f"Sending audio to {recipient_id}")
173
- r = requests.post(self.url, headers=self.headers, json=data)
222
+ r = requests.post(url, headers=self.headers, json=data)
174
223
  if r.status_code == 200:
175
224
  logging.info(f"Audio sent to {recipient_id}")
176
225
  return r.json()
@@ -181,7 +230,7 @@ def send_audio(self, audio: str, recipient_id: str, link: bool = True) -> dict:
181
230
 
182
231
 
183
232
  def send_video(
184
- self, video: str, recipient_id: str, caption: str = "", link: bool = True
233
+ self, video: str, recipient_id: str, caption: str = "", link: bool = True, sender = None
185
234
  ) -> dict:
186
235
  """ "
187
236
  Sends a video message to a WhatsApp user
@@ -198,6 +247,18 @@ def send_video(
198
247
  >>> whatsapp = WhatsApp(token, phone_number_id)
199
248
  >>> whatsapp.send_video("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "5511999999999")
200
249
  """
250
+ try:
251
+ sender = dict(self.l)[sender]
252
+
253
+
254
+
255
+ except:
256
+ sender = self.phone_number_id
257
+
258
+ if sender == None:
259
+ sender = self.phone_number_id
260
+
261
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
201
262
  if link:
202
263
  data = {
203
264
  "messaging_product": "whatsapp",
@@ -213,7 +274,7 @@ def send_video(
213
274
  "video": {"id": video, "caption": caption},
214
275
  }
215
276
  logging.info(f"Sending video to {recipient_id}")
216
- r = requests.post(self.url, headers=self.headers, json=data)
277
+ r = requests.post(url, headers=self.headers, json=data)
217
278
  if r.status_code == 200:
218
279
  logging.info(f"Video sent to {recipient_id}")
219
280
  return r.json()
@@ -241,6 +302,18 @@ def send_document(
241
302
  >>> whatsapp = WhatsApp(token, phone_number_id)
242
303
  >>> whatsapp.send_document("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", "5511999999999")
243
304
  """
305
+ try:
306
+ sender = dict(self.l)[sender]
307
+
308
+
309
+
310
+ except:
311
+ sender = self.phone_number_id
312
+
313
+ if sender == None:
314
+ sender = self.phone_number_id
315
+
316
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
244
317
  if link:
245
318
  data = {
246
319
  "messaging_product": "whatsapp",
@@ -257,7 +330,7 @@ def send_document(
257
330
  }
258
331
 
259
332
  logging.info(f"Sending document to {recipient_id}")
260
- r = requests.post(self.url, headers=self.headers, json=data)
333
+ r = requests.post(url, headers=self.headers, json=data)
261
334
  if r.status_code == 200:
262
335
  logging.info(f"Document sent to {recipient_id}")
263
336
  return r.json()
@@ -3,7 +3,7 @@ import requests
3
3
  import logging
4
4
 
5
5
 
6
- def send_custom_json(self, data: dict, recipient_id: str = ""):
6
+ def send_custom_json(self, data: dict, recipient_id: str = "", sender=None):
7
7
  """
8
8
  Sends a custom json to a WhatsApp user. This can be used to send custom objects to the message endpoint.
9
9
 
@@ -18,17 +18,28 @@ def send_custom_json(self, data: dict, recipient_id: str = ""):
18
18
  "type": "audio",
19
19
  "audio": {"id": audio}}, "5511999999999")
20
20
  """
21
+ try:
22
+ sender = dict(self.l)[sender]
23
+
24
+ except:
25
+ sender = self.phone_number_id
26
+
27
+ if sender == None:
28
+ sender = self.phone_number_id
29
+
30
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
21
31
 
22
32
  if recipient_id:
23
33
  if "to" in data.keys():
24
34
  data_recipient_id = data["to"]
25
35
  logging.info(
26
- f"Recipient Id is defined in data ({data_recipient_id}) and recipient_id parameter ({recipient_id})")
36
+ f"Recipient Id is defined in data ({data_recipient_id}) and recipient_id parameter ({recipient_id})"
37
+ )
27
38
  else:
28
39
  data["to"] = recipient_id
29
40
 
30
41
  logging.info(f"Sending custom json to {recipient_id}")
31
- r = requests.post(self.url, headers=self.headers, json=data)
42
+ r = requests.post(url, headers=self.headers, json=data)
32
43
  if r.status_code == 200:
33
44
  logging.info(f"Custom json sent to {recipient_id}")
34
45
  return r.json()
@@ -39,7 +50,7 @@ def send_custom_json(self, data: dict, recipient_id: str = ""):
39
50
 
40
51
 
41
52
  def send_contacts(
42
- self, contacts: List[Dict[Any, Any]], recipient_id: str
53
+ self, contacts: List[Dict[Any, Any]], recipient_id: str, sender=None
43
54
  ) -> Dict[Any, Any]:
44
55
  """send_contacts
45
56
 
@@ -68,6 +79,16 @@ def send_contacts(
68
79
 
69
80
  REFERENCE: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages#contacts-object
70
81
  """
82
+ try:
83
+ sender = dict(self.l)[sender]
84
+
85
+ except:
86
+ sender = self.phone_number_id
87
+
88
+ if sender == None:
89
+ sender = self.phone_number_id
90
+
91
+ url = f"https://graph.facebook.com/v18.0/{sender}/messages"
71
92
 
72
93
  data = {
73
94
  "messaging_product": "whatsapp",
@@ -76,7 +97,7 @@ def send_contacts(
76
97
  "contacts": contacts,
77
98
  }
78
99
  logging.info(f"Sending contacts to {recipient_id}")
79
- r = requests.post(self.url, headers=self.headers, json=data)
100
+ r = requests.post(url, headers=self.headers, json=data)
80
101
  if r.status_code == 200:
81
102
  logging.info(f"Contacts sent to {recipient_id}")
82
103
  return r.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: whatsapp-python
3
- Version: 3.3.5.dev0
3
+ Version: 3.3.9b0
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
@@ -107,7 +107,7 @@ Whereas using third-party providers of the WhatsApp API can result in monthly fe
107
107
  All the prices are available in the [**WhatsApp API docs**](https://developers.facebook.com/docs/whatsapp/pricing).
108
108
 
109
109
  > [!TIP]
110
- > One recommendation I can give you is to use a test number (you can get a free phone number and use it for testing purposes only).
110
+ > I recomend to use a test number, as you you can get a free one and use it for testing purposes.
111
111
 
112
112
  ## Migrating from `Neurotech-HQ/heyoo`
113
113
 
@@ -0,0 +1,13 @@
1
+ whatsapp/__init__.py,sha256=wTwyUgvhE9Pjweo7gTY_LV5-p6mcqNl3VBLYeqH_pz4,14284
2
+ whatsapp/constants.py,sha256=1Vg2VGdkCT6XJDRTrxzst_9U_KR_x7ZPUw75rwyWv-w,226
3
+ whatsapp/ext/_buttons.py,sha256=whj0v4Qgow9AWaWztZxUxaHB8o0MnqA8uRjHHsDht6c,2836
4
+ whatsapp/ext/_media.py,sha256=SAawDZ_5ctneC9kLmtxkjmQyI4sbnQkSuKWs9mcYQUM,4377
5
+ whatsapp/ext/_message.py,sha256=ProE9GbqtsLic0WjKXU-F2NPxtRs3Z0VACzghol6yF8,4385
6
+ whatsapp/ext/_property.py,sha256=-btASb_1B4t69TRGAm21lgnjgb5yemZteW7Bmmouooc,123
7
+ whatsapp/ext/_send_media.py,sha256=DER4i5sCALVJFjfhyP-KOoVomt7d6U_pbun2Sk4pJr8,11350
8
+ whatsapp/ext/_send_others.py,sha256=_h79gcj4iWN1q73PBHOZvZ64Ih1fGz4yznGoSY3cqj0,3327
9
+ whatsapp/ext/_static.py,sha256=NghY748DarWcpHZ6Xa7DtuVpYnHv3udEgZL5E1YdL4M,9853
10
+ whatsapp_python-3.3.9b0.dist-info/METADATA,sha256=MQlEvZFgsXLVmnbUJ3IAtsWjlRYh137WEKnLC4SMoPo,6321
11
+ whatsapp_python-3.3.9b0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
12
+ whatsapp_python-3.3.9b0.dist-info/licenses/LICENSE,sha256=Lcl62br0APneFzEOsYHEVs0hThCIA8eEauvxuLGd1cs,1076
13
+ whatsapp_python-3.3.9b0.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- whatsapp/__init__.py,sha256=7G9OXsmH3tIXlUPw5tRvvo9RymKaNdAa0mImS_iD3ys,14548
2
- whatsapp/constants.py,sha256=LC4qzGNpp1zEedl6VVfWej-2mD6CDYshqSLtaIYL_VI,230
3
- whatsapp/ext/_buttons.py,sha256=whj0v4Qgow9AWaWztZxUxaHB8o0MnqA8uRjHHsDht6c,2836
4
- whatsapp/ext/_media.py,sha256=SAawDZ_5ctneC9kLmtxkjmQyI4sbnQkSuKWs9mcYQUM,4377
5
- whatsapp/ext/_message.py,sha256=pCtE0DsEwd6mTku4wT89SH09mvMi331V_s8R4n4AS4k,4408
6
- whatsapp/ext/_property.py,sha256=-btASb_1B4t69TRGAm21lgnjgb5yemZteW7Bmmouooc,123
7
- whatsapp/ext/_send_media.py,sha256=CpvAdFUOh65G628NULqauy4lEM-xmks6-6irsdy31Yc,9769
8
- whatsapp/ext/_send_others.py,sha256=A6554k98ftStmUu_Wo0wls-2zWuB8ZujaqQoEEgtbZs,2848
9
- whatsapp/ext/_static.py,sha256=NghY748DarWcpHZ6Xa7DtuVpYnHv3udEgZL5E1YdL4M,9853
10
- whatsapp_python-3.3.5.dev0.dist-info/METADATA,sha256=gGotqHv5UZYGWEOv_9CIplBhyQWaVbXGxWbo2Rj21-M,6358
11
- whatsapp_python-3.3.5.dev0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
12
- whatsapp_python-3.3.5.dev0.dist-info/licenses/LICENSE,sha256=Lcl62br0APneFzEOsYHEVs0hThCIA8eEauvxuLGd1cs,1076
13
- whatsapp_python-3.3.5.dev0.dist-info/RECORD,,