Browse Source

1. Some api updates

master
Rubenlagu 11 years ago
committed by Rubenlagus
parent
commit
4cbf2da3d2
  1. 28
      src/main/java/org/telegram/api/Audio.java
  2. 69
      src/main/java/org/telegram/api/Voice.java
  3. 18
      src/main/java/org/telegram/methods/SendAudio.java
  4. 31
      src/main/java/org/telegram/methods/SendVoice.java

28
src/main/java/org/telegram/api/Audio.java

@ -6,8 +6,8 @@ import org.json.JSONObject;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents an audio file (voice note)
* @date 20 of June of 2015
* @brief This object represents an audio file
* @date 16 of July of 2015
*/
public class Audio {
@ -23,6 +23,12 @@ public class Audio {
public static final String FILESIZE_FIELD = "file_size";
@JsonProperty(FILESIZE_FIELD)
private Integer fileSize; ///< Optional. File size
public static final String TITLE_FIELD = "title";
@JsonProperty(TITLE_FIELD)
private String title; ///< Optional. Title of the audio as defined by sender or by audio tags
public static final String PERFORMER_FIELD = "performer";
@JsonProperty(PERFORMER_FIELD)
private String performer; ///< Optional. Performer of the audio as defined by sender or by audio tags
public Audio() {
super();
@ -34,6 +40,8 @@ public class Audio {
this.duration = jsonObject.getInt(DURATION_FIELD);
this.mimeType = jsonObject.optString(MIMETYPE_FIELD, "");
this.fileSize = jsonObject.optInt(FILESIZE_FIELD, 0);
this.title = jsonObject.optString(TITLE_FIELD, "");
this.performer = jsonObject.optString(PERFORMER_FIELD, "");
}
public String getFileId() {
@ -67,4 +75,20 @@ public class Audio {
public void setFileSize(Integer fileSize) {
this.fileSize = fileSize;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPerformer() {
return performer;
}
public void setPerformer(String performer) {
this.performer = performer;
}
}

69
src/main/java/org/telegram/api/Voice.java

@ -0,0 +1,69 @@
package org.telegram.api;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.json.JSONObject;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents a voice note
* @date 16 of July of 2015
*/
public class Voice {
public static final String FILEID_FIELD = "file_id";
@JsonProperty(FILEID_FIELD)
private String fileId; ///< Unique identifier for this file
public static final String DURATION_FIELD = "duration";
@JsonProperty(DURATION_FIELD)
private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender
public static final String MIMETYPE_FIELD = "mime_type";
@JsonProperty(MIMETYPE_FIELD)
private String mimeType; ///< Optional. MIME type of the file as defined by sender
public static final String FILESIZE_FIELD = "file_size";
@JsonProperty(FILESIZE_FIELD)
private Integer fileSize; ///< Optional. File size
public Voice() {
super();
}
public Voice(JSONObject jsonObject) {
super();
this.fileId = jsonObject.getString(FILEID_FIELD);
this.duration = jsonObject.getInt(DURATION_FIELD);
this.mimeType = jsonObject.optString(MIMETYPE_FIELD, "");
this.fileSize = jsonObject.optInt(FILESIZE_FIELD, 0);
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
public Integer getDuration() {
return duration;
}
public void setDuration(Integer duration) {
this.duration = duration;
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public Integer getFileSize() {
return fileSize;
}
public void setFileSize(Integer fileSize) {
this.fileSize = fileSize;
}
}

18
src/main/java/org/telegram/methods/SendAudio.java

@ -6,10 +6,16 @@ import org.telegram.api.ReplyKeyboard;
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send audio files,
* if you want Telegram clients to display the file as a playable voice message.
* For this to work, your audio must be in an .ogg file encoded with OPUS
* (other formats may be sent as Document). On success, the sent Message is returned.
* @date 20 of June of 2015
* Use this method to send audio files, if you want Telegram clients to display them in the music player.
* Your audio must be in an .mp3 format. On success, the sent Message is returned.
* Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
*
* @note For backward compatibility, when both fields title and description are empty and mime-type of the sent
* file is not audio/mpeg, file is sent as playable voice message.
* In this case, your audio must be in an .ogg file encoded with OPUS.
* This will be removed in the future. You need to use sendVoice method instead.
*
* @date 16 of July of 2015
*/
public class SendAudio {
public static final String PATH = "sendaudio";
@ -22,6 +28,10 @@ public class SendAudio {
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
public static final String PERFOMER_FIELD = "performer";
private String performer; ///< Optional. Performer of sent audio
public static final String TITLE_FIELD = "title";
private String title; ///< Optional. Title of sent audio
public SendAudio() {
super();

31
src/main/java/org/telegram/methods/SendVoice.java

@ -0,0 +1,31 @@
package org.telegram.methods;
import org.telegram.api.ReplyKeyboard;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send voice notes, if you want Telegram clients to display
* the file as a playable voice message.
* For this to work, your audio must be in an .ogg file encoded with OPUS
* (other formats may be sent as Audio or Document).
* @date 16 of July of 2015
*/
public class SendVoice {
public static final String PATH = "sendvoice";
public static final String CHATID_FIELD = "chat_id";
private Integer chatId; ///< Unique identifier for the message recepient — User or GroupChat id
public static final String AUDIO_FIELD = "audio";
private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
public static final String DURATION_FIELD = "duration";
private Integer duration; ///< Optional. Duration of sent audio in seconds
public SendVoice() {
super();
}
}
Loading…
Cancel
Save