hypersender 1.0.0__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.
@@ -0,0 +1,8 @@
1
+ """Official Python SDK for the Hypersender WhatsApp API, SMS API, and OTP API."""
2
+
3
+ __version__ = "1.0.0"
4
+
5
+ from ._base import HypersenderError
6
+ from ._client import Hypersender
7
+
8
+ __all__ = ["Hypersender", "HypersenderError", "__version__"]
hypersender/_base.py ADDED
@@ -0,0 +1,97 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ import httpx
6
+
7
+
8
+ class HypersenderError(Exception):
9
+ """Raised when the API returns an error response (HTTP 4xx or 5xx)."""
10
+
11
+ def __init__(self, message: str, status_code: int, body: Any = None) -> None:
12
+ super().__init__(message)
13
+ self.message = message
14
+ self.status_code = status_code
15
+ self.body = body
16
+
17
+ def __str__(self) -> str:
18
+ return f"[{self.status_code}] {self.message}"
19
+
20
+
21
+ def _clean(data: dict[str, Any] | None) -> dict[str, Any] | None:
22
+ """Drop arguments the caller left as None so the API uses its defaults."""
23
+ if data is None:
24
+ return None
25
+ return {key: value for key, value in data.items() if value is not None}
26
+
27
+
28
+ def _filters(filters: dict[str, Any] | None) -> dict[str, Any]:
29
+ """{"status": "sent"} -> {"filter[status]": "sent"}"""
30
+ return {f"filter[{key}]": value for key, value in (filters or {}).items()}
31
+
32
+
33
+ class Service:
34
+ """One API product (WhatsApp, SMS, OTP, Enterprise) with its own base URL and key."""
35
+
36
+ def __init__(
37
+ self,
38
+ http: httpx.Client,
39
+ base_url: str,
40
+ api_key: str | None,
41
+ instance_id: str | None,
42
+ product: str,
43
+ ) -> None:
44
+ self._http = http
45
+ self._base_url = base_url.rstrip("/")
46
+ self._api_key = api_key
47
+ self._instance_id = instance_id
48
+ self._product = product
49
+
50
+ def _request(
51
+ self,
52
+ method: str,
53
+ path: str,
54
+ *,
55
+ json: dict[str, Any] | None = None,
56
+ params: dict[str, Any] | None = None,
57
+ data: dict[str, Any] | None = None,
58
+ files: dict[str, Any] | None = None,
59
+ per_instance: bool = True,
60
+ ) -> Any:
61
+ if not self._api_key:
62
+ raise ValueError(
63
+ f"Missing API key: pass {self._product.lower()}_api_key= "
64
+ f"or set HYPERSENDER_{self._product}_API_KEY."
65
+ )
66
+ if per_instance:
67
+ if not self._instance_id:
68
+ raise ValueError(
69
+ f"Missing instance ID: pass {self._product.lower()}_instance_id= "
70
+ f"or set HYPERSENDER_{self._product}_INSTANCE_ID."
71
+ )
72
+ path = f"/{self._instance_id}{path}"
73
+
74
+ response = self._http.request(
75
+ method,
76
+ self._base_url + path,
77
+ json=_clean(json),
78
+ params=_clean(params),
79
+ data=_clean(data),
80
+ files=files,
81
+ headers={"Authorization": f"Bearer {self._api_key}", "Accept": "application/json"},
82
+ )
83
+ return _parse(response)
84
+
85
+
86
+ def _parse(response: httpx.Response) -> Any:
87
+ try:
88
+ body = response.json() if response.content else None
89
+ except ValueError:
90
+ body = response.text
91
+
92
+ if response.is_error:
93
+ message = body.get("message") if isinstance(body, dict) else None
94
+ raise HypersenderError(
95
+ message or f"HTTP {response.status_code}", response.status_code, body
96
+ )
97
+ return body
hypersender/_client.py ADDED
@@ -0,0 +1,95 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from typing import Any
5
+
6
+ import httpx
7
+
8
+ from . import __version__
9
+ from .enterprise import Enterprise
10
+ from .otp import OTP
11
+ from .sms import SMS
12
+ from .whatsapp import WhatsApp
13
+
14
+ BASE_URL = "https://app.hypersender.com/api"
15
+
16
+
17
+ class Hypersender:
18
+ """Hypersender API client.
19
+
20
+ Credentials come from the arguments, or from the same environment variables
21
+ the Laravel and Node.js SDKs use::
22
+
23
+ HYPERSENDER_WHATSAPP_API_KEY, HYPERSENDER_WHATSAPP_INSTANCE_ID
24
+ HYPERSENDER_SMS_API_KEY, HYPERSENDER_SMS_INSTANCE_ID
25
+ HYPERSENDER_OTP_API_KEY, HYPERSENDER_OTP_INSTANCE_ID
26
+ HYPERSENDER_ENTERPRISE_API_KEY
27
+
28
+ Example::
29
+
30
+ from hypersender import Hypersender
31
+
32
+ hs = Hypersender()
33
+ hs.whatsapp.send_text("201234567890@c.us", "Hello from Python")
34
+ """
35
+
36
+ def __init__(
37
+ self,
38
+ *,
39
+ whatsapp_api_key: str | None = None,
40
+ whatsapp_instance_id: str | None = None,
41
+ sms_api_key: str | None = None,
42
+ sms_instance_id: str | None = None,
43
+ otp_api_key: str | None = None,
44
+ otp_instance_id: str | None = None,
45
+ enterprise_api_key: str | None = None,
46
+ base_url: str = BASE_URL,
47
+ timeout: float = 30.0,
48
+ http_client: httpx.Client | None = None,
49
+ ) -> None:
50
+ self._http = http_client or httpx.Client(
51
+ timeout=timeout, headers={"User-Agent": f"hypersender-python/{__version__}"}
52
+ )
53
+ base_url = base_url.rstrip("/")
54
+
55
+ def env(name: str, value: str | None) -> str | None:
56
+ return value if value is not None else os.environ.get(f"HYPERSENDER_{name}")
57
+
58
+ self.whatsapp = WhatsApp(
59
+ self._http,
60
+ f"{base_url}/whatsapp/v2",
61
+ env("WHATSAPP_API_KEY", whatsapp_api_key),
62
+ env("WHATSAPP_INSTANCE_ID", whatsapp_instance_id),
63
+ "WHATSAPP",
64
+ )
65
+ self.sms = SMS(
66
+ self._http,
67
+ f"{base_url}/sms/v1",
68
+ env("SMS_API_KEY", sms_api_key),
69
+ env("SMS_INSTANCE_ID", sms_instance_id),
70
+ "SMS",
71
+ )
72
+ self.otp = OTP(
73
+ self._http,
74
+ f"{base_url}/otp/v2",
75
+ env("OTP_API_KEY", otp_api_key),
76
+ env("OTP_INSTANCE_ID", otp_instance_id),
77
+ "OTP",
78
+ )
79
+ self.enterprise = Enterprise(
80
+ self._http,
81
+ f"{base_url}/whatsapp/v2",
82
+ env("ENTERPRISE_API_KEY", enterprise_api_key),
83
+ None,
84
+ "ENTERPRISE",
85
+ )
86
+
87
+ def close(self) -> None:
88
+ """Close the underlying HTTP connections."""
89
+ self._http.close()
90
+
91
+ def __enter__(self) -> Hypersender:
92
+ return self
93
+
94
+ def __exit__(self, *exc: Any) -> None:
95
+ self.close()
@@ -0,0 +1,36 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from ._base import Service, _filters
6
+
7
+
8
+ class Enterprise(Service):
9
+ """Manage many WhatsApp instances on an Enterprise account: `hs.enterprise`.
10
+ The instance ID is passed on each call instead of being set on the client."""
11
+
12
+ def list_instances(self, *, filters: dict[str, Any] | None = None) -> Any:
13
+ """List instances. Filter by uuid, name (partial), phone, or status
14
+ (STOPPED, STARTING, WORKING, SCAN_QR_CODE, FAILED, PENDING)."""
15
+ return self._request("GET", "/instances", params=_filters(filters), per_instance=False)
16
+
17
+ def create_instance(self, phone: str, name: str, *, webhook_url: str | None = None) -> Any:
18
+ """Create an instance. `phone` is E.164 (+201234567890). The response has a QR code."""
19
+ return self._request(
20
+ "POST",
21
+ "/create-instance",
22
+ json={"phone": phone, "name": name, "webhook_url": webhook_url},
23
+ per_instance=False,
24
+ )
25
+
26
+ def get_instance_health(self, instance_id: str) -> Any:
27
+ """Check whether an instance is connected and working."""
28
+ return self._request("GET", f"/{instance_id}/health", per_instance=False)
29
+
30
+ def request_new_qr_code(self, instance_id: str) -> Any:
31
+ """Get a fresh QR code to connect the phone."""
32
+ return self._request("POST", f"/{instance_id}/request-new-qr-code", per_instance=False)
33
+
34
+ def restart_instance(self, instance_id: str) -> Any:
35
+ """Restart an instance."""
36
+ return self._request("POST", f"/{instance_id}/restart", per_instance=False)
hypersender/otp.py ADDED
@@ -0,0 +1,63 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from ._base import Service
6
+
7
+
8
+ class OTP(Service):
9
+ """One-time passwords over WhatsApp or SMS: `hs.otp`."""
10
+
11
+ def request_code(
12
+ self,
13
+ chat_id: str,
14
+ *,
15
+ length: int | None = None,
16
+ use_number: bool | None = None,
17
+ use_letter: bool | None = None,
18
+ all_capital: bool | None = None,
19
+ name: str | None = None,
20
+ expires: int | None = None,
21
+ ) -> Any:
22
+ """Send a one-time code. `length` is 4-10; `expires` is seconds (60-1800);
23
+ `name` is your app or company name shown in the message."""
24
+ return self._request(
25
+ "POST",
26
+ "/request-code",
27
+ json={
28
+ "chatId": chat_id,
29
+ "length": length,
30
+ "useNumber": use_number,
31
+ "useLetter": use_letter,
32
+ "allCapital": all_capital,
33
+ "name": name,
34
+ "expires": expires,
35
+ },
36
+ )
37
+
38
+ def validate_code(self, chat_id: str, code: str) -> Any:
39
+ """Check a code the user entered."""
40
+ return self._request("POST", "/validate-code", json={"chatId": chat_id, "code": code})
41
+
42
+ def generate_link(
43
+ self,
44
+ chat_id: str,
45
+ *,
46
+ expires: int | None = None,
47
+ name: str | None = None,
48
+ message: dict[str, str] | None = None,
49
+ callback: dict[str, str] | None = None,
50
+ ) -> Any:
51
+ """Create a WhatsApp OTP link the user opens to verify.
52
+ `message` keys: prompt, success, failed, expired. `callback` keys: success, failed."""
53
+ return self._request(
54
+ "POST",
55
+ "/generate-link",
56
+ json={
57
+ "chatId": chat_id,
58
+ "expires": expires,
59
+ "name": name,
60
+ "message": message,
61
+ "callback": callback,
62
+ },
63
+ )
hypersender/py.typed ADDED
File without changes
hypersender/sms.py ADDED
@@ -0,0 +1,117 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from ._base import Service, _filters
6
+
7
+
8
+ class SMS(Service):
9
+ """SMS messaging through your Android phone: `hs.sms`."""
10
+
11
+ def send_message(
12
+ self,
13
+ to: str,
14
+ content: str,
15
+ *,
16
+ request_id: str | None = None,
17
+ schedule_send_at: str | None = None,
18
+ max_send_attempts: int | None = None,
19
+ message_expiration_seconds: int | None = None,
20
+ ) -> Any:
21
+ """Send an SMS. `schedule_send_at` is an ISO 8601 datetime to send later."""
22
+ return self._request(
23
+ "POST",
24
+ "/send-message",
25
+ json={
26
+ "to": to,
27
+ "content": content,
28
+ "request_id": request_id,
29
+ "schedule_send_at": schedule_send_at,
30
+ "max_send_attempts": max_send_attempts,
31
+ "message_expiration_seconds": message_expiration_seconds,
32
+ },
33
+ )
34
+
35
+ def list_messages(
36
+ self,
37
+ *,
38
+ filters: dict[str, Any] | None = None,
39
+ sort: str | None = None,
40
+ include: str | None = None,
41
+ page: int | None = None,
42
+ per_page: int | None = None,
43
+ ) -> Any:
44
+ """List messages. `filters={"status": "delivered"}` becomes `filter[status]=delivered`."""
45
+ return self._request(
46
+ "GET",
47
+ "/messages",
48
+ params={
49
+ **_filters(filters),
50
+ "sort": sort,
51
+ "include": include,
52
+ "page": page,
53
+ "per_page": per_page,
54
+ },
55
+ )
56
+
57
+ def delete_message(self, message_id: str) -> Any:
58
+ """Delete a message."""
59
+ return self._request("DELETE", "/delete-message", params={"messageId": message_id})
60
+
61
+ def list_message_threads(
62
+ self,
63
+ *,
64
+ filters: dict[str, Any] | None = None,
65
+ sort: str | None = None,
66
+ include: str | None = None,
67
+ page: int | None = None,
68
+ per_page: int | None = None,
69
+ ) -> Any:
70
+ """List conversations (message threads)."""
71
+ return self._request(
72
+ "GET",
73
+ "/message-threads",
74
+ params={
75
+ **_filters(filters),
76
+ "sort": sort,
77
+ "include": include,
78
+ "page": page,
79
+ "per_page": per_page,
80
+ },
81
+ )
82
+
83
+ def edit_message_thread(self, message_thread_id: str, *, is_archived: bool) -> Any:
84
+ """Archive or unarchive a conversation."""
85
+ return self._request(
86
+ "PUT",
87
+ "/edit-message-thread",
88
+ json={"messageThreadId": message_thread_id, "is_archived": is_archived},
89
+ )
90
+
91
+ def delete_message_thread(self, message_thread_id: str) -> Any:
92
+ """Delete a conversation."""
93
+ return self._request(
94
+ "DELETE", "/delete-message-thread", params={"messageThreadId": message_thread_id}
95
+ )
96
+
97
+ def get_heartbeats(
98
+ self,
99
+ *,
100
+ filters: dict[str, Any] | None = None,
101
+ sort: str | None = None,
102
+ include: str | None = None,
103
+ page: int | None = None,
104
+ per_page: int | None = None,
105
+ ) -> Any:
106
+ """List the phone's heartbeats (app version, battery, charging) to check it is online."""
107
+ return self._request(
108
+ "GET",
109
+ "/heartbeats",
110
+ params={
111
+ **_filters(filters),
112
+ "sort": sort,
113
+ "include": include,
114
+ "page": page,
115
+ "per_page": per_page,
116
+ },
117
+ )
@@ -0,0 +1,379 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from pathlib import Path
5
+ from typing import IO, Any, Union
6
+
7
+ from ._base import Service
8
+
9
+ FileInput = Union[str, "os.PathLike[str]", bytes, IO[bytes]]
10
+
11
+
12
+ def _file(file: FileInput, filename: str | None) -> tuple[str, Any]:
13
+ """A path, bytes, or open binary file -> an httpx multipart file tuple."""
14
+ if isinstance(file, (str, os.PathLike)):
15
+ path = Path(file)
16
+ return (filename or path.name, path.read_bytes())
17
+ return (filename or getattr(file, "name", "file"), file)
18
+
19
+
20
+ def _form(data: dict[str, Any]) -> dict[str, Any]:
21
+ """Multipart fields must be strings; send booleans the way the API's validator expects."""
22
+ return {k: ("1" if v else "0") if isinstance(v, bool) else v for k, v in data.items()}
23
+
24
+
25
+ class Contacts(Service):
26
+ """WhatsApp contacts and LID lookups: `hs.whatsapp.contacts`."""
27
+
28
+ def check_contact_exists(self, phone: str) -> Any:
29
+ """Check if a phone number has WhatsApp. `phone` has the country code, no + or spaces."""
30
+ return self._request("POST", "/contacts/check-exists", json={"phone": phone})
31
+
32
+ def get_all_contacts(
33
+ self,
34
+ *,
35
+ limit: int | None = None,
36
+ offset: int | None = None,
37
+ sort_by: str | None = None,
38
+ sort_order: str | None = None,
39
+ ) -> Any:
40
+ """List contacts. `sort_by` is "id" or "name"; `sort_order` is "asc" or "desc"."""
41
+ return self._request(
42
+ "GET",
43
+ "/contacts/get-all",
44
+ params={"limit": limit, "offset": offset, "sort_by": sort_by, "sort_order": sort_order},
45
+ )
46
+
47
+ def get_contact(self, chat_id: str) -> Any:
48
+ """Get a contact by phone number or chat ID (`123@c.us` or `123@lid`)."""
49
+ return self._request("GET", "/contacts/get", params={"chat_id": chat_id})
50
+
51
+ def get_profile_picture(self, chat_id: str) -> Any:
52
+ """Get a contact's WhatsApp profile picture URL."""
53
+ return self._request("GET", "/contacts/profile-picture", params={"chat_id": chat_id})
54
+
55
+ def upsert_contact(self, chat_id: str, first_name: str, last_name: str | None = None) -> Any:
56
+ """Create a contact, or update its name if it already exists."""
57
+ return self._request(
58
+ "POST",
59
+ "/contacts/upsert",
60
+ json={"chat_id": chat_id, "first_name": first_name, "last_name": last_name},
61
+ )
62
+
63
+ def get_all_known_lids(self, *, limit: int | None = None, offset: int | None = None) -> Any:
64
+ """List the LID to phone number mappings the instance knows."""
65
+ return self._request(
66
+ "GET", "/contacts/get-all-known-lids", params={"limit": limit, "offset": offset}
67
+ )
68
+
69
+ def get_lids_count(self) -> Any:
70
+ """Count the known LID mappings."""
71
+ return self._request("GET", "/contacts/get-lids-count")
72
+
73
+ def get_phone_number_by_lid(self, lid: str) -> Any:
74
+ """Resolve a LID (`1111111@lid`) to its phone number chat ID."""
75
+ return self._request("GET", "/contacts/get-phone-number-by-lid", params={"lid": lid})
76
+
77
+ def get_lid_by_phone_number(self, phone_number: str) -> Any:
78
+ """Find the LID linked to a phone number (`3333333@c.us` or `3333333`)."""
79
+ return self._request(
80
+ "GET", "/contacts/get-lid-by-phone-number", params={"phoneNumber": phone_number}
81
+ )
82
+
83
+
84
+ class WhatsApp(Service):
85
+ """WhatsApp messaging: `hs.whatsapp`."""
86
+
87
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
88
+ super().__init__(*args, **kwargs)
89
+ self.contacts = Contacts(*args, **kwargs)
90
+
91
+ # Sending messages
92
+
93
+ def send_text(
94
+ self,
95
+ chat_id: str,
96
+ text: str,
97
+ *,
98
+ reply_to: str | None = None,
99
+ link_preview: bool | None = None,
100
+ link_preview_high_quality: bool | None = None,
101
+ ) -> Any:
102
+ """Send a text message. `chat_id` looks like `201234567890@c.us`."""
103
+ return self._request(
104
+ "POST",
105
+ "/send-text",
106
+ json={
107
+ "chatId": chat_id,
108
+ "text": text,
109
+ "reply_to": reply_to,
110
+ "link_preview": link_preview,
111
+ "link_preview_high_quality": link_preview_high_quality,
112
+ },
113
+ )
114
+
115
+ def send_text_safe(
116
+ self,
117
+ chat_id: str,
118
+ text: str,
119
+ *,
120
+ reply_to: str | None = None,
121
+ link_preview: bool | None = None,
122
+ link_preview_high_quality: bool | None = None,
123
+ ) -> Any:
124
+ """Send a text message with human-like pacing and typing to lower the risk of a block."""
125
+ return self._request(
126
+ "POST",
127
+ "/send-text-safe",
128
+ json={
129
+ "chatId": chat_id,
130
+ "text": text,
131
+ "reply_to": reply_to,
132
+ "link_preview": link_preview,
133
+ "link_preview_high_quality": link_preview_high_quality,
134
+ },
135
+ )
136
+
137
+ def send_link_custom_preview(
138
+ self,
139
+ chat_id: str,
140
+ text: str,
141
+ *,
142
+ preview_title: str,
143
+ preview_description: str,
144
+ preview_url: str,
145
+ preview_image_url: str | None = None,
146
+ preview_image_file: FileInput | None = None,
147
+ reply_to: str | None = None,
148
+ high_quality: bool | None = None,
149
+ ) -> Any:
150
+ """Send a link with your own preview title, description, and image (URL or file)."""
151
+ fields = {
152
+ "chatId": chat_id,
153
+ "text": text,
154
+ "preview_title": preview_title,
155
+ "preview_description": preview_description,
156
+ "preview_url": preview_url,
157
+ "preview_image_url": preview_image_url,
158
+ "reply_to": reply_to,
159
+ "high_quality": high_quality,
160
+ }
161
+ if preview_image_file is not None:
162
+ return self._request(
163
+ "POST",
164
+ "/send-link-custom-preview",
165
+ data=_form(fields),
166
+ files={"preview_image_file": _file(preview_image_file, None)},
167
+ )
168
+ return self._request("POST", "/send-link-custom-preview", json=fields)
169
+
170
+ def _send_media(
171
+ self,
172
+ path: str,
173
+ chat_id: str,
174
+ url: str | None,
175
+ file: FileInput | None,
176
+ **fields: Any,
177
+ ) -> Any:
178
+ if (url is None) == (file is None):
179
+ raise ValueError("Pass exactly one of url= or file=.")
180
+ fields = {"chatId": chat_id, **fields}
181
+ if file is not None:
182
+ upload = _file(file, fields.get("filename"))
183
+ return self._request("POST", path, data=_form(fields), files={"file": upload})
184
+ return self._request("POST", path, json={**fields, "url": url})
185
+
186
+ def send_file(
187
+ self,
188
+ chat_id: str,
189
+ *,
190
+ url: str | None = None,
191
+ file: FileInput | None = None,
192
+ filename: str | None = None,
193
+ mimetype: str | None = None,
194
+ caption: str | None = None,
195
+ reply_to: str | None = None,
196
+ ) -> Any:
197
+ """Send a document from a URL or a local file (path, bytes, or open binary file)."""
198
+ return self._send_media(
199
+ "/send-file",
200
+ chat_id,
201
+ url,
202
+ file,
203
+ filename=filename,
204
+ mimetype=mimetype,
205
+ caption=caption,
206
+ reply_to=reply_to,
207
+ )
208
+
209
+ def send_image(
210
+ self,
211
+ chat_id: str,
212
+ *,
213
+ url: str | None = None,
214
+ file: FileInput | None = None,
215
+ filename: str | None = None,
216
+ mimetype: str | None = None,
217
+ caption: str | None = None,
218
+ reply_to: str | None = None,
219
+ ) -> Any:
220
+ """Send an image from a URL or a local file."""
221
+ return self._send_media(
222
+ "/send-image",
223
+ chat_id,
224
+ url,
225
+ file,
226
+ filename=filename,
227
+ mimetype=mimetype,
228
+ caption=caption,
229
+ reply_to=reply_to,
230
+ )
231
+
232
+ def send_video(
233
+ self,
234
+ chat_id: str,
235
+ *,
236
+ url: str | None = None,
237
+ file: FileInput | None = None,
238
+ filename: str | None = None,
239
+ mimetype: str | None = None,
240
+ caption: str | None = None,
241
+ reply_to: str | None = None,
242
+ ) -> Any:
243
+ """Send a video from a URL or a local file."""
244
+ return self._send_media(
245
+ "/send-video",
246
+ chat_id,
247
+ url,
248
+ file,
249
+ filename=filename,
250
+ mimetype=mimetype,
251
+ caption=caption,
252
+ reply_to=reply_to,
253
+ )
254
+
255
+ def send_voice(
256
+ self,
257
+ chat_id: str,
258
+ *,
259
+ url: str | None = None,
260
+ file: FileInput | None = None,
261
+ caption: str | None = None,
262
+ reply_to: str | None = None,
263
+ ) -> Any:
264
+ """Send a voice note from a URL or a local file."""
265
+ return self._send_media(
266
+ "/send-voice", chat_id, url, file, caption=caption, reply_to=reply_to
267
+ )
268
+
269
+ def send_poll(
270
+ self,
271
+ chat_id: str,
272
+ name: str,
273
+ options: list[str],
274
+ *,
275
+ multiple_answers: bool = False,
276
+ reply_to: str | None = None,
277
+ ) -> Any:
278
+ """Send a poll."""
279
+ return self._request(
280
+ "POST",
281
+ "/send-poll",
282
+ json={
283
+ "chatId": chat_id,
284
+ "reply_to": reply_to,
285
+ "poll": {"name": name, "options": options, "multipleAnswers": multiple_answers},
286
+ },
287
+ )
288
+
289
+ def send_contact_card(self, chat_id: str, contacts: list[dict[str, Any]]) -> Any:
290
+ """Send contact cards. Each contact has fullName, phoneNumber, and optionally
291
+ organization, whatsappId, or a raw vcard."""
292
+ return self._request(
293
+ "POST", "/send-contact-card", json={"chatId": chat_id, "contacts": contacts}
294
+ )
295
+
296
+ def send_location(
297
+ self,
298
+ chat_id: str,
299
+ latitude: float,
300
+ longitude: float,
301
+ *,
302
+ title: str | None = None,
303
+ reply_to: str | None = None,
304
+ ) -> Any:
305
+ """Send a location pin."""
306
+ return self._request(
307
+ "POST",
308
+ "/send-location",
309
+ json={
310
+ "chatId": chat_id,
311
+ "latitude": latitude,
312
+ "longitude": longitude,
313
+ "title": title,
314
+ "reply_to": reply_to,
315
+ },
316
+ )
317
+
318
+ def forward_message(self, chat_id: str, message_id: str) -> Any:
319
+ """Forward a message to a chat."""
320
+ return self._request(
321
+ "POST", "/forward-message", json={"chatId": chat_id, "messageId": message_id}
322
+ )
323
+
324
+ # Message management
325
+
326
+ def react_to_message(self, chat_id: str, message_id: str, reaction: str) -> Any:
327
+ """React to a message with an emoji."""
328
+ return self._request(
329
+ "PUT",
330
+ "/react-to-message",
331
+ json={"chatId": chat_id, "messageId": message_id, "reaction": reaction},
332
+ )
333
+
334
+ def star_message(self, chat_id: str, message_id: str, star: bool = True) -> Any:
335
+ """Star or unstar a message."""
336
+ return self._request(
337
+ "PUT",
338
+ "/star-message",
339
+ json={"chatId": chat_id, "messageId": message_id, "star": star},
340
+ )
341
+
342
+ def delete_message(self, chat_id: str, message_id: str) -> Any:
343
+ """Delete a message for everyone."""
344
+ return self._request(
345
+ "DELETE", "/delete-message", params={"chatId": chat_id, "messageId": message_id}
346
+ )
347
+
348
+ def get_queued_request(self, uuid: str) -> Any:
349
+ """Get a request's status by the `queued_request_uuid` every send method returns."""
350
+ return self._request("GET", f"/queued-requests/{uuid}")
351
+
352
+ # Chat status
353
+
354
+ def send_seen(self, chat_id: str, message_id: str, *, participant: str | None = None) -> Any:
355
+ """Mark a message as seen (blue ticks)."""
356
+ return self._request(
357
+ "POST",
358
+ "/send-seen",
359
+ json={"chatId": chat_id, "messageId": message_id, "participant": participant},
360
+ )
361
+
362
+ def read_chat(
363
+ self, chat_id: str, *, messages: int | None = None, days: int | None = None
364
+ ) -> Any:
365
+ """Mark a chat's recent messages as read."""
366
+ return self._request(
367
+ "POST",
368
+ "/read-chat",
369
+ json={"chatId": chat_id},
370
+ params={"messages": messages, "days": days},
371
+ )
372
+
373
+ def start_typing(self, chat_id: str) -> Any:
374
+ """Show "typing..." in a chat."""
375
+ return self._request("POST", "/start-typing", json={"chatId": chat_id})
376
+
377
+ def stop_typing(self, chat_id: str) -> Any:
378
+ """Stop showing "typing..." in a chat."""
379
+ return self._request("POST", "/stop-typing", json={"chatId": chat_id})
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.5
2
+ Name: hypersender
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for the Hypersender WhatsApp API, SMS API, and OTP API.
5
+ Project-URL: Homepage, https://hypersender.com
6
+ Project-URL: Documentation, https://docs.hypersender.com/v2/packages-and-sdks/python/installation
7
+ Project-URL: Repository, https://github.com/hypersender/hypersender-python
8
+ Project-URL: Changelog, https://github.com/hypersender/hypersender-python/blob/main/CHANGELOG.md
9
+ Author-email: Hypersender <info@hypersender.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: hypersender,otp,python whatsapp bot,sdk,sms,sms api,whatsapp,whatsapp api,whatsapp bot,whatsapp bot python
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Communications :: Chat
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: httpx<1,>=0.25
23
+ Description-Content-Type: text/markdown
24
+
25
+ <p align="center"><img width="307" height="63" src="https://raw.githubusercontent.com/hypersender/hypersender-python/main/art/hy.svg" alt="Hypersender Logo"></p>
26
+
27
+ <p align="center">
28
+ <a href="https://pypi.org/project/hypersender/"><img src="https://img.shields.io/pypi/dm/hypersender" alt="Monthly Downloads"></a>
29
+ <a href="https://pypi.org/project/hypersender/"><img src="https://img.shields.io/pypi/v/hypersender" alt="Latest Stable Version"></a>
30
+ <a href="https://pypi.org/project/hypersender/"><img src="https://img.shields.io/pypi/pyversions/hypersender" alt="Python Versions"></a>
31
+ <a href="https://github.com/hypersender/hypersender-python/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="License"></a>
32
+ </p>
33
+
34
+ # Introduction
35
+
36
+ The official Python SDK for the Hypersender WhatsApp API, SMS API, and OTP API. Send WhatsApp messages, build a Python WhatsApp bot, send SMS from your own Android phone, and verify users with one-time codes.
37
+
38
+ # Installation
39
+
40
+ You can install the package via pip (Python 3.10+):
41
+
42
+ ```bash
43
+ pip install hypersender
44
+ ```
45
+
46
+ ```python
47
+ from hypersender import Hypersender
48
+
49
+ hs = Hypersender() # reads HYPERSENDER_WHATSAPP_API_KEY and HYPERSENDER_WHATSAPP_INSTANCE_ID
50
+ hs.whatsapp.send_text("201234567890@c.us", "Hello from Python!")
51
+ ```
52
+
53
+ # Official Documentation
54
+
55
+ You can find the official documentation at [Hypersender Python SDK Documentation](https://docs.hypersender.com/v2/packages-and-sdks/python/installation).
56
+
57
+ Building a WhatsApp bot in Python? Follow [Build a WhatsApp Bot in Python](https://docs.hypersender.com/v2/packages-and-sdks/python/whatsapp/whatsapp-bot) for a complete Flask and FastAPI example.
58
+
59
+ ## Changelog
60
+
61
+ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
62
+
63
+ ## Contributing
64
+
65
+ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
66
+
67
+ ## Security Vulnerabilities
68
+
69
+ Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
70
+
71
+ ## Credits
72
+
73
+ - [Hypersender](https://github.com/hypersender)
74
+ - [All Contributors](../../contributors)
75
+
76
+ ## License
77
+
78
+ The MIT License (MIT). Please see [License File](LICENSE) for more information.
@@ -0,0 +1,12 @@
1
+ hypersender/__init__.py,sha256=o1QDXF3hIMCmrc_2HcGiEbSv7WS4Jz77WTbzS3gcoEo,237
2
+ hypersender/_base.py,sha256=Yc81o3KCWPmgms76tjHmhyUnoBROGIHR-YfdR8Dm77Q,3027
3
+ hypersender/_client.py,sha256=xsDfV6Ah-0NfqqgEcbTc3ZAWq9Giya05m1p04eBa6Pc,2787
4
+ hypersender/enterprise.py,sha256=LqUy9lK11OroAT0htJxCl_UA0z9KC9pvitt_Mr61k9U,1606
5
+ hypersender/otp.py,sha256=Y9MRy82ifmrK9z7A0HrCK_nvR92Io2ufCesAf3qaZNk,1922
6
+ hypersender/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ hypersender/sms.py,sha256=dGpzOw6jroQ_ZTUbn3LdFjxpoxCjRvJfxTabUziq8eY,3588
8
+ hypersender/whatsapp.py,sha256=0NZ9DiVX6fXBPuvmpdzV_YFTcsezMxeL4JXoXeMGrKA,12738
9
+ hypersender-1.0.0.dist-info/METADATA,sha256=qzRYYW8g7vhDWX3n_1ozoIPNhPtXk_8rEuItriU6400,3344
10
+ hypersender-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ hypersender-1.0.0.dist-info/licenses/LICENSE,sha256=ZHHo8ELngaZXEX4-_-_bdGno2ji9Wyhuc4AExMcY7Mc,1096
12
+ hypersender-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Hypersender <info@hypersender.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.