apitypes: sourceNumber can be null

This commit is contained in:
lemoer 2024-12-29 18:12:30 +01:00
parent 286588e0fe
commit 1c3e363433

View File

@ -122,6 +122,45 @@ def test_reaction_message():
assert m.envelope.dataMessage.reaction.isRemove is False assert m.envelope.dataMessage.reaction.isRemove is False
assert m.account == "+4900000000002" 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(): def test_simple_message():
data = """{ data = """{
"envelope": { "envelope": {
@ -550,8 +589,8 @@ class EditMessage(BaseModel):
dataMessage: DataMessage dataMessage: DataMessage
class Envelope(BaseModel): class Envelope(BaseModel):
source: str source: str # can be uuid or number
sourceNumber: str sourceNumber: str | None # Might be none if the bot doesn't know the phone number
sourceUuid: str sourceUuid: str
sourceName: str sourceName: str
sourceDevice: int sourceDevice: int