process return of sendAudio correctly

This commit is contained in:
Marcel Caspar 2016-03-20 12:47:22 +01:00
parent 7a9a704aa0
commit 334b25b296
2 changed files with 12 additions and 4 deletions

View File

@ -138,6 +138,9 @@ public class Message implements IBotApiObject {
if (jsonObject.has(VIDEO_FIELD)) {
this.video = new Video(jsonObject.getJSONObject(VIDEO_FIELD));
}
if(jsonObject.has(AUDIO_FIELD)){
this.audio = new Audio(jsonObject.getJSONObject(AUDIO_FIELD));
}
if (jsonObject.has(CONTACT_FIELD)) {
this.contact = new Contact(jsonObject.getJSONObject(CONTACT_FIELD));
}

View File

@ -519,11 +519,16 @@ public abstract class AbsSender {
}
JSONObject jsonObject = new JSONObject(responseContent);
if (!jsonObject.getBoolean("ok")) {
throw new TelegramApiException("Error at sendAudio", jsonObject.getString("description"));
}
return new Message(jsonObject);
if(jsonObject.has("result")){
return new Message(jsonObject.getJSONObject("result"));
}
//and if not, there should be a field in our jsonObject that represents a boolean "false" with a key of "ok"
//{"description":"[Error]: Bad Request: chat not found","error_code":400,"ok":false}
// for example. and can throw an exception, cause there was an error...
throw new TelegramApiException("Error at sendAudio", jsonObject.getString("description"));
}
/**