Skip to content

Commit 1a986df

Browse files
committed
[client] support message cancellation
1 parent 5aac96f commit 1a986df

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

android_sms_gateway/client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ def send(
166166
)
167167
)
168168

169+
def cancel_message(self, _id: str) -> None:
170+
"""
171+
Cancels a pending message by ID.
172+
173+
Args:
174+
_id: The message ID.
175+
"""
176+
if self.http is None:
177+
raise ValueError("HTTP client not initialized")
178+
179+
self.http.delete(f"{self.base_url}/messages/{_id}", headers=self.headers)
180+
169181
def get_state(self, _id: str) -> domain.MessageState:
170182
"""
171183
Returns message state by ID.
@@ -583,6 +595,20 @@ async def send(
583595
)
584596
)
585597

598+
async def cancel_message(self, _id: str) -> None:
599+
"""
600+
Cancels a pending message by ID.
601+
602+
Args:
603+
_id: The message ID.
604+
"""
605+
if self.http is None:
606+
raise ValueError("HTTP client not initialized")
607+
608+
await self.http.delete(
609+
f"{self.base_url}/messages/{_id}", headers=self.headers
610+
)
611+
586612
async def get_state(self, _id: str) -> domain.MessageState:
587613
"""
588614
Returns message state by ID.

android_sms_gateway/enums.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
class ProcessState(enum.Enum):
55
Pending = "Pending"
6+
Cancelling = "Cancelling"
7+
Cancelled = "Cancelled"
68
Processed = "Processed"
79
Sent = "Sent"
810
Delivered = "Delivered"
@@ -29,6 +31,9 @@ class WebhookEvent(enum.Enum):
2931
SMS_FAILED = "sms:failed"
3032
"""Triggered when an SMS processing fails."""
3133

34+
SMS_CANCELLED = "sms:cancelled"
35+
"""Triggered when an SMS is cancelled."""
36+
3237
SYSTEM_PING = "system:ping"
3338
"""Triggered when the device pings the server."""
3439

0 commit comments

Comments
 (0)