Skip to content

Commit 80368f0

Browse files
author
stlc-bot
committed
feat(api): add messages.resend to resend a message on its id
Stainless-Generated-From: 28cfce3
1 parent f6c4605 commit 80368f0

7 files changed

Lines changed: 306 additions & 11 deletions

File tree

‎.stats.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 67
1+
configured_endpoints: 68

‎README.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ client = Sent(
3232
api_key=os.environ.get("SENT_DM_API_KEY"), # This is the default and can be omitted
3333
)
3434

35-
response = client.messages.send(
35+
message_send_response = client.messages.send(
3636
channel=["sms", "whatsapp"],
3737
template={
3838
"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8",
@@ -44,7 +44,7 @@ response = client.messages.send(
4444
},
4545
to=["+14155551234", "+14155555678"],
4646
)
47-
print(response.data)
47+
print(message_send_response.data)
4848
```
4949

5050
While you can provide an `api_key` keyword argument,
@@ -67,7 +67,7 @@ client = AsyncSent(
6767

6868

6969
async def main() -> None:
70-
response = await client.messages.send(
70+
message_send_response = await client.messages.send(
7171
channel=["sms", "whatsapp"],
7272
template={
7373
"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8",
@@ -79,7 +79,7 @@ async def main() -> None:
7979
},
8080
to=["+14155551234", "+14155555678"],
8181
)
82-
print(response.data)
82+
print(message_send_response.data)
8383

8484

8585
asyncio.run(main())
@@ -112,7 +112,7 @@ async def main() -> None:
112112
api_key=os.environ.get("SENT_DM_API_KEY"), # This is the default and can be omitted
113113
http_client=DefaultAioHttpClient(),
114114
) as client:
115-
response = await client.messages.send(
115+
message_send_response = await client.messages.send(
116116
channel=["sms", "whatsapp"],
117117
template={
118118
"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8",
@@ -124,7 +124,7 @@ async def main() -> None:
124124
},
125125
to=["+14155551234", "+14155555678"],
126126
)
127-
print(response.data)
127+
print(message_send_response.data)
128128

129129

130130
asyncio.run(main())
@@ -209,7 +209,7 @@ from sent_dm import Sent
209209

210210
client = Sent()
211211

212-
response = client.messages.send(
212+
message_send_response = client.messages.send(
213213
template={
214214
"id": "7ba7b820-9dad-11d1-80b4-00c04fd430c8",
215215
"name": "order_confirmation",
@@ -219,7 +219,7 @@ response = client.messages.send(
219219
},
220220
},
221221
)
222-
print(response.template)
222+
print(message_send_response.template)
223223
```
224224

225225
## Handling errors

‎api.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,15 @@ Types:
159159

160160
```python
161161
from sent_dm.types import (
162+
MessageSendResponse,
162163
MessageRetrieveActivitiesResponse,
163164
MessageRetrieveStatusResponse,
164-
MessageSendResponse,
165165
)
166166
```
167167

168168
Methods:
169169

170+
- <code title="post /v3/messages/{id}/resend">client.messages.<a href="./src/sent_dm/resources/messages.py">resend</a>(id, \*\*<a href="src/sent_dm/types/message_resend_params.py">params</a>) -> <a href="./src/sent_dm/types/message_send_response.py">MessageSendResponse</a></code>
170171
- <code title="get /v3/messages/{id}/activities">client.messages.<a href="./src/sent_dm/resources/messages.py">retrieve_activities</a>(id) -> <a href="./src/sent_dm/types/message_retrieve_activities_response.py">MessageRetrieveActivitiesResponse</a></code>
171172
- <code title="get /v3/messages/{id}">client.messages.<a href="./src/sent_dm/resources/messages.py">retrieve_status</a>(id) -> <a href="./src/sent_dm/types/message_retrieve_status_response.py">MessageRetrieveStatusResponse</a></code>
172173
- <code title="post /v3/messages">client.messages.<a href="./src/sent_dm/resources/messages.py">send</a>(\*\*<a href="src/sent_dm/types/message_send_params.py">params</a>) -> <a href="./src/sent_dm/types/message_send_response.py">MessageSendResponse</a></code>

‎src/sent_dm/resources/messages.py‎

Lines changed: 167 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import httpx
99

10-
from ..types import message_send_params
10+
from ..types import message_send_params, message_resend_params
1111
from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
1212
from .._utils import path_template, maybe_transform, strip_not_given, async_maybe_transform
1313
from .._compat import cached_property
@@ -57,6 +57,83 @@ def with_streaming_response(self) -> MessagesResourceWithStreamingResponse:
5757
"""
5858
return MessagesResourceWithStreamingResponse(self)
5959

60+
def resend(
61+
self,
62+
id: str,
63+
*,
64+
sandbox: bool | Omit = omit,
65+
idempotency_key: str | Omit = omit,
66+
x_profile_id: str | Omit = omit,
67+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
68+
# The extra values given here take precedence over values defined on the client or passed to this method.
69+
extra_headers: Headers | None = None,
70+
extra_query: Query | None = None,
71+
extra_body: Body | None = None,
72+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
73+
) -> MessageSendResponse:
74+
"""
75+
Resends a message you already sent, on the same message id, without rebuilding
76+
the request. The typical use is recovering a BLOCKED message — for example one
77+
refused for insufficient balance — after the account has been topped up.
78+
79+
**A resend bills again.** Each accepted resend is a new delivery attempt and
80+
records a new charge against the same message id; a client that resends on every
81+
failure is charged on every loop.
82+
83+
**Every policy runs again.** The resend goes back through the full send pipeline
84+
— consent, balance, KYC and channel quota, template approval, quiet hours and
85+
channel health — so it can land on BLOCKED, FILTERED or SCHEDULED again rather
86+
than being sent, exactly as a fresh send would. Status webhooks (message.sent,
87+
message.blocked, message.filtered, message.failed) fire again for the same
88+
message id, so consumers keyed on the id will see repeated transitions.
89+
90+
**What can be resent.** A message in a terminal state — DELIVERED, FAILED, READ
91+
or BLOCKED — or one stuck at SENT for more than 15 minutes. A FILTERED message
92+
can never be resent: the recipient opted out or a routing rule refused the send.
93+
A message still in flight (QUEUED, PROCESSED, ROUTED), held for quiet hours
94+
(SCHEDULED), or SENT less than 15 minutes ago returns 409. Two concurrent
95+
resends of one id are serialised: one is accepted, the other gets 409.
96+
97+
The resend keeps the channel the message was originally requested on; the
98+
channel cannot be changed on a resend — send a new message instead.
99+
`Idempotency-Key` is honoured, so a retried request replays the first accepted
100+
response instead of resending twice.
101+
102+
The response has the same shape as `POST /v3/messages`: `recipients` has a
103+
single entry whose `message_id` is the id you resent.
104+
105+
Args:
106+
sandbox: Sandbox flag - when true, the operation is simulated without side effects Useful
107+
for testing integrations without actual execution
108+
109+
extra_headers: Send extra headers
110+
111+
extra_query: Add additional query parameters to the request
112+
113+
extra_body: Add additional JSON properties to the request
114+
115+
timeout: Override the client-level default timeout for this request, in seconds
116+
"""
117+
if not id:
118+
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
119+
extra_headers = {
120+
**strip_not_given(
121+
{
122+
"Idempotency-Key": idempotency_key,
123+
"x-profile-id": x_profile_id,
124+
}
125+
),
126+
**(extra_headers or {}),
127+
}
128+
return self._post(
129+
path_template("/v3/messages/{id}/resend", id=id),
130+
body=maybe_transform({"sandbox": sandbox}, message_resend_params.MessageResendParams),
131+
options=make_request_options(
132+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
133+
),
134+
cast_to=MessageSendResponse,
135+
)
136+
60137
def retrieve_activities(
61138
self,
62139
id: str,
@@ -338,6 +415,83 @@ def with_streaming_response(self) -> AsyncMessagesResourceWithStreamingResponse:
338415
"""
339416
return AsyncMessagesResourceWithStreamingResponse(self)
340417

418+
async def resend(
419+
self,
420+
id: str,
421+
*,
422+
sandbox: bool | Omit = omit,
423+
idempotency_key: str | Omit = omit,
424+
x_profile_id: str | Omit = omit,
425+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
426+
# The extra values given here take precedence over values defined on the client or passed to this method.
427+
extra_headers: Headers | None = None,
428+
extra_query: Query | None = None,
429+
extra_body: Body | None = None,
430+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
431+
) -> MessageSendResponse:
432+
"""
433+
Resends a message you already sent, on the same message id, without rebuilding
434+
the request. The typical use is recovering a BLOCKED message — for example one
435+
refused for insufficient balance — after the account has been topped up.
436+
437+
**A resend bills again.** Each accepted resend is a new delivery attempt and
438+
records a new charge against the same message id; a client that resends on every
439+
failure is charged on every loop.
440+
441+
**Every policy runs again.** The resend goes back through the full send pipeline
442+
— consent, balance, KYC and channel quota, template approval, quiet hours and
443+
channel health — so it can land on BLOCKED, FILTERED or SCHEDULED again rather
444+
than being sent, exactly as a fresh send would. Status webhooks (message.sent,
445+
message.blocked, message.filtered, message.failed) fire again for the same
446+
message id, so consumers keyed on the id will see repeated transitions.
447+
448+
**What can be resent.** A message in a terminal state — DELIVERED, FAILED, READ
449+
or BLOCKED — or one stuck at SENT for more than 15 minutes. A FILTERED message
450+
can never be resent: the recipient opted out or a routing rule refused the send.
451+
A message still in flight (QUEUED, PROCESSED, ROUTED), held for quiet hours
452+
(SCHEDULED), or SENT less than 15 minutes ago returns 409. Two concurrent
453+
resends of one id are serialised: one is accepted, the other gets 409.
454+
455+
The resend keeps the channel the message was originally requested on; the
456+
channel cannot be changed on a resend — send a new message instead.
457+
`Idempotency-Key` is honoured, so a retried request replays the first accepted
458+
response instead of resending twice.
459+
460+
The response has the same shape as `POST /v3/messages`: `recipients` has a
461+
single entry whose `message_id` is the id you resent.
462+
463+
Args:
464+
sandbox: Sandbox flag - when true, the operation is simulated without side effects Useful
465+
for testing integrations without actual execution
466+
467+
extra_headers: Send extra headers
468+
469+
extra_query: Add additional query parameters to the request
470+
471+
extra_body: Add additional JSON properties to the request
472+
473+
timeout: Override the client-level default timeout for this request, in seconds
474+
"""
475+
if not id:
476+
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
477+
extra_headers = {
478+
**strip_not_given(
479+
{
480+
"Idempotency-Key": idempotency_key,
481+
"x-profile-id": x_profile_id,
482+
}
483+
),
484+
**(extra_headers or {}),
485+
}
486+
return await self._post(
487+
path_template("/v3/messages/{id}/resend", id=id),
488+
body=await async_maybe_transform({"sandbox": sandbox}, message_resend_params.MessageResendParams),
489+
options=make_request_options(
490+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
491+
),
492+
cast_to=MessageSendResponse,
493+
)
494+
341495
async def retrieve_activities(
342496
self,
343497
id: str,
@@ -592,6 +746,9 @@ class MessagesResourceWithRawResponse:
592746
def __init__(self, messages: MessagesResource) -> None:
593747
self._messages = messages
594748

749+
self.resend = to_raw_response_wrapper(
750+
messages.resend,
751+
)
595752
self.retrieve_activities = to_raw_response_wrapper(
596753
messages.retrieve_activities,
597754
)
@@ -607,6 +764,9 @@ class AsyncMessagesResourceWithRawResponse:
607764
def __init__(self, messages: AsyncMessagesResource) -> None:
608765
self._messages = messages
609766

767+
self.resend = async_to_raw_response_wrapper(
768+
messages.resend,
769+
)
610770
self.retrieve_activities = async_to_raw_response_wrapper(
611771
messages.retrieve_activities,
612772
)
@@ -622,6 +782,9 @@ class MessagesResourceWithStreamingResponse:
622782
def __init__(self, messages: MessagesResource) -> None:
623783
self._messages = messages
624784

785+
self.resend = to_streamed_response_wrapper(
786+
messages.resend,
787+
)
625788
self.retrieve_activities = to_streamed_response_wrapper(
626789
messages.retrieve_activities,
627790
)
@@ -637,6 +800,9 @@ class AsyncMessagesResourceWithStreamingResponse:
637800
def __init__(self, messages: AsyncMessagesResource) -> None:
638801
self._messages = messages
639802

803+
self.resend = async_to_streamed_response_wrapper(
804+
messages.resend,
805+
)
640806
self.retrieve_activities = async_to_streamed_response_wrapper(
641807
messages.retrieve_activities,
642808
)

‎src/sent_dm/types/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from .contact_update_params import ContactUpdateParams as ContactUpdateParams
4343
from .inbound_message_event import InboundMessageEvent as InboundMessageEvent
4444
from .message_event_payload import MessageEventPayload as MessageEventPayload
45+
from .message_resend_params import MessageResendParams as MessageResendParams
4546
from .message_send_response import MessageSendResponse as MessageSendResponse
4647
from .payment_details_param import PaymentDetailsParam as PaymentDetailsParam
4748
from .profile_create_params import ProfileCreateParams as ProfileCreateParams
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Annotated, TypedDict
6+
7+
from .._utils import PropertyInfo
8+
9+
__all__ = ["MessageResendParams"]
10+
11+
12+
class MessageResendParams(TypedDict, total=False):
13+
sandbox: bool
14+
"""
15+
Sandbox flag - when true, the operation is simulated without side effects Useful
16+
for testing integrations without actual execution
17+
"""
18+
19+
idempotency_key: Annotated[str, PropertyInfo(alias="Idempotency-Key")]
20+
21+
x_profile_id: Annotated[str, PropertyInfo(alias="x-profile-id")]

0 commit comments

Comments
 (0)