rubenlagus / TelegramBots

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

sendPhoto fails to return resulting json #58

Closed heyferh closed 8 years ago

heyferh commented 8 years ago

Greetings, the following code snippet from the bottom of AbsSender::sendPhoto method fails to create new Message object.

JSONObject jsonObject1 = new JSONObject(responseContent);
        if(!jsonObject1.getBoolean("ok")) {
            throw new TelegramApiException("Error at sendPhoto", jsonObject1.getString("description"));
        } else {
            return new Message(jsonObject1);
        }
public Message(JSONObject jsonObject) {
        this.messageId = Integer.valueOf(jsonObject.getInt("message_id"));
        if(jsonObject.has("from")) {
            this.from = new User(jsonObject.getJSONObject("from"));
        }

the Message constructor is reading json wrong (there are 2 top level fields: ok and result), have to jsonObject.getJSONObject("result") first

Clevero commented 8 years ago

Create a pull request if you have tested your code

@rubenlagus is always happy about contributions :wink:

heyferh commented 8 years ago

Ok 👍 thx, @Clevero

heyferh commented 8 years ago

Well, I think @antonu17 has already started the same fix, it seems like there are another similar bugs in SendVideo, SendDocument etc. https://github.com/antonu17/TelegramBots/commit/60cb6687d5a65e67adea697a752d18f6eec12b33

antonu17 commented 8 years ago

I see. I made several commits after pull request, so i don't think it will be accepted. Lets wait for @rubenlagus reaction.

dapoldi commented 8 years ago

Hey guys :) give us some time, should be soon but we have a few more projects that require attention at the moment.

rubenlagus commented 8 years ago

@antonu17 @heyferh Can you check with version v2.3 ? Sorry about these issues, but none of my bots currently use those methods so I didn't noticed

antonu17 commented 8 years ago

I confirm it working well now.