pengrad / java-telegram-bot-api

Telegram Bot API for Java
https://core.telegram.org/bots
Apache License 2.0
1.79k stars 372 forks source link

Incompatible chat id types #5

Closed Tillerino closed 8 years ago

Tillerino commented 8 years ago

Chat.id() is of type Long, but all TelegramBot.send*() methods have Integer as the first argument. Not only do you have to cast the id, which is already annoying enough, but because both types are boxed, you have to do a double cast:

bot.sendWhatever((int) (long) Chat.id(), ...)

The specification says that the id field of the Chat type is an integer, so maybe Chat.id should be changed?

pengrad commented 8 years ago

Yes, you are right about Integer, but it doesn't say about Java's Integer. Here is a description of the Chat object: Unique identifier for this chat, not exceeding 1e13 by absolute value. And it's not an Integer, it's a Long.

So, I think I should change all Integer fields to Long, as 2 billions it's not enough. Probably Telegram use Integer as Int64. What do you think?

And of course, there is no need to cast bot.send( longChatId.intValue() )

maratkalibek commented 8 years ago

I think Integer is right choice.

cause in documentation - It is safe to use 32-bit signed integers for storing all Integer fields unless otherwise noted.

maratkalibek commented 8 years ago

everywhere must be used Integer type unless otherwise noted... you must return to Integer.

pengrad commented 8 years ago

@maratkalibek thanks, I was just looking for this is documentation.. But for chat_id the otherwise is noted – it's a Long. And all send* methods should use Long too.

Tillerino commented 8 years ago

@pengrad I agree. Or maybe just use long instead of Long?

maratkalibek commented 8 years ago

@pengrad hmmm, I'm looking here - https://core.telegram.org/bots/api#sendmessage

maratkalibek commented 8 years ago

where it is specified that is have to be long? as I know, there is negative values for groups and positive for users.

pengrad commented 8 years ago

Just read Chat object description

pengrad commented 8 years ago

@Tillerino I decided not to use primitives to allow null

maratkalibek commented 8 years ago

sorry, was my fault. @pengrad @Tillerino maybe start using String for send* chat_id parameters?

pengrad commented 8 years ago

I am actually thinking how to support Integer for chats and String for channels. But using String for everything it's not a good solution.