TelegramBots / Telegram.Bot

.NET Client for Telegram Bot API
https://telegrambots.github.io/book
MIT License
3.22k stars 691 forks source link

Property "update.callback_query.message.date" might not exist #801

Closed poulad closed 4 months ago

poulad commented 6 years ago

Bug Report

Property Message.Date might not exist for the old callback query updates. See the update.callback_query.message descriptions.

https://github.com/TelegramBots/Telegram.Bot/blob/85134a4b5f09de4bef4306aa44d708c202b31f31/src/Telegram.Bot/Types/Message.cs#L34-L36

Note that I don't have a real old callback query update from Telegram to test this.

Steps to reproduce

Try to deserialize this update.

string update = @"{
    update_id: 1,
    callback_query: {
        id: ""5399"",
        data: ""foo/bar"",
        from: {
            id: 1234,
            first_name: ""Poulad"",
            is_bot: false
        },
        message: {
            message_id: 2744,
            from: {
                id: 1234,
                first_name: ""Poulad"",
                is_bot: false
            },
            chat: {
                id: 1234,
                type: ""private""
            }
        },
        chat_instance: ""-9999"",
        date: 1100
    }
}";
Update u = JsonConvert.DeserializeObject<Update>(update);

Expected behavior

JSON is deserialized into u object.

Actual behavior

Throws serialization exception:

Unable to deserialize update payload. Required property 'date' not found in JSON. Path 'callback_query.message', line 22, position 2

Environment data

NuGet Package Version: 14.10.0

karb0f0s commented 4 years ago

Is this still an issue? There is no signs of reproducing this behaviour for more than a year.

tuscen commented 4 years ago

I'd leave it open because there's still a probability of facing it.

karb0f0s commented 2 years ago

As of today CallbackQuery has a really vague description of this behaviour:

Field Type Description
message Message Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old

How old is "too old"? Which properties fit "message content" description? To fix this we could either introduce MessageInQuestion class (where all properties are optional), or make all properties of Message class optional (and it won't look good).

wiz0u commented 4 months ago

Solved with v21.* Undefined date will have default value as we are no longer enforcing JsonRequired fields.