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/_message.py
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import requests
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def react(self, emoji: str) -> dict:
|
|
6
|
-
data = {
|
|
7
|
-
"messaging_product": "whatsapp",
|
|
8
|
-
"recipient_type":"individual",
|
|
9
|
-
"to": self.sender,
|
|
10
|
-
"type": "reaction",
|
|
11
|
-
"reaction": {"message_id": self.id, "emoji": emoji},
|
|
12
|
-
}
|
|
13
|
-
logging.info(f"Reacting to {self.id}")
|
|
14
|
-
r = requests.post(self.url, headers=self.headers, json=data)
|
|
15
|
-
if r.status_code == 200:
|
|
16
|
-
logging.info(f"Reaction sent to {self.to}")
|
|
17
|
-
return r.json()
|
|
18
|
-
logging.info(f"Reaction not sent to {self.to}")
|
|
19
|
-
logging.info(f"Status code: {r.status_code}")
|
|
20
|
-
logging.debug(f"Response: {r.json()}")
|
|
21
|
-
return r.json()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def send_template(self, template: str, recipient_id: str, components: str, lang: str = "en_US") -> dict:
|
|
25
|
-
"""
|
|
26
|
-
Sends a template message to a WhatsApp user, Template messages can either be;
|
|
27
|
-
1. Text template
|
|
28
|
-
2. Media based template
|
|
29
|
-
3. Interactive template
|
|
30
|
-
You can customize the template message by passing a dictionary of components.
|
|
31
|
-
You can find the available components in the documentation.
|
|
32
|
-
https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates
|
|
33
|
-
Args:
|
|
34
|
-
template[str]: Template name to be sent to the user
|
|
35
|
-
recipient_id[str]: Phone number of the user with country code wihout +
|
|
36
|
-
lang[str]: Language of the template message
|
|
37
|
-
components[list]: List of components to be sent to the user # \
|
|
38
|
-
Example:
|
|
39
|
-
>>> from whatsapp import WhatsApp
|
|
40
|
-
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
41
|
-
>>> whatsapp.send_template("hello_world", "5511999999999", lang="en_US"))
|
|
42
|
-
"""
|
|
43
|
-
data = {
|
|
44
|
-
"messaging_product": "whatsapp",
|
|
45
|
-
"to": recipient_id,
|
|
46
|
-
"type": "template",
|
|
47
|
-
"template": {
|
|
48
|
-
"name": template,
|
|
49
|
-
"language": {"code": lang},
|
|
50
|
-
"components": components,
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
logging.info(f"Sending template to {recipient_id}")
|
|
54
|
-
r = requests.post(self.url, headers=self.headers, json=data)
|
|
55
|
-
if r.status_code == 200:
|
|
56
|
-
logging.info(f"Template sent to {recipient_id}")
|
|
57
|
-
return r.json()
|
|
58
|
-
logging.info(f"Template not sent to {recipient_id}")
|
|
59
|
-
logging.info(f"Status code: {r.status_code}")
|
|
60
|
-
logging.error(f"Response: {r.json()}")
|
|
61
|
-
return r.json()
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# MESSAGE()
|
|
65
|
-
|
|
66
|
-
def reply(self, reply_text: str = "", preview_url: bool = True) -> dict:
|
|
67
|
-
if self.data == {}:
|
|
68
|
-
return {"error": "No data provided"}
|
|
69
|
-
author = self.instance.get_author(self.data)
|
|
70
|
-
payload = {
|
|
71
|
-
"messaging_product": "whatsapp",
|
|
72
|
-
"recipient_type": "individual",
|
|
73
|
-
"to": str(author),
|
|
74
|
-
"type": "text",
|
|
75
|
-
"context": {"message_id": self.id},
|
|
76
|
-
"text": {"preview_url": preview_url, "body": reply_text},
|
|
77
|
-
}
|
|
78
|
-
logging.info(f"Replying to {self.id}")
|
|
79
|
-
r = requests.post(self.url, headers=self.headers, json=payload)
|
|
80
|
-
if r.status_code == 200:
|
|
81
|
-
logging.info(f"Message sent to {self.instance.get_author(self.data)}")
|
|
82
|
-
return r.json()
|
|
83
|
-
logging.info(f"Message not sent to {self.instance.get_author(self.data)}")
|
|
84
|
-
logging.info(f"Status code: {r.status_code}")
|
|
85
|
-
logging.error(f"Response: {r.json()}")
|
|
86
|
-
return r.json()
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def mark_as_read(self) -> dict:
|
|
90
|
-
payload = {
|
|
91
|
-
"messaging_product": "whatsapp",
|
|
92
|
-
"status": "read",
|
|
93
|
-
"message_id": self.id,
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
response = requests.post(
|
|
97
|
-
f"{self.instance.url}", headers=self.instance.headers, json=payload)
|
|
98
|
-
if response.status_code == 200:
|
|
99
|
-
logging.info(response.json())
|
|
100
|
-
return response.json()
|
|
101
|
-
else:
|
|
102
|
-
logging.error(response.json())
|
|
103
|
-
return response.json()
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def send(self, preview_url: bool = True) -> dict:
|
|
107
|
-
print(self.sender)
|
|
108
|
-
url = f"https://graph.facebook.com/v18.0/{self.sender}/messages"
|
|
109
|
-
data = {
|
|
110
|
-
"messaging_product": "whatsapp",
|
|
111
|
-
"recipient_type": self.rec,
|
|
112
|
-
"to": self.to,
|
|
113
|
-
"type": "text",
|
|
114
|
-
"text": {"preview_url": preview_url, "body": self.content},
|
|
115
|
-
}
|
|
116
|
-
logging.info(f"Sending message to {self.to}")
|
|
117
|
-
r = requests.post(f"{url}", headers=self.headers, json=data)
|
|
118
|
-
if r.status_code == 200:
|
|
119
|
-
logging.info(f"Message sent to {self.to}")
|
|
120
|
-
return r.json()
|
|
121
|
-
logging.info(f"Message not sent to {self.to}")
|
|
122
|
-
logging.info(f"Status code: {r.status_code}")
|
|
123
|
-
logging.error(f"Response: {r.json()}")
|
|
124
|
-
return r.json()
|
|
1
|
+
import logging
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def react(self, emoji: str) -> dict:
|
|
6
|
+
data = {
|
|
7
|
+
"messaging_product": "whatsapp",
|
|
8
|
+
"recipient_type":"individual",
|
|
9
|
+
"to": self.sender,
|
|
10
|
+
"type": "reaction",
|
|
11
|
+
"reaction": {"message_id": self.id, "emoji": emoji},
|
|
12
|
+
}
|
|
13
|
+
logging.info(f"Reacting to {self.id}")
|
|
14
|
+
r = requests.post(self.url, headers=self.headers, json=data)
|
|
15
|
+
if r.status_code == 200:
|
|
16
|
+
logging.info(f"Reaction sent to {self.to}")
|
|
17
|
+
return r.json()
|
|
18
|
+
logging.info(f"Reaction not sent to {self.to}")
|
|
19
|
+
logging.info(f"Status code: {r.status_code}")
|
|
20
|
+
logging.debug(f"Response: {r.json()}")
|
|
21
|
+
return r.json()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def send_template(self, template: str, recipient_id: str, components: str, lang: str = "en_US") -> dict:
|
|
25
|
+
"""
|
|
26
|
+
Sends a template message to a WhatsApp user, Template messages can either be;
|
|
27
|
+
1. Text template
|
|
28
|
+
2. Media based template
|
|
29
|
+
3. Interactive template
|
|
30
|
+
You can customize the template message by passing a dictionary of components.
|
|
31
|
+
You can find the available components in the documentation.
|
|
32
|
+
https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates
|
|
33
|
+
Args:
|
|
34
|
+
template[str]: Template name to be sent to the user
|
|
35
|
+
recipient_id[str]: Phone number of the user with country code wihout +
|
|
36
|
+
lang[str]: Language of the template message
|
|
37
|
+
components[list]: List of components to be sent to the user # \
|
|
38
|
+
Example:
|
|
39
|
+
>>> from whatsapp import WhatsApp
|
|
40
|
+
>>> whatsapp = WhatsApp(token, phone_number_id)
|
|
41
|
+
>>> whatsapp.send_template("hello_world", "5511999999999", lang="en_US"))
|
|
42
|
+
"""
|
|
43
|
+
data = {
|
|
44
|
+
"messaging_product": "whatsapp",
|
|
45
|
+
"to": recipient_id,
|
|
46
|
+
"type": "template",
|
|
47
|
+
"template": {
|
|
48
|
+
"name": template,
|
|
49
|
+
"language": {"code": lang},
|
|
50
|
+
"components": components,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
logging.info(f"Sending template to {recipient_id}")
|
|
54
|
+
r = requests.post(self.url, headers=self.headers, json=data)
|
|
55
|
+
if r.status_code == 200:
|
|
56
|
+
logging.info(f"Template sent to {recipient_id}")
|
|
57
|
+
return r.json()
|
|
58
|
+
logging.info(f"Template not sent to {recipient_id}")
|
|
59
|
+
logging.info(f"Status code: {r.status_code}")
|
|
60
|
+
logging.error(f"Response: {r.json()}")
|
|
61
|
+
return r.json()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# MESSAGE()
|
|
65
|
+
|
|
66
|
+
def reply(self, reply_text: str = "", preview_url: bool = True) -> dict:
|
|
67
|
+
if self.data == {}:
|
|
68
|
+
return {"error": "No data provided"}
|
|
69
|
+
author = self.instance.get_author(self.data)
|
|
70
|
+
payload = {
|
|
71
|
+
"messaging_product": "whatsapp",
|
|
72
|
+
"recipient_type": "individual",
|
|
73
|
+
"to": str(author),
|
|
74
|
+
"type": "text",
|
|
75
|
+
"context": {"message_id": self.id},
|
|
76
|
+
"text": {"preview_url": preview_url, "body": reply_text},
|
|
77
|
+
}
|
|
78
|
+
logging.info(f"Replying to {self.id}")
|
|
79
|
+
r = requests.post(self.url, headers=self.headers, json=payload)
|
|
80
|
+
if r.status_code == 200:
|
|
81
|
+
logging.info(f"Message sent to {self.instance.get_author(self.data)}")
|
|
82
|
+
return r.json()
|
|
83
|
+
logging.info(f"Message not sent to {self.instance.get_author(self.data)}")
|
|
84
|
+
logging.info(f"Status code: {r.status_code}")
|
|
85
|
+
logging.error(f"Response: {r.json()}")
|
|
86
|
+
return r.json()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def mark_as_read(self) -> dict:
|
|
90
|
+
payload = {
|
|
91
|
+
"messaging_product": "whatsapp",
|
|
92
|
+
"status": "read",
|
|
93
|
+
"message_id": self.id,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
response = requests.post(
|
|
97
|
+
f"{self.instance.url}", headers=self.instance.headers, json=payload)
|
|
98
|
+
if response.status_code == 200:
|
|
99
|
+
logging.info(response.json())
|
|
100
|
+
return response.json()
|
|
101
|
+
else:
|
|
102
|
+
logging.error(response.json())
|
|
103
|
+
return response.json()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def send(self, preview_url: bool = True) -> dict:
|
|
107
|
+
print(self.sender)
|
|
108
|
+
url = f"https://graph.facebook.com/v18.0/{self.sender}/messages"
|
|
109
|
+
data = {
|
|
110
|
+
"messaging_product": "whatsapp",
|
|
111
|
+
"recipient_type": self.rec,
|
|
112
|
+
"to": self.to,
|
|
113
|
+
"type": "text",
|
|
114
|
+
"text": {"preview_url": preview_url, "body": self.content},
|
|
115
|
+
}
|
|
116
|
+
logging.info(f"Sending message to {self.to}")
|
|
117
|
+
r = requests.post(f"{url}", headers=self.headers, json=data)
|
|
118
|
+
if r.status_code == 200:
|
|
119
|
+
logging.info(f"Message sent to {self.to}")
|
|
120
|
+
return r.json()
|
|
121
|
+
logging.info(f"Message not sent to {self.to}")
|
|
122
|
+
logging.info(f"Status code: {r.status_code}")
|
|
123
|
+
logging.error(f"Response: {r.json()}")
|
|
124
|
+
return r.json()
|
whatsapp/ext/_property.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def authorized(self) -> bool:
|
|
5
|
-
return requests.get(self.url, headers=self.headers).status_code != 401
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def authorized(self) -> bool:
|
|
5
|
+
return requests.get(self.url, headers=self.headers).status_code != 401
|