From 1c3e36343366a6ebf705c0436434498908d3cc3d Mon Sep 17 00:00:00 2001 From: lemoer Date: Sun, 29 Dec 2024 18:12:30 +0100 Subject: [PATCH] apitypes: sourceNumber can be null --- apitypes.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/apitypes.py b/apitypes.py index e5804ce..608dc1c 100644 --- a/apitypes.py +++ b/apitypes.py @@ -122,6 +122,45 @@ def test_reaction_message(): assert m.envelope.dataMessage.reaction.isRemove is False assert m.account == "+4900000000002" + # This is a message with a reaction from an anonymous + # source (where the source number is not known to the bot) + # sourceNumber is None/null here + + data2 = """{ + "envelope": { + "source": "00000000-0000-0000-0000-000000000000", + "sourceNumber": null, + "sourceUuid": "00000000-0000-0000-0000-000000000000", + "sourceName": "Anonymous", + "sourceDevice": 2, + "timestamp": 1735490493003, + "serverReceivedTimestamp": 1735490493148, + "serverDeliveredTimestamp": 1735490493149, + "dataMessage": { + "timestamp": 1735490493003, + "message": null, + "expiresInSeconds": 0, + "viewOnce": false, + "reaction": { + "emoji": "👎", + "targetAuthor": "+4900000000001", + "targetAuthorNumber": "+4900000000001", + "targetAuthorUuid": "00000000-0000-0000-0000-000000000000", + "targetSentTimestamp": 1735490231727, + "isRemove": false + } + } + }, + "account": "+4900000000001" + }""" + + res2 = parse_response(Message, data2) + assert res2.is_ok() + + m2 = res2.unwrap() + assert(m2.envelope.source == "00000000-0000-0000-0000-000000000000") + assert(m2.envelope.sourceNumber is None) + def test_simple_message(): data = """{ "envelope": { @@ -550,8 +589,8 @@ class EditMessage(BaseModel): dataMessage: DataMessage class Envelope(BaseModel): - source: str - sourceNumber: str + source: str # can be uuid or number + sourceNumber: str | None # Might be none if the bot doesn't know the phone number sourceUuid: str sourceName: str sourceDevice: int