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

Wrong type in return of getChatId() of Message class #1042

Closed neo7BF closed 2 years ago

neo7BF commented 2 years ago

Hi, but the return type of getChatId() of class telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java should be String not Long.

In fact, in the examples here: https://github.com/rubenlagus/TelegramBotsExample/blob/master/src/main/java/org/telegram/updateshandlers/FilesHandlers.java is ever used in the form "... .setChatId(message.getChatId())" as if getChatId() returned a String, instead returns Long Why? Now I am forced to do: "... .setChatId(message.getChatId().toString())"

Chase22 commented 2 years ago

the Id of the Chat object is an Integer (in telegram api defined as a 52-bit signed integer), which in java terms is type long. (See: https://core.telegram.org/bots/api#chat )

The reason setChatId takes a String is because you can pass in a username of a public channel. (See for example: https://core.telegram.org/bots/api#senddocument )

One could argue that setChatId should be overloaded to take both Longs and Strings, but in my opinion the additional work in the library (since it uses generated getters and setters) outweighs the benifit of not having to write toString()

neo7BF commented 2 years ago

Ok, thanks for the reply.