Skip to content

Commit 9d49db2

Browse files
authored
Merge pull request #2 from textbee/feat/sms-error-history
Add errorHistory to the message type
2 parents 7b88104 + 20a15a1 commit 9d49db2

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎src/textbee/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
Direction,
1818
Message,
1919
MessageDevice,
20+
MessageIssueEntry,
21+
MessageIssueSource,
2022
MessageList,
2123
MessageListMeta,
2224
MessageStatus,
@@ -39,6 +41,8 @@
3941
"Direction",
4042
"Message",
4143
"MessageDevice",
44+
"MessageIssueEntry",
45+
"MessageIssueSource",
4246
"MessageList",
4347
"MessageListMeta",
4448
"MessageStatus",

‎src/textbee/_types.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,32 @@ class MessageDevice(_MessageDeviceRequired, total=False):
121121
enabled: bool
122122

123123

124+
MessageIssueSource = Literal["push", "device", "server"]
125+
"""Where a failure was reported from."""
126+
127+
128+
class _MessageIssueEntryRequired(TypedDict):
129+
code: str
130+
at: str
131+
"""When the failure happened. ISO date."""
132+
133+
source: MessageIssueSource
134+
135+
136+
class MessageIssueEntry(_MessageIssueEntryRequired, total=False):
137+
"""One failure a message had. Kept after the message later succeeds."""
138+
139+
message: str
140+
backfilled: bool
141+
"""Set on entries rebuilt from old message fields."""
142+
143+
deliveryReport: bool
144+
"""True for a delivery report that did not confirm delivery.
145+
146+
The message was sent; this is not a send failure.
147+
"""
148+
149+
124150
class _MessageRequired(TypedDict):
125151
_id: str
126152
message: str
@@ -142,9 +168,28 @@ class _MessageFields(_MessageRequired, total=False):
142168
sentAt: str
143169
deliveredAt: str
144170
failedAt: str
171+
"""When the message failed. Present only while status is ``failed``."""
172+
145173
receivedAt: str
146174
errorCode: str
175+
"""Current failure code. Present only while status is ``failed``.
176+
177+
Test accounts can keep ``FCM_SEND_SKIPPED``.
178+
"""
179+
147180
errorMessage: str
181+
"""Current failure text.
182+
183+
Present only while status is ``failed``, or as a timeout note on ``unknown``.
184+
"""
185+
186+
issueHistory: List[MessageIssueEntry]
187+
"""Every failure the message had, plus unconfirmed delivery reports.
188+
189+
Delivery reports carry ``deliveryReport: true`` and are not failures.
190+
Oldest first. At most 15: the first 5 and the newest 10.
191+
"""
192+
148193
simSubscriptionId: int
149194
smsBatch: str
150195
createdAt: str

‎src/textbee/_version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.1"
1+
__version__ = "0.2.0"

‎tests/test_client.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,34 @@ def test_returns_get_messages_as_data_and_meta_because_it_has_no_outer_wrapper(
329329
assert query["limit"] == "50"
330330
assert "type" not in query
331331

332+
def test_returns_error_history_on_a_message_that_failed_and_later_succeeded(
333+
self, http: FakeUrlopen
334+
) -> None:
335+
entry = {
336+
"code": "FCM_SEND_FAILED",
337+
"message": "push failed",
338+
"at": "2026-10-01T10:00:00.000Z",
339+
"source": "push",
340+
"backfilled": True,
341+
}
342+
page = {
343+
"data": [
344+
{
345+
"_id": "sms-2",
346+
"message": "hi",
347+
"type": "SENT",
348+
"status": "sent",
349+
"issueHistory": [entry],
350+
}
351+
],
352+
"meta": {},
353+
}
354+
http.respond(200, page)
355+
356+
result = client().get_messages()
357+
358+
assert result["data"][0]["issueHistory"] == [entry]
359+
332360
def test_sends_no_query_at_all_for_a_bare_get_messages(self, http: FakeUrlopen) -> None:
333361
http.respond(200, {"data": [], "meta": {}})
334362

0 commit comments

Comments
 (0)