API 3.0
This commit is contained in:
parent
fc712656fa
commit
5937a2e3a6
@ -27,12 +27,12 @@ Just import add the library to your project with one of these options:
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>2.4.4.6</version>
|
||||
<version>3.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/2.4.4.6)
|
||||
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/2.4.4.6)
|
||||
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.0)
|
||||
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/3.0)
|
||||
|
||||
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
||||
|
||||
|
@ -44,10 +44,13 @@
|
||||
5. Added custom ExponentialBackOff waiting time when having network problems in long-polling mode. (Custom implementation is allowed via BotOptions)
|
||||
6. Bug fixing: #184, #183
|
||||
|
||||
### <a id="2.4.4.6"></a>2.4.4.6 ###
|
||||
### <a id="3.0"></a>3.0 ###
|
||||
1. New field `gif_duration` and `mpeg4_duration` in `InlineQueryResultGif` and `InlineQueryResultMpeg4Gif`.
|
||||
2. Field `new_chat_member` was replaced by `new_chat_members` in `Message` object.
|
||||
3. Some methods gets now constructors with mandatory parameters to simplify their creation (including preconditions).
|
||||
4. New Payments API methods
|
||||
4. New `deleteMessage` method.
|
||||
5. New field `language_code` in `User` object.
|
||||
6. New Payments API methods
|
||||
7. New Video Messages API methods
|
||||
|
||||
**[[How to update to version 2.4.4.6|How-To-Update#2.4.4.6]]**
|
||||
**[[How to update to version 3.0|How-To-Update#3.0]]**
|
@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>2.4.4.6</version>
|
||||
<version>3.0</version>
|
||||
</dependency>
|
||||
```
|
||||
* With **Gradle**:
|
||||
|
||||
```groovy
|
||||
compile group: 'org.telegram', name: 'telegrambots', version: '2.4.4.6'
|
||||
compile group: 'org.telegram', name: 'telegrambots', version: '3.0'
|
||||
```
|
||||
|
||||
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
|
||||
|
@ -22,5 +22,5 @@
|
||||
1. All calls to `editMessageText`, `editMessageCaption` or `editMessageReplyMarkup` in `AbsSender` return value is changed to `Serializable`
|
||||
2. In `editMessageTextAsync`, `editMessageCaptionAsync` or `editMessageReplyMarkupAsync` in `AbsSender`, second parameter should become `SentCallback<Serializable>` due to new return type.
|
||||
|
||||
### <a id="2.4.4.6"></a>To version 2.4.4.6 ###
|
||||
### <a id="3.0"></a>To version 3.0 ###
|
||||
1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users.
|
4
pom.xml
4
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>Bots</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.4.4.6</version>
|
||||
<version>3.0</version>
|
||||
|
||||
<modules>
|
||||
<module>telegrambots</module>
|
||||
@ -24,6 +24,6 @@
|
||||
|
||||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
<bots.version>2.4.4.6</bots.version>
|
||||
<bots.version>3.0</bots.version>
|
||||
</properties>
|
||||
</project>
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-meta</artifactId>
|
||||
<version>2.4.4.6</version>
|
||||
<version>3.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Telegram Bots Meta</name>
|
||||
|
@ -13,13 +13,14 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* @brief Use this method when you need to tell the user that something is happening on the bot's
|
||||
* Use this method when you need to tell the user that something is happening on the bot's
|
||||
* side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram
|
||||
* clients clear its typing status).
|
||||
* @date 20 of June of 2015
|
||||
*/
|
||||
public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
|
||||
@ -31,10 +32,10 @@ public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
/**
|
||||
* Type of action to broadcast. Choose one, depending on what the user is about to receive:
|
||||
* 'typing' for text messages 'upload_photo' for photos 'record_video' or 'upload_video' for
|
||||
* videos 'record_audio' or 'upload_audio' for audio files 'upload_document' for general files,
|
||||
* 'find_location' for location data.
|
||||
* Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages,
|
||||
* upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files,
|
||||
* upload_document for general files, find_location for location data,
|
||||
* record_video_note or upload_video_note for video notes.
|
||||
*/
|
||||
@JsonProperty(ACTION_FIELD)
|
||||
private String action;
|
||||
@ -43,6 +44,16 @@ public class SendChatAction extends BotApiMethod<Boolean> {
|
||||
super();
|
||||
}
|
||||
|
||||
public SendChatAction(String chatId, String action) {
|
||||
this.chatId = checkNotNull(chatId);
|
||||
this.action = checkNotNull(action);
|
||||
}
|
||||
|
||||
public SendChatAction(Integer chatId, String action) {
|
||||
this.chatId = checkNotNull(chatId).toString();
|
||||
this.action = checkNotNull(action);
|
||||
}
|
||||
|
||||
public String getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
@ -14,11 +14,12 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* @brief Use this method to send text messages. On success, the sent Message is returned.
|
||||
* @date 20 of June of 2015
|
||||
* Use this method to send text messages. On success, the sent Message is returned.
|
||||
*/
|
||||
public class SendMessage extends BotApiMethod<Message> {
|
||||
public static final String PATH = "sendmessage";
|
||||
@ -50,6 +51,16 @@ public class SendMessage extends BotApiMethod<Message> {
|
||||
super();
|
||||
}
|
||||
|
||||
public SendMessage(String chatId, String text) {
|
||||
this.chatId = checkNotNull(chatId);
|
||||
this.text = checkNotNull(text);
|
||||
}
|
||||
|
||||
public SendMessage(Integer chatId, String text) {
|
||||
this.chatId = checkNotNull(chatId).toString();
|
||||
this.text = checkNotNull(text);
|
||||
}
|
||||
|
||||
public String getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
@ -0,0 +1,282 @@
|
||||
package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.telegram.telegrambots.api.methods.PartialBotApiMethod;
|
||||
import org.telegram.telegrambots.api.objects.Message;
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ApiResponse;
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
|
||||
* Use this method to send video messages. On success, the sent Message is returned.
|
||||
*/
|
||||
public class SendVideoNote extends PartialBotApiMethod<Message> {
|
||||
public static final String PATH = "sendvideonote";
|
||||
|
||||
public static final String CHATID_FIELD = "chat_id";
|
||||
public static final String VIDEONOTE_FIELD = "video_note";
|
||||
public static final String DURATION_FIELD = "duration";
|
||||
public static final String LENGTH_FIELD = "length";
|
||||
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
|
||||
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
|
||||
public static final String REPLYMARKUP_FIELD = "reply_markup";
|
||||
|
||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||
private String videoNote; ///< Videonote to send. file_id as String to resend a video that is already on the Telegram servers.
|
||||
private Integer duration; ///< Optional. Duration of sent video in seconds
|
||||
private Integer length; ///< Optional. Video width and height
|
||||
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
|
||||
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
|
||||
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
|
||||
|
||||
private boolean isNewVideoNote; ///< True to upload a new video note, false to use a fileId
|
||||
private String videoNoteName; ///< Name of the video
|
||||
private File newVideoNoteFile; ///< New video note file
|
||||
private InputStream newVideoNoteStream; ///< New video note stream
|
||||
|
||||
public SendVideoNote() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new video note with a video already present in telegram servers
|
||||
* @param chatId Chat Id to send the video note
|
||||
* @param videoNote Video note file_id to send
|
||||
*/
|
||||
public SendVideoNote(String chatId, String videoNote) {
|
||||
this.chatId = checkNotNull(chatId);
|
||||
this.videoNote = checkNotNull(videoNote);
|
||||
this.isNewVideoNote = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new video note with a video already present in telegram servers
|
||||
* @param chatId Chat Id to send the video note
|
||||
* @param videoNote Video note file_id to send
|
||||
*/
|
||||
public SendVideoNote(Integer chatId, String videoNote) {
|
||||
this.chatId = checkNotNull(chatId).toString();
|
||||
this.videoNote = checkNotNull(videoNote);
|
||||
this.isNewVideoNote = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new video note with a new video note
|
||||
* @param chatId Chat Id to send the video note
|
||||
* @param newVideoNoteFile Video note file to upload
|
||||
*/
|
||||
public SendVideoNote(String chatId, File newVideoNoteFile) {
|
||||
this.chatId = checkNotNull(chatId);
|
||||
this.newVideoNoteFile = checkNotNull(newVideoNoteFile);
|
||||
this.isNewVideoNote = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new video note with a video already present in telegram servers
|
||||
* @param chatId Chat Id to send the video note
|
||||
* @param newVideoNoteFile Video note file to upload
|
||||
*/
|
||||
public SendVideoNote(Integer chatId, File newVideoNoteFile) {
|
||||
this.chatId = checkNotNull(chatId).toString();
|
||||
this.newVideoNoteFile = checkNotNull(newVideoNoteFile);
|
||||
this.isNewVideoNote = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new video note with a new video note
|
||||
* @param chatId Chat Id to send the video note
|
||||
* @param videoNoteName Name of the video note file
|
||||
* @param newVideoNoteStream Video note file to upload
|
||||
*/
|
||||
public SendVideoNote(String chatId, String videoNoteName, InputStream newVideoNoteStream) {
|
||||
this.chatId = checkNotNull(chatId);
|
||||
this.videoNoteName = checkNotNull(videoNoteName);
|
||||
this.newVideoNoteStream = checkNotNull(newVideoNoteStream);
|
||||
this.isNewVideoNote = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new video note with a video already present in telegram servers
|
||||
* @param chatId Chat Id to send the video note
|
||||
* @param videoNoteName Name of the video note file
|
||||
* @param newVideoNoteStream Video note file to upload
|
||||
*/
|
||||
public SendVideoNote(Integer chatId, String videoNoteName, InputStream newVideoNoteStream) {
|
||||
this.chatId = checkNotNull(chatId).toString();
|
||||
this.videoNoteName = checkNotNull(videoNoteName);
|
||||
this.newVideoNoteStream = checkNotNull(newVideoNoteStream);
|
||||
this.isNewVideoNote = true;
|
||||
}
|
||||
|
||||
public String getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public SendVideoNote setChatId(String chatId) {
|
||||
this.chatId = chatId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getVideoNote() {
|
||||
return videoNote;
|
||||
}
|
||||
|
||||
public SendVideoNote setVideoNote(String videoNote) {
|
||||
this.videoNote = videoNote;
|
||||
this.isNewVideoNote = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public SendVideoNote setLength(Integer length) {
|
||||
this.length = length;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendVideoNote setChatId(Long chatId) {
|
||||
Objects.requireNonNull(chatId);
|
||||
this.chatId = chatId.toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public SendVideoNote setDuration(Integer duration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getReplyToMessageId() {
|
||||
return replyToMessageId;
|
||||
}
|
||||
|
||||
public SendVideoNote setReplyToMessageId(Integer replyToMessageId) {
|
||||
this.replyToMessageId = replyToMessageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReplyKeyboard getReplyMarkup() {
|
||||
return replyMarkup;
|
||||
}
|
||||
|
||||
public SendVideoNote setReplyMarkup(ReplyKeyboard replyMarkup) {
|
||||
this.replyMarkup = replyMarkup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getDisableNotification() {
|
||||
return disableNotification;
|
||||
}
|
||||
|
||||
public SendVideoNote enableNotification() {
|
||||
this.disableNotification = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendVideoNote disableNotification() {
|
||||
this.disableNotification = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isNewVideoNote() {
|
||||
return isNewVideoNote;
|
||||
}
|
||||
|
||||
public SendVideoNote setNewVideoNote(File file) {
|
||||
this.isNewVideoNote = true;
|
||||
this.newVideoNoteFile = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendVideoNote setNewVideo(String videoName, InputStream inputStream) {
|
||||
Objects.requireNonNull(videoName, "videoName cannot be null!");
|
||||
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
|
||||
this.videoNoteName = videoName;
|
||||
this.isNewVideoNote = true;
|
||||
this.newVideoNoteStream = inputStream;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getVideoNoteName() {
|
||||
return videoNoteName;
|
||||
}
|
||||
|
||||
public File getNewVideoNoteFile() {
|
||||
return newVideoNoteFile;
|
||||
}
|
||||
|
||||
public InputStream getNewVideoNoteStream() {
|
||||
return newVideoNoteStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Message>>(){});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error sending video", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
|
||||
if (isNewVideoNote) {
|
||||
if (newVideoNoteFile == null && newVideoNoteStream == null) {
|
||||
throw new TelegramApiValidationException("Videonote can't be empty", this);
|
||||
}
|
||||
if (newVideoNoteStream != null && (videoNoteName == null || videoNoteName.isEmpty())) {
|
||||
throw new TelegramApiValidationException("Video note name can't be empty", this);
|
||||
}
|
||||
} else if (videoNote == null) {
|
||||
throw new TelegramApiValidationException("Video note can't be empty", this);
|
||||
}
|
||||
if (replyMarkup != null) {
|
||||
replyMarkup.validate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SendVideoNote{" +
|
||||
"chatId='" + chatId + '\'' +
|
||||
", videoNote='" + videoNote + '\'' +
|
||||
", duration=" + duration +
|
||||
", length=" + length +
|
||||
", disableNotification=" + disableNotification +
|
||||
", replyToMessageId=" + replyToMessageId +
|
||||
", replyMarkup=" + replyMarkup +
|
||||
", isNewVideoNote=" + isNewVideoNote +
|
||||
", videoNoteName='" + videoNoteName + '\'' +
|
||||
", newVideoNoteFile=" + newVideoNoteFile +
|
||||
", newVideoNoteStream=" + newVideoNoteStream +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package org.telegram.telegrambots.api.methods.updatingmessages;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.telegram.telegrambots.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ApiResponse;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*
|
||||
* Use this method to delete a message. A message can only be deleted if it was sent less than
|
||||
* 48 hours ago. Any sent outgoing message may be deleted.
|
||||
* Additionally, if the bot is an administrator in a group chat, it can delete any message.
|
||||
* If the bot is an administrator of a supergroup or channel,
|
||||
* it can delete ordinary messages from any other user,
|
||||
* including service messages about people added or removed from the chat.
|
||||
*/
|
||||
public class DeleteMessage extends BotApiMethod<Boolean> {
|
||||
public static final String PATH = "deleteMessage";
|
||||
|
||||
private static final String CHATID_FIELD = "chat_id";
|
||||
private static final String MESSAGEID_FIELD = "message_id";
|
||||
|
||||
/**
|
||||
* Unique identifier for the chat to send the message to (Or username for channels)
|
||||
*/
|
||||
@JsonProperty(CHATID_FIELD)
|
||||
private String chatId;
|
||||
/**
|
||||
* Identifier of the message to delete
|
||||
*/
|
||||
@JsonProperty(MESSAGEID_FIELD)
|
||||
private Integer messageId;
|
||||
|
||||
public DeleteMessage() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DeleteMessage(String chatId, Integer messageId) {
|
||||
this.chatId = checkNotNull(chatId);
|
||||
this.messageId = checkNotNull(messageId);
|
||||
}
|
||||
|
||||
public DeleteMessage(Integer chatId, Integer messageId) {
|
||||
this.chatId = checkNotNull(chatId).toString();
|
||||
this.messageId = checkNotNull(messageId);
|
||||
}
|
||||
|
||||
public String getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public DeleteMessage setChatId(String chatId) {
|
||||
this.chatId = chatId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public DeleteMessage setMessageId(Integer messageId) {
|
||||
this.messageId = messageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
|
||||
try {
|
||||
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
|
||||
new TypeReference<ApiResponse<Boolean>>() {
|
||||
});
|
||||
if (result.getOk()) {
|
||||
return result.getResult();
|
||||
} else {
|
||||
throw new TelegramApiRequestException("Error editing message caption", result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiRequestException("Unable to deserialize response", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws TelegramApiValidationException {
|
||||
if (chatId == null) {
|
||||
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
|
||||
}
|
||||
if (messageId == null) {
|
||||
throw new TelegramApiValidationException("MessageId parameter can't be empty", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeleteMessage{" +
|
||||
"chatId='" + chatId + '\'' +
|
||||
", messageId=" + messageId +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -11,8 +11,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
* @brief This object represents a message.
|
||||
* @date 20 of June of 2015
|
||||
* This object represents a message.
|
||||
*/
|
||||
public class Message implements BotApiObject {
|
||||
private static final String MESSAGEID_FIELD = "message_id";
|
||||
@ -51,6 +50,7 @@ public class Message implements BotApiObject {
|
||||
private static final String FORWARDFROMMESSAGEID_FIELD = "forward_from_message_id";
|
||||
private static final String INVOICE_FIELD = "invoice";
|
||||
private static final String SUCCESSFUL_PAYMENT_FIELD = "successful_payment";
|
||||
private static final String VIDEO_NOTE_FIELD = "video_note";
|
||||
|
||||
@JsonProperty(MESSAGEID_FIELD)
|
||||
private Integer messageId; ///< Integer Unique message identifier
|
||||
@ -93,7 +93,7 @@ public class Message implements BotApiObject {
|
||||
@JsonProperty(PINNED_MESSAGE_FIELD)
|
||||
private Message pinnedMessage; ///< Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
|
||||
@JsonProperty(NEWCHATMEMBERS_FIELD)
|
||||
private List<User> newChatMembers; ///< Optional. New members were added to the group or supergroup, information about them (there are may be the bot itself among them)
|
||||
private List<User> newChatMembers; ///< Optional. New members were added to the group or supergroup, information about them (the bot itself may be one of these members)
|
||||
@JsonProperty(LEFTCHATMEMBER_FIELD)
|
||||
private User leftChatMember; ///< Optional. A member was removed from the group, information about them (this member may be bot itself)
|
||||
@JsonProperty(NEWCHATTITLE_FIELD)
|
||||
@ -156,6 +156,8 @@ public class Message implements BotApiObject {
|
||||
private Invoice invoice; ///< Optional. Message is an invoice for a payment, information about the invoice.
|
||||
@JsonProperty(SUCCESSFUL_PAYMENT_FIELD)
|
||||
private SuccessfulPayment successfulPayment; ///< Optional. Message is a service message about a successful payment, information about the payment.
|
||||
@JsonProperty(VIDEO_NOTE_FIELD)
|
||||
private VideoNote videoNote; ///< Optional. Message is a video note, information about the video message
|
||||
|
||||
public Message() {
|
||||
super();
|
||||
@ -374,6 +376,10 @@ public class Message implements BotApiObject {
|
||||
return successfulPayment;
|
||||
}
|
||||
|
||||
public VideoNote getVideoNote() {
|
||||
return videoNote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message{" +
|
||||
@ -413,6 +419,7 @@ public class Message implements BotApiObject {
|
||||
", forwardFromMessageId=" + forwardFromMessageId +
|
||||
", invoice=" + invoice +
|
||||
", successfulPayment=" + successfulPayment +
|
||||
", videoNote=" + videoNote +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package org.telegram.telegrambots.api.objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.telegram.telegrambots.api.interfaces.BotApiObject;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
*
|
||||
* This object represents a video message (available in Telegram apps as of v.4.0).
|
||||
*/
|
||||
public class VideoNote implements BotApiObject {
|
||||
private static final String FILEID_FIELD = "file_id";
|
||||
private static final String LENGTH_FIELD = "length";
|
||||
private static final String DURATION_FIELD = "duration";
|
||||
private static final String THUMB_FIELD = "thumb";
|
||||
private static final String FILESIZE_FIELD = "file_size";
|
||||
|
||||
@JsonProperty(FILEID_FIELD)
|
||||
private String fileId; ///< Unique identifier for this file
|
||||
@JsonProperty(LENGTH_FIELD)
|
||||
private Integer length; ///< Video width and height as defined by sender
|
||||
@JsonProperty(DURATION_FIELD)
|
||||
private Integer duration; ///< Duration of the video in seconds as defined by sender
|
||||
@JsonProperty(THUMB_FIELD)
|
||||
private PhotoSize thumb; ///< Optional. Video thumbnail
|
||||
@JsonProperty(FILESIZE_FIELD)
|
||||
private Integer fileSize; ///< Optional. File size
|
||||
|
||||
public VideoNote() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public Integer getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public Integer getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public PhotoSize getThumb() {
|
||||
return thumb;
|
||||
}
|
||||
|
||||
public Integer getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VideoNote{" +
|
||||
"fileId='" + fileId + '\'' +
|
||||
", length=" + length +
|
||||
", duration=" + duration +
|
||||
", thumb=" + thumb +
|
||||
", fileSize=" + fileSize +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
package org.telegram.telegrambots.api.objects.replykeyboard.buttons;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.telegram.telegrambots.api.interfaces.InputBotApiObject;
|
||||
import org.telegram.telegrambots.api.interfaces.Validable;
|
||||
import org.telegram.telegrambots.api.objects.games.CallbackGame;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -23,7 +24,7 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
|
||||
private static final String CALLBACK_GAME_FIELD = "callback_game";
|
||||
private static final String SWITCH_INLINE_QUERY_FIELD = "switch_inline_query";
|
||||
private static final String SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD = "switch_inline_query_current_chat";
|
||||
private static final String BUY_FIELD = "buy";
|
||||
private static final String PAY_FIELD = "pay";
|
||||
|
||||
@JsonProperty(TEXT_FIELD)
|
||||
private String text; ///< Label text on the button
|
||||
@ -64,13 +65,17 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
|
||||
*
|
||||
* @note This type of button must always be the first button in the first row.
|
||||
*/
|
||||
@JsonProperty(BUY_FIELD)
|
||||
private Boolean buy;
|
||||
@JsonProperty(PAY_FIELD)
|
||||
private Boolean pay;
|
||||
|
||||
public InlineKeyboardButton() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InlineKeyboardButton(String text) {
|
||||
this.text = checkNotNull(text);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
@ -125,12 +130,12 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getBuy() {
|
||||
return buy;
|
||||
public Boolean getPay() {
|
||||
return pay;
|
||||
}
|
||||
|
||||
public InlineKeyboardButton setBuy(Boolean buy) {
|
||||
this.buy = buy;
|
||||
public InlineKeyboardButton setPay(Boolean pay) {
|
||||
this.pay = pay;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -150,7 +155,7 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
|
||||
", callbackGame=" + callbackGame +
|
||||
", switchInlineQuery='" + switchInlineQuery + '\'' +
|
||||
", switchInlineQueryCurrentChat='" + switchInlineQueryCurrentChat + '\'' +
|
||||
", buy=" + buy +
|
||||
", pay=" + pay +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.telegram.telegrambots.api.methods.groupadministration.*;
|
||||
import org.telegram.telegrambots.api.methods.send.*;
|
||||
import org.telegram.telegrambots.api.methods.updates.DeleteWebhook;
|
||||
import org.telegram.telegrambots.api.methods.updates.GetWebhookInfo;
|
||||
import org.telegram.telegrambots.api.methods.updatingmessages.DeleteMessage;
|
||||
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageCaption;
|
||||
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageReplyMarkup;
|
||||
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageText;
|
||||
@ -241,6 +242,13 @@ public abstract class AbsSender {
|
||||
return sendApiMethod(answerPreCheckoutQuery);
|
||||
}
|
||||
|
||||
public final Boolean deleteMessage(DeleteMessage deleteMessage) throws TelegramApiException {
|
||||
if(deleteMessage == null){
|
||||
throw new TelegramApiException("Parameter deleteMessage can not be null");
|
||||
}
|
||||
return sendApiMethod(deleteMessage);
|
||||
}
|
||||
|
||||
// Send Requests Async
|
||||
|
||||
public final void sendMessageAsync(SendMessage sendMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||
@ -552,6 +560,16 @@ public abstract class AbsSender {
|
||||
sendApiMethodAsync(answerPreCheckoutQuery, sentCallback);
|
||||
}
|
||||
|
||||
public final void deleteMessage(DeleteMessage deleteMessage, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
||||
if (deleteMessage == null) {
|
||||
throw new TelegramApiException("Parameter deleteMessage can not be null");
|
||||
}
|
||||
if (sentCallback == null) {
|
||||
throw new TelegramApiException("Parameter sentCallback can not be null");
|
||||
}
|
||||
sendApiMethodAsync(deleteMessage, sentCallback);
|
||||
}
|
||||
|
||||
// Specific Send Requests
|
||||
public abstract Message sendDocument(SendDocument sendDocument) throws TelegramApiException;
|
||||
|
||||
@ -559,6 +577,8 @@ public abstract class AbsSender {
|
||||
|
||||
public abstract Message sendVideo(SendVideo sendVideo) throws TelegramApiException;
|
||||
|
||||
public abstract Message sendVideoNote(SendVideoNote sendVideoNote) throws TelegramApiException;
|
||||
|
||||
public abstract Message sendSticker(SendSticker sendSticker) throws TelegramApiException;
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>2.4.4.6</version>
|
||||
<version>3.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Telegram Bots</name>
|
||||
@ -66,7 +66,7 @@
|
||||
<jackson.version>2.8.7</jackson.version>
|
||||
<jacksonanotation.version>2.8.0</jacksonanotation.version>
|
||||
<commonio.version>2.5</commonio.version>
|
||||
<bots.version>2.4.4.6</bots.version>
|
||||
<bots.version>3.0</bots.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.telegram.telegrambots.bots;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.NameValuePair;
|
||||
@ -20,12 +19,7 @@ import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.telegram.telegrambots.ApiConstants;
|
||||
import org.telegram.telegrambots.api.methods.BotApiMethod;
|
||||
import org.telegram.telegrambots.api.methods.send.SendAudio;
|
||||
import org.telegram.telegrambots.api.methods.send.SendDocument;
|
||||
import org.telegram.telegrambots.api.methods.send.SendPhoto;
|
||||
import org.telegram.telegrambots.api.methods.send.SendSticker;
|
||||
import org.telegram.telegrambots.api.methods.send.SendVideo;
|
||||
import org.telegram.telegrambots.api.methods.send.SendVoice;
|
||||
import org.telegram.telegrambots.api.methods.send.*;
|
||||
import org.telegram.telegrambots.api.objects.File;
|
||||
import org.telegram.telegrambots.api.objects.Message;
|
||||
import org.telegram.telegrambots.exceptions.TelegramApiException;
|
||||
@ -403,6 +397,79 @@ public abstract class DefaultAbsSender extends AbsSender {
|
||||
return sendVideo.deserializeResponse(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Message sendVideoNote(SendVideoNote sendVideoNote) throws TelegramApiException {
|
||||
if(sendVideoNote == null){
|
||||
throw new TelegramApiException("Parameter sendVideoNote can not be null");
|
||||
}
|
||||
|
||||
sendVideoNote.validate();
|
||||
String responseContent;
|
||||
try {
|
||||
String url = getBaseUrl() + SendVideoNote.PATH;
|
||||
HttpPost httppost = new HttpPost(url);
|
||||
httppost.setConfig(requestConfig);
|
||||
if (sendVideoNote.isNewVideoNote()) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addTextBody(SendVideoNote.CHATID_FIELD, sendVideoNote.getChatId());
|
||||
if (sendVideoNote.getNewVideoNoteFile() != null) {
|
||||
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getNewVideoNoteFile());
|
||||
} else if (sendVideoNote.getNewVideoNoteStream() != null) {
|
||||
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getNewVideoNoteStream(), ContentType.APPLICATION_OCTET_STREAM, sendVideoNote.getVideoNoteName());
|
||||
} else {
|
||||
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, new java.io.File(sendVideoNote.getVideoNote()), ContentType.APPLICATION_OCTET_STREAM, sendVideoNote.getVideoNoteName());
|
||||
}
|
||||
if (sendVideoNote.getReplyMarkup() != null) {
|
||||
builder.addTextBody(SendVideoNote.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendVideoNote.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
|
||||
}
|
||||
if (sendVideoNote.getReplyToMessageId() != null) {
|
||||
builder.addTextBody(SendVideoNote.REPLYTOMESSAGEID_FIELD, sendVideoNote.getReplyToMessageId().toString());
|
||||
}
|
||||
if (sendVideoNote.getDuration() != null) {
|
||||
builder.addTextBody(SendVideoNote.DURATION_FIELD, sendVideoNote.getDuration().toString());
|
||||
}
|
||||
if (sendVideoNote.getLength() != null) {
|
||||
builder.addTextBody(SendVideoNote.LENGTH_FIELD, sendVideoNote.getLength().toString());
|
||||
}
|
||||
if (sendVideoNote.getDisableNotification() != null) {
|
||||
builder.addTextBody(SendVideoNote.DISABLENOTIFICATION_FIELD, sendVideoNote.getDisableNotification().toString());
|
||||
}
|
||||
HttpEntity multipart = builder.build();
|
||||
httppost.setEntity(multipart);
|
||||
} else {
|
||||
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
||||
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.CHATID_FIELD, sendVideoNote.getChatId()));
|
||||
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getVideoNote()));
|
||||
if (sendVideoNote.getReplyMarkup() != null) {
|
||||
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendVideoNote.getReplyMarkup())));
|
||||
}
|
||||
if (sendVideoNote.getReplyToMessageId() != null) {
|
||||
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.REPLYTOMESSAGEID_FIELD, sendVideoNote.getReplyToMessageId().toString()));
|
||||
}
|
||||
if (sendVideoNote.getDuration() != null) {
|
||||
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.DURATION_FIELD, sendVideoNote.getDuration().toString()));
|
||||
}
|
||||
if (sendVideoNote.getLength() != null) {
|
||||
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.LENGTH_FIELD, sendVideoNote.getLength().toString()));
|
||||
}
|
||||
if (sendVideoNote.getDisableNotification() != null) {
|
||||
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.DISABLENOTIFICATION_FIELD, sendVideoNote.getDisableNotification().toString()));
|
||||
}
|
||||
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
try (CloseableHttpResponse response = httpclient.execute(httppost)) {
|
||||
HttpEntity ht = response.getEntity();
|
||||
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
|
||||
responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TelegramApiException("Unable to send video note", e);
|
||||
}
|
||||
|
||||
return sendVideoNote.deserializeResponse(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Message sendSticker(SendSticker sendSticker) throws TelegramApiException {
|
||||
if(sendSticker == null){
|
||||
|
@ -39,11 +39,6 @@ import com.google.common.base.Preconditions;
|
||||
* <b>Note:</b> max_interval caps the retry_interval and not the randomized_interval.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If the time elapsed since an {@link ExponentialBackOff} instance is created goes past the
|
||||
* max_elapsed_time then the method {@link #nextBackOffMillis()} starts returning
|
||||
* {@link ExponentialBackOff#STOP}. The elapsed time can be reset by calling {@link #reset()}.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Example: The default retry_interval is .5 seconds, default randomization_factor is 0.5, default
|
||||
|
Loading…
Reference in New Issue
Block a user