rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.68k stars 1.18k forks source link

TelegramApiRequestException thrown due to InvalidDefinitionException construction of WriteAccessAllowed #1312

Closed rbondar closed 6 months ago

rbondar commented 7 months ago

Description Using latest https://mvnrepository.com/artifact/org.telegram/telegrambots/6.9.7.0 get on polling updates deserialization issue :

[gram Connection] o.t.t.u.DefaultBotSession : Unable to deserialize response

... meta.exceptions.TelegramApiRequestException: Unable to deserialize response ... Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of org.telegram.telegrambots.meta.api.objects.WriteAccessAllowed (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (String)

"{"ok":true,"result":[{"update_id":329421187, "message":{"message_id":120,"from":{"id":00000000,"is_bot":false,"first_name":"Alice Bob","username":"alicebob","language_code":"ru"},"chat":{"id":1111111,"first_name":"Alice Bob","username":"alicebob","type":"private"},"date":1706801738,"write_access_allowed":{"web_app_name":"shopapp"}}}]}"

; line: 2, column: 286] (through reference chain: org.telegram.telegrambots.meta.api.objects.ApiResponse["result"] ->java.util.ArrayList[0]->org.telegram.telegrambots.meta.api.objects.Update["message"] ->org.telegram.telegrambots.meta.api.objects.Message["write_access_allowed"])

To Reproduce Steps to reproduce the behavior:

  1. User opens webapp via link
  2. Telegram API Bot polls message { "ok": true, "result": [ { "update_id": 329421187, "message": { "message_id": 120, "from": { "id": 10000001, "is_bot": false, "first_name": "Alice Bob", "username": "alicebob", "language_code": "ru" }, "chat": { "id": 1111111, "first_name": "Alice Bob", "username": "alicebob", "type": "private" }, "date": 1706801738, "write_access_allowed": { "web_app_name": "shopapp" } } } ] }

Expected behavior Message serialized .

Additional context Assured that build constains the class org/telegram/telegrambots/meta/api/objects/WriteAccessAllowed.class 17 Java macos / Java 17 on redhat linux

PS Playing with removing /adding from polled message json section "write_access_allowed":{"web_app_name":"shopapp"} i got succesfull serialization -without write_access_allowed And the same failure as mentioned above - with write_access_allowed

t1mkke commented 7 months ago

Please fix it. Thanks

rubenlagus commented 6 months ago

Solved