Update version 3.5

This commit is contained in:
Ruben Bermudez 2017-11-17 15:47:22 +01:00
parent 083f020a35
commit 49c0fef3c5
24 changed files with 505 additions and 36 deletions

View File

@ -27,16 +27,16 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.4</version>
<version>3.5</version>
</dependency>
```
```gradle
compile "org.telegram:telegrambots:3.4"
compile "org.telegram:telegrambots:3.5"
```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.4)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.4)
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.5)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.5)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -1,3 +1,11 @@
### <a id="3.5"></a>3.5 ###
1. Support for Api Version [3.5](https://core.telegram.org/bots/api-changelog#november-17-2017)
2. Bug fixing: #168, #329 and #335
3. Added processInvalidCommandUpdate (#337)
4. AbilitiyBot update and tutorial (#324)
5. Add DefaultBotCommand with message ID (#330)
6. New wiki content (#326 and #327)
### <a id="3.4"></a>3.4 ###
1. Support for Api Version [3.4](https://core.telegram.org/bots/api-changelog#october-11-2017)
2. Use regular expressions to split parameters in `TelegramLongPollingCommandBot` (#309)

View File

@ -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>3.4</version>
<version>3.5</version>
</dependency>
```
* With **Gradle**:
```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '3.4'
compile group: 'org.telegram', name: 'telegrambots', version: '3.5'
```
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilties</artifactId>
<version>3.4</version>
<version>3.5</version>
</dependency>
```
* **Gradle**
```groovy
compile group: 'org.telegram', name: 'telegrambots-abilties', version: '3.4'
compile group: 'org.telegram', name: 'telegrambots-abilties', version: '3.5'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)

View File

@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>3.4</version>
<version>3.5</version>
<modules>
<module>telegrambots</module>
@ -26,6 +26,6 @@
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<bots.version>3.4</bots.version>
<bots.version>3.5</bots.version>
</properties>
</project>

View File

@ -18,19 +18,19 @@ Usage
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>3.4</version>
<version>3.5</version>
</dependency>
```
**Gradle**
```gradle
compile "org.telegram:telegrambots-abilities:3.4"
compile "org.telegram:telegrambots-abilities:3.5"
```
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v3.4)
**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v3.5)
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.4)
**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.5)
Motivation
----------

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>3.4</version>
<version>3.5</version>
<packaging>jar</packaging>
<name>Telegram Ability Bot</name>
@ -65,7 +65,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>3.4</bots.version>
<bots.version>3.5</bots.version>
<commonslang.version>3.5</commonslang.version>
<mapdb.version>3.0.4</mapdb.version>
<guava.version>19.0</guava.version>

View File

@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>3.4</version>
<version>3.5</version>
</dependency>
```
2. Using Gradle:
```gradle
compile "org.telegram:telegrambotsextensions:3.4"
compile "org.telegram:telegrambotsextensions:3.5"
```

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>3.4</version>
<version>3.5</version>
<packaging>jar</packaging>
<name>Telegram Bots Extensions</name>
@ -59,7 +59,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<bots.version>3.4</bots.version>
<bots.version>3.5</bots.version>
</properties>
<dependencies>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>3.4</version>
<version>3.5</version>
<packaging>jar</packaging>
<name>Telegram Bots Meta</name>

View File

