Skip to content

Commit f6ce695

Browse files
committed
Ignore statuses from turn payload
1 parent 625914e commit f6ce695

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/turn_webhook.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel, ConfigDict
1+
from pydantic import BaseModel, ConfigDict, Field
22

33

44
class TurnBaseModel(BaseModel):
@@ -16,4 +16,5 @@ class TurnMessage(TurnBaseModel):
1616

1717

1818
class TurnWebhook(TurnBaseModel):
19-
messages: list[TurnMessage]
19+
messages: list[TurnMessage] = Field(default_factory=list)
20+
statuses: list[dict] = Field(default_factory=list)

tests/test_application.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_nlu_invalid_payload(client):
105105
""""""
106106

107107
body = json.dumps(
108-
{"not_messages": []}, separators=(",", ":"), sort_keys=True
108+
{"messages": "not-a-list"}, separators=(",", ":"), sort_keys=True
109109
).encode()
110110
signature = _sign_payload(body, app.config["TURN_HMAC_SECRET"])
111111

@@ -117,3 +117,31 @@ def test_nlu_invalid_payload(client):
117117
)
118118
assert response.status_code == 400
119119
assert response.json["error"] == "invalid payload"
120+
121+
122+
def test_nlu_status_only_payload_is_ignored(client, mocker):
123+
"""Status webhooks should be accepted and ignored."""
124+
125+
mock_build_chain = mocker.patch("src.application.build_classify_and_update_chain")
126+
127+
payload = {
128+
"statuses": [
129+
{
130+
"id": "wamid.HBgLMjc4MzYzNzg1MzEVAgARGBI2QTBBOTM1MDdFNUEwRDJDOEMA",
131+
"status": "delivered",
132+
"timestamp": "1773842339",
133+
}
134+
]
135+
}
136+
body = json.dumps(payload, separators=(",", ":"), sort_keys=True).encode()
137+
signature = _sign_payload(body, app.config["TURN_HMAC_SECRET"])
138+
139+
response = client.post(
140+
"/nlu/",
141+
data=body,
142+
content_type="application/json",
143+
headers={"X-Turn-Hook-Signature": signature},
144+
)
145+
assert response.status_code == 200
146+
assert response.json == {"status": "ignored", "count": 0}
147+
mock_build_chain.assert_not_called()

0 commit comments

Comments
 (0)