Skip to content

Commit cb4fedb

Browse files
author
Lemonyte
committed
Add from and attachments params to text.send
1 parent 8bdd445 commit cb4fedb

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/contiguity/text.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from collections.abc import Sequence
23

34
import phonenumbers
45

@@ -13,17 +14,14 @@ class TextResponse(BaseResponse):
1314

1415

1516
class Text(BaseProduct):
16-
def send(self, *, to: str, message: str) -> TextResponse:
17-
"""
18-
Send a text message.
19-
Args:
20-
to (str): The recipient's phone number.
21-
message (str): The message to send.
22-
Returns:
23-
dict: The response object.
24-
Raises:
25-
ValueError: Raises an error if required fields are missing or sending the message fails.
26-
"""
17+
def send(
18+
self,
19+
*,
20+
to: str,
21+
message: str,
22+
from_: str | None = None,
23+
attachments: Sequence[str] | None = None,
24+
) -> TextResponse:
2725
try:
2826
parsed_number = phonenumbers.parse(to, None)
2927
if not phonenumbers.is_valid_number(parsed_number):
@@ -33,12 +31,16 @@ def send(self, *, to: str, message: str) -> TextResponse:
3331
msg = "parsing failed. Phone number must follow the E.164 format."
3432
raise ValueError(msg) from exc
3533

34+
payload = {
35+
"to": phonenumbers.format_number(parsed_number, phonenumbers.PhoneNumberFormat.E164),
36+
"message": message,
37+
"from": from_,
38+
"attachments": attachments,
39+
}
40+
3641
response = self._client.post(
3742
"/send/text",
38-
json={
39-
"to": phonenumbers.format_number(parsed_number, phonenumbers.PhoneNumberFormat.E164),
40-
"message": message,
41-
},
43+
json={k: v for k, v in payload.items() if v is not None},
4244
)
4345

4446
self._client.handle_error(response, fail_message="failed to send text message")

0 commit comments

Comments
 (0)