@ -51,7 +51,7 @@ public class PromoteChatMember extends BotApiMethod<Boolean> {
@JsonProperty(CANRESTRICTMEMBERS_FIELD)
private Boolean canRestrictMembers; ///< Pass True, if the administrator can restrict, ban or unban chat members
@JsonProperty(CANPINMESSAGES_FIELD)
private Boolean canPinMessages; ///< Pass True, if the administrator can pin messages, supergroups only
private Boolean canPinMessages; ///< Pass True, if the administrator can pin messages
@JsonProperty(CANPROMOTEMEMBERS_FIELD)
private Boolean canPromoteMembers; ///< Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administators that were appointed by the him)

View File

@ -15,8 +15,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.1
* Use this method to pin a message in a supergroup.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Use this method to pin a message in a supergroup or channel.
* The bot must be an administrator in the chat for this to work and must have the can_pin_messages
* admin right in the supergroup or can_edit_messages admin right in the channel.
* Returns True on success.
*/
public class PinChatMessage extends BotApiMethod<Boolean> {
@ -27,11 +28,15 @@ public class PinChatMessage extends BotApiMethod<Boolean> {
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Required. Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId; ///< Required. Identifier of a message to pin
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Pass true, if it is not necessary to send a notification to all group members about the new pinned message
/**
* Pass True, if it is not necessary to send a notification to all chat members about the new pinned message.
* Notifications are always disabled in channels.
*/
private Boolean disableNotification;
public PinChatMessage() {
super();

View File

@ -8,7 +8,6 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.io.Serializable;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
@ -16,7 +15,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.1
* Use this method to unpin a message in a supergroup chat.
* Use this method to unpin a message in a supergroup or channel.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Returns True on success.
*/
@ -26,7 +25,7 @@ public class UnpinChatMessage extends BotApiMethod<Boolean> {
private static final String CHATID_FIELD = "chat_id";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Required. Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
private String chatId; ///< Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
public UnpinChatMessage() {
super();

View File

@ -42,7 +42,8 @@ public class SendInvoice extends BotApiMethod<Message> {
private static final String IS_FLEXIBLE_FIELD = "is_flexible";
private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification";
private static final String REPLY_TO_MESSAGE_ID_FIELD = "reply_to_message_id";
private static final String REPLY_MARKUP_FIELD = "reply_markup\t";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String PRIVIDER_DATA_FIELD = "provider_data";
@JsonProperty(CHATID_FIELD)
private Integer chatId; ///< Unique identifier for the target private chat
@ -93,6 +94,13 @@ public class SendInvoice extends BotApiMethod<Message> {
* @note If empty, one 'Buy title' button will be shown. If not empty, the first button must be a Pay button.
*/
private InlineKeyboardMarkup replyMarkup;
@JsonProperty(PRIVIDER_DATA_FIELD)
/**
* Optional JSON-encoded data about the invoice, which will be shared with the payment provider.
*
* @note A detailed description of required fields should be provided by the payment provider.
*/
private String providerData;
/**
@ -305,6 +313,15 @@ public class SendInvoice extends BotApiMethod<Message> {
return this;
}
public String getProviderData() {
return providerData;
}
public SendInvoice setProviderData(String providerData) {
this.providerData = providerData;
return this;
}
@Override
public String getMethod() {
return PATH;
@ -363,7 +380,7 @@ public class SendInvoice extends BotApiMethod<Message> {
@Override
public String toString() {
return "SendInvoice{" +
"chatId='" + chatId + '\'' +
"chatId=" + chatId +
", title='" + title + '\'' +
", description='" + description + '\'' +
", payload='" + payload + '\'' +
@ -383,6 +400,7 @@ public class SendInvoice extends BotApiMethod<Message> {
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", providerData='" + providerData + '\'' +
'}';
}
}

View File

@ -0,0 +1,144 @@
package org.telegram.telegrambots.api.methods.send;
import com.fasterxml.jackson.annotation.JsonProperty;
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.media.InputMedia;
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 java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 3.5
*
* Use this method to send a group of photos or videos as an album.
* On success, an array of the sent Messages is returned.
*/
@SuppressWarnings("unused")
public class SendMediaGroup extends PartialBotApiMethod<ArrayList<Message>> {
public static final String PATH = "sendMediaGroup";
public static final String CHATID_FIELD = "chat_id";
public static final String MEDIA_FIELD = "media";
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
@JsonProperty(MEDIA_FIELD)
private List<InputMedia> media; ///< A JSON-serialized array describing photos and videos to be sent
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the messages are a reply, ID of the original message
@JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the messages silently. Users will receive a notification with no sound.
public SendMediaGroup() {
super();
}
public SendMediaGroup(String chatId, List<InputMedia> media) {
super();
this.chatId = checkNotNull(chatId);
this.media = checkNotNull(media);
}
public SendMediaGroup(Long chatId, List<InputMedia> media) {
super();
this.chatId = checkNotNull(chatId).toString();
this.media = checkNotNull(media);
}
public String getChatId() {
return chatId;
}
public SendMediaGroup setChatId(String chatId) {
this.chatId = checkNotNull(chatId);
return this;
}
public SendMediaGroup setChatId(Long chatId) {
this.chatId = checkNotNull(chatId).toString();
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendMediaGroup setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendMediaGroup enableNotification() {
this.disableNotification = false;
return this;
}
public SendMediaGroup disableNotification() {
this.disableNotification = true;
return this;
}
public List<InputMedia> getMedia() {
return media;
}
public void setMedia(List<InputMedia> media) {
this.media = media;
}
@Override
public ArrayList<Message> deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<ArrayList<Message>> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<ArrayList<Message>>>() {
});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error sending media group", 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 (media == null || media.isEmpty()) {
throw new TelegramApiValidationException("Media parameter can't be empty", this);
}
for (InputMedia inputMedia : media) {
inputMedia.validate();
}
}
@Override
public String toString() {
return "SendMediaGroup{" +
"chatId='" + chatId + '\'' +
", media=" + media +
", replyToMessageId=" + replyToMessageId +
", disableNotification=" + disableNotification +
'}';
}
}

View File

@ -41,7 +41,7 @@ public class ChatMember implements BotApiObject {
@JsonProperty(CANPOSTMESSAGES_FIELD)
private Boolean canPostMessages; ///< Optional. Administrators only. True, if the administrator can post in the channel, channels only
@JsonProperty(CANEDITMESSAGES_FIELD)
private Boolean canEditMessages; ///< Optional. Administrators only. True, if the administrator can edit messages of other users, channels only
private Boolean canEditMessages; ///< Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only
@JsonProperty(CANDELETEMESSAGES_FIELD)
private Boolean canDeleteMessages; ///< Optional. Administrators only. True, if the administrator can delete messages of other users
@JsonProperty(CANINVITEUSERS_FIELD)
@ -49,7 +49,7 @@ public class ChatMember implements BotApiObject {
@JsonProperty(CANRESTRICTUSERS_FIELD)
private Boolean canRestrictUsers; ///< Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
@JsonProperty(CANPINMESSAGES_FIELD)
private Boolean canPinMessages; ///< Optional. Administrators only. True, if the administrator can pin messages, supergroups only
private Boolean canPinMessages; ///< Optional. Administrators only. True, if the administrator can pin messages
@JsonProperty(CANPROMOTEMEMBERS_FIELD)
private Boolean canPromoteMembers; ///< Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that it has promoted, directly or indirectly (promoted by administators that were appointed by the bot)
@JsonProperty(CANSENDMESSAGES_FIELD)

View File

@ -55,6 +55,7 @@ public class Message implements BotApiObject {
private static final String VIDEO_NOTE_FIELD = "video_note";
private static final String AUTHORSIGNATURE_FIELD = "author_signature";
private static final String FORWARDSIGNATURE_FIELD = "forward_signature";
private static final String MEDIAGROUPID_FIELD = "media_group_id";
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId; ///< Integer Unique message identifier
@ -172,7 +173,8 @@ public class Message implements BotApiObject {
private String authorSignature; ///< Optional. Post author signature for posts in channel chats
@JsonProperty(FORWARDSIGNATURE_FIELD)
private String forwardSignature; ///< Optional. Post author signature for messages forwarded from channel chats
@JsonProperty(MEDIAGROUPID_FIELD)
private String mediaGroupId;
public Message() {
super();
@ -412,6 +414,10 @@ public class Message implements BotApiObject {
return forwardSignature;
}
public String getMediaGroupId() {
return mediaGroupId;
}
@Override
public String toString() {
return "Message{" +
@ -455,6 +461,7 @@ public class Message implements BotApiObject {
", videoNote=" + videoNote +
", authorSignature='" + authorSignature + '\'' +
", forwardSignature='" + forwardSignature + '\'' +
", mediaGroupId='" + mediaGroupId + '\'' +
'}';
}
}

View File

@ -0,0 +1,132 @@
package org.telegram.telegrambots.api.objects.media;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
* @version 3.5
*/
public abstract class InputMedia<T> implements InputBotApiObject, Validable {
protected static final String TYPE_FIELD = "type";
private static final String MEDIA_FIELD = "media";
private static final String CAPTION_FIELD = "caption";
@JsonProperty(MEDIA_FIELD)
/**
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
* pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://<file_attach_name>"
* to upload a new one using multipart/form-data under <file_attach_name> name.
*/
private String media;
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the media to be sent, 0-200 characters
@JsonIgnore
private boolean isNewMedia; ///< True to upload a new media, false to use a fileId or URL
@JsonIgnore
private String mediaName; ///< Name of the media to upload
@JsonIgnore
private File newMediaFile; ///< New media file
@JsonIgnore
private InputStream newMediaStream; ///< New media stream
public InputMedia() {
super();
}
public InputMedia(String media, String caption) {
this.media = media;
this.caption = caption;
}
public String getMedia() {
return media;
}
public File getMediaFile() {
return newMediaFile;
}
public InputStream getNewMediaStream() {
return newMediaStream;
}
public String getMediaName() {
return mediaName;
}
@JsonIgnore
public boolean isNewMedia() {
return isNewMedia;
}
/**
* Use this setter to send an existing file (using file_id) or an url.
* @param media File_id or URL of the file to send
* @return This object
*/
public T setMedia(String media) {
this.media = media;
this.isNewMedia = false;
return (T) this;
}
/**
* Use this setter to send new file.
* @param mediaFile File to send
* @return This object
*/
public T setMedia(File mediaFile, String fileName) {
this.newMediaFile = mediaFile;
this.isNewMedia = true;
this.mediaName = fileName;
this.media = "attach://" + fileName;
return (T) this;
}
/**
* Use this setter to send new file as stream.
* @param mediaStream File to send
* @return This object
*/
public T setMedia(InputStream mediaStream, String fileName) {
this.newMediaStream = mediaStream;
this.isNewMedia = true;
this.mediaName = fileName;
this.media = "attach://" + fileName;
return (T) this;
}
public String getCaption() {
return caption;
}
public InputMedia setCaption(String caption) {
this.caption = caption;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (isNewMedia) {
if (mediaName == null || mediaName.isEmpty()) {
throw new TelegramApiValidationException("Media name can't be empty", this);
}
if (newMediaFile == null && newMediaStream == null) {
throw new TelegramApiValidationException("Media can't be empty", this);
}
} else if (media == null || media.isEmpty()) {
throw new TelegramApiValidationException("Media can't be empty", this);
}
}
@JsonProperty(TYPE_FIELD)
public abstract String getType();
}

View File

@ -0,0 +1,32 @@
package org.telegram.telegrambots.api.objects.media;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 3.5
*
* Represents a photo.
*/
@SuppressWarnings("unused")
public class InputMediaPhoto extends InputMedia<InputMediaPhoto> {
private static final String TYPE = "photo";
public InputMediaPhoto() {
super();
}
public InputMediaPhoto(String media, String caption) {
super(media, caption);
}
@Override
public String getType() {
return TYPE;
}
@Override
public void validate() throws TelegramApiValidationException {
super.validate();
}
}

View File

@ -0,0 +1,71 @@
package org.telegram.telegrambots.api.objects.media;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 3.5
*
* Represents a video.
*/
@SuppressWarnings("unused")
public class InputMediaVideo extends InputMedia<InputMediaVideo> {
private static final String TYPE = "video";
private static final String WIDTH_FIELD = "width";
private static final String HEIGHT_FIELD = "height";
private static final String DURATION_FIELD = "duration";
@JsonProperty(WIDTH_FIELD)
private int width; ///< Optional. Video width
@JsonProperty(HEIGHT_FIELD)
private int height; ///< Optional. Video height
@JsonProperty(DURATION_FIELD)
private int duration; ///< Optional. Video duration
public InputMediaVideo() {
super();
}
public InputMediaVideo(String media, String caption) {
super(media, caption);
}
public int getWidth() {
return width;
}
public InputMediaVideo setWidth(int width) {
this.width = width;
return this;
}
public int getHeight() {
return height;
}
public InputMediaVideo setHeight(int height) {
this.height = height;
return this;
}
public int getDuration() {
return duration;
}
public InputMediaVideo setDuration(int duration) {
this.duration = duration;
return this;
}
@Override
public String getType() {
return TYPE;
}
@Override
public void validate() throws TelegramApiValidationException {
super.validate();
}
}

View File

@ -825,6 +825,13 @@ public abstract class AbsSender {
*/
public abstract Message sendVoice(SendVoice sendVoice) throws TelegramApiException;
/**
* Send a media group (https://core.telegram.org/bots/api#sendMediaGroup)
* @return If success, list of generated messages
* @throws TelegramApiException If there is any error sending the media group
*/
public abstract List<Message> sendMediaGroup(SendMediaGroup sendMediaGroup) throws TelegramApiException;
/**
* Set chat profile photo (https://core.telegram.org/bots/api#setChatPhoto)
* @param setChatPhoto Information to set the photo

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.4</version>
<version>3.5</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>3.4</bots.version>
<bots.version>3.5</bots.version>
</properties>
<dependencyManagement>

View File

@ -22,6 +22,7 @@ import org.telegram.telegrambots.api.methods.stickers.CreateNewStickerSet;
import org.telegram.telegrambots.api.methods.stickers.UploadStickerFile;
import org.telegram.telegrambots.api.objects.File;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.media.InputMedia;
import org.telegram.telegrambots.exceptions.TelegramApiException;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
@ -33,6 +34,7 @@ import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -497,6 +499,49 @@ public abstract class DefaultAbsSender extends AbsSender {
}
}
@Override
public List<Message> sendMediaGroup(SendMediaGroup sendMediaGroup) throws TelegramApiException {
assertParamNotNull(sendMediaGroup, "sendMediaGroup");
sendMediaGroup.validate();
try {
String url = getBaseUrl() + SendMediaGroup.PATH;
HttpPost httppost = configuredHttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setLaxMode();
builder.setCharset(StandardCharsets.UTF_8);
builder.addTextBody(SendMediaGroup.CHATID_FIELD, sendMediaGroup.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
builder.addTextBody(SendMediaGroup.MEDIA_FIELD, objectMapper.writeValueAsString(sendMediaGroup.getMedia()), TEXT_PLAIN_CONTENT_TYPE);
for (InputMedia inputMedia : sendMediaGroup.getMedia()) {
if (inputMedia.isNewMedia()) {
if (inputMedia.getMediaFile() != null) {
builder.addBinaryBody(inputMedia.getMediaName(), inputMedia.getMediaFile(), ContentType.APPLICATION_OCTET_STREAM, inputMedia.getMediaName());
} else if (inputMedia.getNewMediaStream() != null) {
builder.addBinaryBody(inputMedia.getMediaName(), inputMedia.getNewMediaStream(), ContentType.APPLICATION_OCTET_STREAM, inputMedia.getMediaName());
}
}
}
if (sendMediaGroup.getDisableNotification() != null) {
builder.addTextBody(SendMediaGroup.DISABLENOTIFICATION_FIELD, sendMediaGroup.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendMediaGroup.getReplyToMessageId() != null) {
builder.addTextBody(SendMediaGroup.REPLYTOMESSAGEID_FIELD, sendMediaGroup.getReplyToMessageId().toString(), TEXT_PLAIN_CONTENT_TYPE);
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
return sendMediaGroup.deserializeResponse(sendHttpPostRequest(httppost));
} catch (IOException e) {
throw new TelegramApiException("Unable to set chat photo", e);
}
}
@Override
public Boolean addStickerToSet(AddStickerToSet addStickerToSet) throws TelegramApiException {

View File

@ -26,6 +26,7 @@ public class DefaultBotOptions implements BotOptions {
baseUrl = ApiConstants.BASE_URL;
}
@Override
public String getBaseUrl() {
return baseUrl;
}