77
88import httpx
99
10- from ..types import message_send_params
10+ from ..types import message_send_params , message_resend_params
1111from .._types import Body , Omit , Query , Headers , NotGiven , SequenceNotStr , omit , not_given
1212from .._utils import path_template , maybe_transform , strip_not_given , async_maybe_transform
1313from .._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 )
0 commit comments