diff --git a/Bots.ipr b/Bots.ipr
index 94516c63..fa84a71b 100644
--- a/Bots.ipr
+++ b/Bots.ipr
@@ -36,6 +36,466 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -46,9 +506,39 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -129,9 +619,6 @@
/usr/local/bin/bower
-
-
-
@@ -262,7 +749,32 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -960,6 +1472,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index f2180275..0e7e1639 100644
--- a/README.md
+++ b/README.md
@@ -27,16 +27,16 @@ Just import add the library to your project with one of these options:
org.telegram
telegrambots
- 3.5
+ 3.6
```
```gradle
- compile "org.telegram:telegrambots:3.5"
+ compile "org.telegram:telegrambots:3.6"
```
- 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)
+ 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.6)
+ 3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.6)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md
index bbe00b59..1509ad43 100644
--- a/TelegramBots.wiki/Changelog.md
+++ b/TelegramBots.wiki/Changelog.md
@@ -1,3 +1,7 @@
+### 3.6 ###
+1. Support for Api Version [3.6](https://core.telegram.org/bots/api-changelog#february-13-2018)
+2. Bug fixing and other improvements
+
### 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
diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md
index 618c16cf..da550b3f 100644
--- a/TelegramBots.wiki/Getting-Started.md
+++ b/TelegramBots.wiki/Getting-Started.md
@@ -11,7 +11,7 @@ First you need ot get the library and add it to your project. There are few poss
org.telegram
telegrambots
- 3.5
+ 3.6
```
* With **Gradle**:
@@ -53,7 +53,7 @@ Now that we have the library, we can start coding. There are few steps to follow
```
- * `getBotUsermane()`: This method must always return your **Bot username**. May look like:
+ * `getBotUsername()`: This method must always return your **Bot username**. May look like:
```java
diff --git a/TelegramBots.wiki/abilities/Advanced.md b/TelegramBots.wiki/abilities/Advanced.md
index 962f83e7..044a55b0 100644
--- a/TelegramBots.wiki/abilities/Advanced.md
+++ b/TelegramBots.wiki/abilities/Advanced.md
@@ -1,7 +1,7 @@
# Advanced
This will be more of a FAQ on some important notes before you embark on your next big bot project!
-## Default Abilties
+## Default Abilities
It is possible to declare "DEFAULT" abilities that process non-command messages. This is quite close to a reply. If a user says "Hey there" and the default ability is implemented, it will process this input.
```java
diff --git a/TelegramBots.wiki/abilities/Simple-Example.md b/TelegramBots.wiki/abilities/Simple-Example.md
index 8b718183..a64fb9d0 100644
--- a/TelegramBots.wiki/abilities/Simple-Example.md
+++ b/TelegramBots.wiki/abilities/Simple-Example.md
@@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
org.telegram
telegrambots-abilties
- 3.5
+ 3.6
```
* **Gradle**
```groovy
- compile group: 'org.telegram', name: 'telegrambots-abilties', version: '3.5'
+ compile group: 'org.telegram', name: 'telegrambots-abilties', version: '3.6'
```
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
diff --git a/pom.xml b/pom.xml
index 8a836e48..dc751700 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
org.telegram
Bots
pom
- 3.5
+ 3.6
telegrambots
@@ -26,6 +26,6 @@
true
- 3.5
+ 3.6
\ No newline at end of file
diff --git a/telegrambots-abilities/README.md b/telegrambots-abilities/README.md
index 7819d41f..8b01640f 100644
--- a/telegrambots-abilities/README.md
+++ b/telegrambots-abilities/README.md
@@ -18,19 +18,19 @@ Usage
org.telegram
telegrambots-abilities
- 3.5
+ 3.6
```
**Gradle**
```gradle
- compile "org.telegram:telegrambots-abilities:3.5"
+ compile "org.telegram:telegrambots-abilities:3.6"
```
-**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v3.5)
+**JitPack** - [JitPack](https://jitpack.io/#rubenlagus/TelegramBots/v3.6)
-**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.5)
+**Plain imports** - [Here](https://github.com/rubenlagus/TelegramBots/releases/tag/v3.6)
Motivation
----------
diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml
index bd9d85ef..c89607e7 100644
--- a/telegrambots-abilities/pom.xml
+++ b/telegrambots-abilities/pom.xml
@@ -5,7 +5,7 @@
4.0.0
org.telegram
telegrambots-abilities
- 3.5
+ 3.6
jar
Telegram Ability Bot
@@ -65,7 +65,7 @@
UTF-8
UTF-8
- 3.5
+ 3.6
3.5
3.0.4
19.0
diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java
index c512e7c4..a9c4e0e3 100644
--- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java
+++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java
@@ -10,6 +10,7 @@ import org.telegram.abilitybots.api.util.AbilityUtils;
import org.telegram.abilitybots.api.util.Pair;
import org.telegram.abilitybots.api.util.Trio;
import org.telegram.telegrambots.api.methods.GetFile;
+import org.telegram.telegrambots.api.methods.groupadministration.GetChatAdministrators;
import org.telegram.telegrambots.api.methods.send.SendDocument;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
@@ -24,10 +25,7 @@ import java.io.FileReader;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -413,10 +411,10 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
Set blacklist = blacklist();
if (blacklist.contains(userId))
- silent.sendMd(format("%s is already *banned*.", bannedUser), ctx.chatId());
+ silent.sendMd(format("%s is already *banned*.", escape(bannedUser)), ctx.chatId());
else {
blacklist.add(userId);
- silent.sendMd(format("%s is now *banned*.", bannedUser), ctx.chatId());
+ silent.sendMd(format("%s is now *banned*.", escape(bannedUser)), ctx.chatId());
}
})
.post(commitTo(db))
@@ -441,9 +439,9 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
Set blacklist = blacklist();
if (!blacklist.remove(userId))
- silent.sendMd(format("@%s is *not* on the *blacklist*.", username), ctx.chatId());
+ silent.sendMd(format("@%s is *not* on the *blacklist*.", escape(username)), ctx.chatId());
else {
- silent.sendMd(format("@%s, your ban has been *lifted*.", username), ctx.chatId());
+ silent.sendMd(format("@%s, your ban has been *lifted*.", escape(username)), ctx.chatId());
}
})
.post(commitTo(db))
@@ -465,10 +463,10 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
Set admins = admins();
if (admins.contains(userId))
- silent.sendMd(format("@%s is already an *admin*.", username), ctx.chatId());
+ silent.sendMd(format("@%s is already an *admin*.", escape(username)), ctx.chatId());
else {
admins.add(userId);
- silent.sendMd(format("@%s has been *promoted*.", username), ctx.chatId());
+ silent.sendMd(format("@%s has been *promoted*.", escape(username)), ctx.chatId());
}
}).post(commitTo(db))
.build();
@@ -489,9 +487,9 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
Set admins = admins();
if (admins.remove(userId)) {
- silent.sendMd(format("@%s has been *demoted*.", username), ctx.chatId());
+ silent.sendMd(format("@%s has been *demoted*.", escape(username)), ctx.chatId());
} else {
- silent.sendMd(format("@%s is *not* an *admin*.", username), ctx.chatId());
+ silent.sendMd(format("@%s is *not* an *admin*.", escape(username)), ctx.chatId());
}
})
.post(commitTo(db))
@@ -540,7 +538,7 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
abilities = stream(this.getClass().getMethods())
.filter(method -> method.getReturnType().equals(Ability.class))
.map(this::returnAbility)
- .collect(toMap(Ability::name, identity()));
+ .collect(toMap(ability -> ability.name().toLowerCase(), identity()));
Stream methodReplies = stream(this.getClass().getMethods())
.filter(method -> method.getReturnType().equals(Reply.class))
@@ -617,7 +615,7 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
boolean isOk = abilityTokens == 0 || (tokens.length > 0 && tokens.length == abilityTokens);
if (!isOk)
- silent.send(String.format("Sorry, this feature requires %d additional %s.", abilityTokens, abilityTokens == 1 ? "input" : "inputs"), getChatId(trio.a()));
+ silent.send(format("Sorry, this feature requires %d additional %s.", abilityTokens, abilityTokens == 1 ? "input" : "inputs"), getChatId(trio.a()));
return isOk;
}
@@ -629,7 +627,7 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
boolean isOk = abilityLocality == ALL || locality == abilityLocality;
if (!isOk)
- silent.send(String.format("Sorry, %s-only feature.", abilityLocality.toString().toLowerCase()), getChatId(trio.a()));
+ silent.send(format("Sorry, %s-only feature.", abilityLocality.toString().toLowerCase()), getChatId(trio.a()));
return isOk;
}
@@ -639,15 +637,24 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
Privacy privacy;
int id = user.id();
- privacy = isCreator(id) ? CREATOR : isAdmin(id) ? ADMIN : PUBLIC;
+ privacy = isCreator(id) ? CREATOR : isAdmin(id) ? ADMIN : isGroupAdmin(update, id)? GROUP_ADMIN : PUBLIC;
boolean isOk = privacy.compareTo(trio.b().privacy()) >= 0;
if (!isOk)
- silent.send(String.format("Sorry, %s-only feature.", trio.b().privacy().toString().toLowerCase()), getChatId(trio.a()));
+ silent.send("Sorry, you don't have the required access level to do that.", getChatId(trio.a()));
+
return isOk;
}
+ private boolean isGroupAdmin(Update update, int id) {
+ GetChatAdministrators admins = new GetChatAdministrators().setChatId(getChatId(update));
+
+ return isGroupUpdate(update) && silent.execute(admins)
+ .orElse(new ArrayList<>()).stream()
+ .anyMatch(member -> member.getUser().getId() == id);
+ }
+
private boolean isCreator(int id) {
return id == creatorId();
}
@@ -667,11 +674,10 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
if (!update.hasMessage() || !msg.hasText())
return Trio.of(update, abilities.get(DEFAULT), new String[]{});
- // Priority goes to text before captions
String[] tokens = msg.getText().split(" ");
if (tokens[0].startsWith("/")) {
- String abilityToken = stripBotUsername(tokens[0].substring(1));
+ String abilityToken = stripBotUsername(tokens[0].substring(1)).toLowerCase();
Ability ability = abilities.get(abilityToken);
tokens = Arrays.copyOfRange(tokens, 1, tokens.length);
return Trio.of(update, ability, tokens);
@@ -743,4 +749,8 @@ public abstract class AbilityBot extends TelegramLongPollingBot {
private File downloadFileWithId(String fileId) throws TelegramApiException {
return sender.downloadFile(sender.execute(new GetFile().setFileId(fileId)));
}
+
+ private String escape(String username) {
+ return username.replace("_", "\\_");
+ }
}
\ No newline at end of file
diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Privacy.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Privacy.java
index 90d13cef..51d40937 100644
--- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Privacy.java
+++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/objects/Privacy.java
@@ -10,6 +10,10 @@ public enum Privacy {
* Anybody who is not a bot admin or its creator will be considered as a public user.
*/
PUBLIC,
+ /**
+ * Only group admins would get to initiate this command.
+ */
+ GROUP_ADMIN,
/**
* A global admin of the bot, regardless of the group the bot is in.
*/
diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java
index d0586039..8852170f 100644
--- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java
+++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/util/AbilityUtils.java
@@ -64,6 +64,28 @@ public final class AbilityUtils {
}
}
+ /**
+ * A "best-effort" boolean stating whether the update is a group message or not.
+ *
+ * @param update a Telegram {@link Update}
+ * @return whether the update is linked to a group
+ */
+ public static boolean isGroupUpdate(Update update) {
+ if (MESSAGE.test(update)) {
+ return update.getMessage().isGroupMessage();
+ } else if (CALLBACK_QUERY.test(update)) {
+ return update.getCallbackQuery().getMessage().isGroupMessage();
+ } else if (CHANNEL_POST.test(update)) {
+ return update.getChannelPost().isGroupMessage();
+ } else if (EDITED_CHANNEL_POST.test(update)) {
+ return update.getEditedChannelPost().isGroupMessage();
+ } else if (EDITED_MESSAGE.test(update)) {
+ return update.getEditedMessage().isGroupMessage();
+ } else {
+ return false;
+ }
+ }
+
/**
* Fetches the direct chat ID of the specified update.
*
diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java
index 634d222d..ff335720 100644
--- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java
+++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java
@@ -2,7 +2,6 @@ package org.telegram.abilitybots.api.bot;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
-import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
@@ -13,6 +12,7 @@ import org.telegram.abilitybots.api.sender.MessageSender;
import org.telegram.abilitybots.api.sender.SilentSender;
import org.telegram.abilitybots.api.util.Pair;
import org.telegram.abilitybots.api.util.Trio;
+import org.telegram.telegrambots.api.methods.groupadministration.GetChatAdministrators;
import org.telegram.telegrambots.api.objects.*;
import org.telegram.telegrambots.exceptions.TelegramApiException;
@@ -21,11 +21,14 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
import static java.lang.String.format;
import static java.util.Collections.emptySet;
+import static java.util.Optional.empty;
import static org.apache.commons.io.FileUtils.deleteQuietly;
import static org.apache.commons.lang3.ArrayUtils.addAll;
import static org.apache.commons.lang3.StringUtils.EMPTY;
@@ -43,8 +46,7 @@ import static org.telegram.abilitybots.api.objects.Flag.MESSAGE;
import static org.telegram.abilitybots.api.objects.Locality.ALL;
import static org.telegram.abilitybots.api.objects.Locality.GROUP;
import static org.telegram.abilitybots.api.objects.MessageContext.newContext;
-import static org.telegram.abilitybots.api.objects.Privacy.ADMIN;
-import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;
+import static org.telegram.abilitybots.api.objects.Privacy.*;
public class AbilityBotTest {
private static final String[] EMPTY_ARRAY = {};
@@ -77,7 +79,7 @@ public class AbilityBotTest {
bot.onUpdateReceived(update);
- verify(silent, times(1)).send(format("Sorry, %s-only feature.", "admin"), MUSER.id());
+ verify(silent, times(1)).send("Sorry, you don't have the required access level to do that.", MUSER.id());
}
@Test
@@ -342,20 +344,61 @@ public class AbilityBotTest {
Message message = mock(Message.class);
org.telegram.telegrambots.api.objects.User user = mock(User.class);
Ability publicAbility = getDefaultBuilder().privacy(PUBLIC).build();
+ Ability groupAdminAbility = getDefaultBuilder().privacy(GROUP_ADMIN).build();
Ability adminAbility = getDefaultBuilder().privacy(ADMIN).build();
Ability creatorAbility = getDefaultBuilder().privacy(Privacy.CREATOR).build();
Trio publicTrio = Trio.of(update, publicAbility, TEXT);
+ Trio groupAdminTrio = Trio.of(update, groupAdminAbility, TEXT);
Trio adminTrio = Trio.of(update, adminAbility, TEXT);
Trio creatorTrio = Trio.of(update, creatorAbility, TEXT);
mockUser(update, message, user);
assertEquals("Unexpected result when checking for privacy", true, bot.checkPrivacy(publicTrio));
+ assertEquals("Unexpected result when checking for privacy", false, bot.checkPrivacy(groupAdminTrio));
assertEquals("Unexpected result when checking for privacy", false, bot.checkPrivacy(adminTrio));
assertEquals("Unexpected result when checking for privacy", false, bot.checkPrivacy(creatorTrio));
}
+ @Test
+ public void canValidateGroupAdminPrivacy() throws TelegramApiException {
+ Update update = mock(Update.class);
+ Message message = mock(Message.class);
+ org.telegram.telegrambots.api.objects.User user = mock(User.class);
+ Ability groupAdminAbility = getDefaultBuilder().privacy(GROUP_ADMIN).build();
+
+ Trio groupAdminTrio = Trio.of(update, groupAdminAbility, TEXT);
+
+ mockUser(update, message, user);
+ when(message.isGroupMessage()).thenReturn(true);
+
+ ChatMember member = mock(ChatMember.class);
+ when(member.getUser()).thenReturn(user);
+ when(member.getUser()).thenReturn(user);
+
+ when(silent.execute(any(GetChatAdministrators.class))).thenReturn(Optional.of(newArrayList(member)));
+
+ assertEquals("Unexpected result when checking for privacy", true, bot.checkPrivacy(groupAdminTrio));
+ }
+
+ @Test
+ public void canRestrictNormalUsersFromGroupAdminAbilities() throws TelegramApiException {
+ Update update = mock(Update.class);
+ Message message = mock(Message.class);
+ org.telegram.telegrambots.api.objects.User user = mock(User.class);
+ Ability groupAdminAbility = getDefaultBuilder().privacy(GROUP_ADMIN).build();
+
+ Trio groupAdminTrio = Trio.of(update, groupAdminAbility, TEXT);
+
+ mockUser(update, message, user);
+ when(message.isGroupMessage()).thenReturn(true);
+
+ when(silent.execute(any(GetChatAdministrators.class))).thenReturn(empty());
+
+ assertEquals("Unexpected result when checking for privacy", false, bot.checkPrivacy(groupAdminTrio));
+ }
+
@Test
public void canBlockAdminsFromCreatorAbilities() {
Update update = mock(Update.class);
@@ -447,6 +490,25 @@ public class AbilityBotTest {
assertEquals("Wrong ability was fetched", expected, actual);
}
+ @Test
+ public void canFetchAbilityCaseInsensitive() {
+ Update update = mock(Update.class);
+ Message message = mock(Message.class);
+
+ String text = "/tESt";
+ when(update.hasMessage()).thenReturn(true);
+ when(update.getMessage()).thenReturn(message);
+ when(update.getMessage().hasText()).thenReturn(true);
+ when(message.getText()).thenReturn(text);
+
+ Trio trio = bot.getAbility(update);
+
+ Ability expected = bot.testAbility();
+ Ability actual = trio.b();
+
+ assertEquals("Wrong ability was fetched", expected, actual);
+ }
+
@Test
public void canFetchDefaultAbility() {
Update update = mock(Update.class);
diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java
index 2d9a6f16..7e53584b 100644
--- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java
+++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java
@@ -31,7 +31,7 @@ public class MapDBContextTest {
}
@Test
- public void canRecoverDB() throws IOException {
+ public void canRecoverDB() {
Map users = db.getMap(USERS);
Map userIds = db.getMap(USER_ID);
users.put(CREATOR.id(), CREATOR);
diff --git a/telegrambots-extensions/README.md b/telegrambots-extensions/README.md
index be786b11..97dd6f2c 100644
--- a/telegrambots-extensions/README.md
+++ b/telegrambots-extensions/README.md
@@ -16,12 +16,12 @@ Just import add the library to your project with one of these options:
org.telegram
telegrambotsextensions
- 3.5
+ 3.6
```
2. Using Gradle:
```gradle
- compile "org.telegram:telegrambotsextensions:3.5"
+ compile "org.telegram:telegrambotsextensions:3.6"
```
\ No newline at end of file
diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml
index f0ff7aec..a6f41734 100644
--- a/telegrambots-extensions/pom.xml
+++ b/telegrambots-extensions/pom.xml
@@ -5,7 +5,7 @@
4.0.0
org.telegram
telegrambotsextensions
- 3.5
+ 3.6
jar
Telegram Bots Extensions
@@ -59,7 +59,7 @@
UTF-8
UTF-8
- 3.5
+ 3.6
diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/HelpCommand.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/HelpCommand.java
new file mode 100644
index 00000000..2926b0e6
--- /dev/null
+++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/HelpCommand.java
@@ -0,0 +1,117 @@
+package org.telegram.telegrambots.bots.commandbot.commands.helpCommand;
+
+import java.util.Collection;
+
+import org.telegram.telegrambots.api.methods.send.SendMessage;
+import org.telegram.telegrambots.api.objects.Chat;
+import org.telegram.telegrambots.api.objects.User;
+import org.telegram.telegrambots.bots.AbsSender;
+import org.telegram.telegrambots.bots.commandbot.TelegramLongPollingCommandBot;
+import org.telegram.telegrambots.bots.commandbot.commands.BotCommand;
+import org.telegram.telegrambots.bots.commandbot.commands.ICommandRegistry;
+import org.telegram.telegrambots.exceptions.TelegramApiException;
+
+/**
+ * A special bot command used for printing help messages similiar to the Linux man command.
+ * The commands printed by this command should implement the {@link IManCommand} interface to provide an extended description.
+ * @author Lukas Prediger(Chase)
+ * @version 1.0.0
+ *
+ */
+public class HelpCommand extends ManCommand {
+
+ private static final String COMMAND_IDENTIFIER = "help";
+ private static final String COMMAND_DESCRIPTION = "shows all commands. Use /help [command] for more info";
+ private static final String EXTENDED_DESCRIPTION = "This command displays all commands the bot has to offer.\n /help [command] can display deeper information";
+
+ /**
+ * Returns the command and description of all supplied commands as a formatted String
+ * @param botCommands the Commands that should be included in the String
+ * @return a formatted String containing command and description for all supplied commands
+ */
+ public static String getHelpText(BotCommand...botCommands) {
+ StringBuilder reply = new StringBuilder();
+ for (BotCommand com : botCommands) {
+ reply.append(com.toString()).append(System.lineSeparator()).append(System.lineSeparator());
+ }
+ return reply.toString();
+ }
+
+ /**
+ * Returns the command and description of all supplied commands as a formatted String
+ * @param botCommands a collection of commands that should be included in the String
+ * @return a formatted String containing command and description for all supplied commands
+ */
+ public static String getHelpText(Collection botCommands) {
+ return getHelpText(botCommands.toArray(new BotCommand[botCommands.size()]));
+ }
+
+ /**
+ * Returns the command and description of all supplied commands as a formatted String
+ * @param registry a commandRegistry which commands are formatted into the String
+ * @return a formatted String containing command and description for all supplied commands
+ */
+ public static String getHelpText(ICommandRegistry registry) {
+ return getHelpText(registry.getRegisteredCommands());
+ }
+
+ /**
+ * Reads the extended Description from a BotCommand. If the Command is not of Type {@link IManCommand}, it calls toString();
+ * @param command a command the extended Descriptions is read from
+ * @return the extended Description or the toString() if IManCommand is not implemented
+ */
+ public static String getManText(BotCommand command) {
+ return IManCommand.class.isInstance(command) ? getManText((IManCommand) command) : command.toString();
+ }
+
+ /**
+ * Reads the extended Description from a BotCommand;
+ * @param command a command the extended Descriptions is read from
+ * @return the extended Description
+ */
+ public static String getManText(IManCommand command) {
+ return command.toMan();
+ }
+
+ /**
+ * Create a Help command with the standard Arguments.
+ */
+ public HelpCommand() {
+ super(COMMAND_IDENTIFIER, COMMAND_DESCRIPTION, EXTENDED_DESCRIPTION);
+ }
+
+ /**
+ * Creates a Help Command with custom identifier, description and extended Description
+ * @param commandIdentifier the unique identifier of this command (e.g. the command string to enter into chat)
+ * @param description the description of this command
+ * @param extendedDescription The extended Description for the Command, should provide detailed information about arguments and possible options
+ */
+ public HelpCommand(String commandIdentifier, String description, String extendedDescription) {
+ super(commandIdentifier, description, extendedDescription);
+ }
+
+ @Override
+ public void execute(AbsSender absSender, User user, Chat chat, String[] arguments) {
+ if (ICommandRegistry.class.isInstance(absSender)) {
+ ICommandRegistry registry = (ICommandRegistry) absSender;
+
+ if (arguments.length > 0) {
+ BotCommand command = registry.getRegisteredCommand(arguments[0]);
+ String reply = getManText(command);
+ try {
+ absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML"));
+ } catch (TelegramApiException e) {
+ e.printStackTrace();
+ }
+ } else {
+ String reply = getHelpText(registry);
+ try {
+ absSender.execute(new SendMessage(chat.getId(), reply).setParseMode("HTML"));
+ } catch (TelegramApiException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/IManCommand.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/IManCommand.java
new file mode 100644
index 00000000..67e15d63
--- /dev/null
+++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/IManCommand.java
@@ -0,0 +1,21 @@
+package org.telegram.telegrambots.bots.commandbot.commands.helpCommand;
+
+/**
+ * Represents a Command that, aside the normal command description provides an extended Description similar to the output of the Linux man command
+ * @author Lukas Prediger(Chase)
+ * @version 1.0.0
+ */
+public interface IManCommand {
+ /**
+ * Returns the extended Description of this command
+ * @return the extendedDescription
+ */
+ String getExtendedDescription();
+
+ /**
+ * Returns a String Representations of the Command and it's extended Description.
+ * @return a String representing the Command and it's extended Description
+ */
+ String toMan();
+
+}
\ No newline at end of file
diff --git a/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/ManCommand.java b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/ManCommand.java
new file mode 100644
index 00000000..1f645b7a
--- /dev/null
+++ b/telegrambots-extensions/src/main/java/org/telegram/telegrambots/bots/commandbot/commands/helpCommand/ManCommand.java
@@ -0,0 +1,41 @@
+package org.telegram.telegrambots.bots.commandbot.commands.helpCommand;
+
+import org.telegram.telegrambots.bots.commandbot.commands.BotCommand;
+
+public abstract class ManCommand extends BotCommand implements IManCommand {
+
+ private final String extendedDescription;
+
+ /**
+ * Create a new ManCommand providing a commandIdentifier, a short description and the extended description
+ * @param commandIdentifier the unique identifier of this command (e.g. the command string to enter into chat)
+ * @param description the description of this command
+ * @param extendedDescription The extended Description for the Command, should provide detailed information about arguments and possible options
+ */
+ public ManCommand(String commandIdentifier, String description, String extendedDescription) {
+ super(commandIdentifier, description);
+ this.extendedDescription = extendedDescription;
+ }
+
+ /* (non-Javadoc)
+ * @see org.telegram.telegrambots.bots.commandbot.commands.helpCommand.IManCommand#getExtendedDescription()
+ */
+ @Override
+ public String getExtendedDescription() {
+ return extendedDescription;
+ }
+
+ /* (non-Javadoc)
+ * @see org.telegram.telegrambots.bots.commandbot.commands.helpCommand.IManCommand#toMan()
+ */
+ @Override
+ public String toMan() {
+ StringBuilder sb = new StringBuilder(toString());
+ sb.append(System.lineSeparator())
+ .append("-----------------")
+ .append(System.lineSeparator());
+ if (getExtendedDescription() != null) sb.append(getExtendedDescription());
+ return sb.toString();
+ }
+
+}
diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml
index 3d08b64a..3bb47ed2 100644
--- a/telegrambots-meta/pom.xml
+++ b/telegrambots-meta/pom.xml
@@ -5,7 +5,7 @@
4.0.0
org.telegram
telegrambots-meta
- 3.5
+ 3.6
jar
Telegram Bots Meta
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendAudio.java
index 6f053266..e312a513 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendAudio.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendAudio.java
@@ -17,12 +17,11 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Use this method to send audio files, Use this method to send audio files, if you want
+ * Use this method to send audio files, 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 sending voice notes, use sendVoice method instead.
- * @date 16 of July of 2015
*/
public class SendAudio extends PartialBotApiMethod {
public static final String PATH = "sendaudio";
@@ -36,6 +35,8 @@ public class SendAudio extends PartialBotApiMethod {
public static final String PERFOMER_FIELD = "performer";
public static final String TITLE_FIELD = "title";
public static final String CAPTION_FIELD = "caption";
+ public static final String PARSEMODE_FIELD = "parse_mode";
+
private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender
private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro channels)
@@ -46,6 +47,7 @@ public class SendAudio extends PartialBotApiMethod {
private String performer; ///< Optional. Performer of sent audio
private String title; ///< Optional. Title of sent audio
private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private boolean isNewAudio; ///< True to upload a new audio, false to use a fileId
private String audioName;
@@ -191,6 +193,15 @@ public class SendAudio extends PartialBotApiMethod {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public SendAudio setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@@ -239,11 +250,12 @@ public class SendAudio extends PartialBotApiMethod {
", replyMarkup=" + replyMarkup +
", performer='" + performer + '\'' +
", title='" + title + '\'' +
+ ", caption='" + caption + '\'' +
+ ", parseMode='" + parseMode + '\'' +
", isNewAudio=" + isNewAudio +
", audioName='" + audioName + '\'' +
", newAudioFile=" + newAudioFile +
", newAudioStream=" + newAudioStream +
- ", caption='" + caption + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendDocument.java
index c9bdc664..4923de82 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendDocument.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendDocument.java
@@ -17,8 +17,7 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Use this method to send general files. On success, the sent Message is returned.
- * @date 20 of June of 2015
+ * Use this method to send general files. On success, the sent Message is returned.
*/
public class SendDocument extends PartialBotApiMethod {
public static final String PATH = "senddocument";
@@ -29,12 +28,15 @@ public class SendDocument extends PartialBotApiMethod {
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";
+ public static final String PARSEMODE_FIELD = "parse_mode";
+
private String chatId; ///< Unique identifier for the chat to send the message to or Username for the channel to send the message to
private String document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers or Url to upload it
private String caption; ///< Optional. Document caption (may also be used when resending documents by file_id), 0-200 characters
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 String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private boolean isNewDocument; ///< True to upload a new document, false to use a fileId
private String documentName;
@@ -154,6 +156,15 @@ public class SendDocument extends PartialBotApiMethod {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public SendDocument setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@@ -196,9 +207,15 @@ public class SendDocument extends PartialBotApiMethod {
return "SendDocument{" +
"chatId='" + chatId + '\'' +
", document='" + document + '\'' +
+ ", caption='" + caption + '\'' +
+ ", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
", isNewDocument=" + isNewDocument +
+ ", documentName='" + documentName + '\'' +
+ ", newDocumentFile=" + newDocumentFile +
+ ", newDocumentStream=" + newDocumentStream +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendMessage.java
index d750304c..53238969 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendMessage.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendMessage.java
@@ -187,6 +187,35 @@ public class SendMessage extends BotApiMethod {
}
}
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof SendMessage)) {
+ return false;
+ }
+ SendMessage sendMessage = (SendMessage) o;
+ return Objects.equals(chatId, sendMessage.chatId)
+ && Objects.equals(disableNotification, sendMessage.disableNotification)
+ && Objects.equals(disableWebPagePreview, sendMessage.disableWebPagePreview)
+ && Objects.equals(parseMode, sendMessage.parseMode)
+ && Objects.equals(replyMarkup, sendMessage.replyMarkup)
+ && Objects.equals(replyToMessageId, sendMessage.replyToMessageId)
+ && Objects.equals(text, sendMessage.text)
+ ;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ chatId,
+ disableNotification,
+ disableWebPagePreview,
+ parseMode,
+ replyMarkup,
+ replyToMessageId,
+ text);
+ }
+
@Override
public String toString() {
return "SendMessage{" +
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendPhoto.java
index c956b665..e8ebec83 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendPhoto.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendPhoto.java
@@ -17,8 +17,7 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Use this method to send photos. On success, the sent Message is returned.
- * @date 20 of June of 2015
+ * Use this method to send photos. On success, the sent Message is returned.
*/
public class SendPhoto extends PartialBotApiMethod {
public static final String PATH = "sendphoto";
@@ -29,12 +28,15 @@ public class SendPhoto extends PartialBotApiMethod {
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";
+ public static final String PARSEMODE_FIELD = "parse_mode";
+
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers or URL to upload it
private String caption; ///< Optional Photo caption (may also be used when resending photos by file_id).
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 String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private boolean isNewPhoto; ///< True if the photo must be uploaded from a file, file if it is a fileId
private String photoName; ///< Name of the photo
@@ -142,6 +144,15 @@ public class SendPhoto extends PartialBotApiMethod {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public SendPhoto setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@@ -184,9 +195,14 @@ public class SendPhoto extends PartialBotApiMethod {
"chatId='" + chatId + '\'' +
", photo='" + photo + '\'' +
", caption='" + caption + '\'' +
+ ", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
", isNewPhoto=" + isNewPhoto +
+ ", photoName='" + photoName + '\'' +
+ ", newPhotoFile=" + newPhotoFile +
+ ", newPhotoStream=" + newPhotoStream +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVideo.java
index f999e221..ffdec937 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVideo.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVideo.java
@@ -31,17 +31,22 @@ public class SendVideo extends PartialBotApiMethod {
public static final String WIDTH_FIELD = "width";
public static final String HEIGHT_FIELD = "height";
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
+ public static final String SUPPORTSSTREAMING_FIELD = "supports_streaming";
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
public static final String REPLYMARKUP_FIELD = "reply_markup";
+ public static final String PARSEMODE_FIELD = "parse_mode";
+
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String video; ///< Video to send. file_id as String to resend a video that is already on the Telegram servers or URL to upload it
private Integer duration; ///< Optional. Duration of sent video in seconds
private String caption; ///< OptionaL. Video caption (may also be used when resending videos by file_id).
private Integer width; ///< Optional. Video width
private Integer height; ///< OptionaL. Video height
+ private Boolean supportsStreaming; ///< Optional. Pass True, if the uploaded video is suitable for streaming
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 String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private boolean isNewVideo; ///< True to upload a new video, false to use a fileId
private String videoName; ///< Name of the video
@@ -176,6 +181,24 @@ public class SendVideo extends PartialBotApiMethod {
return this;
}
+ public Boolean getSupportsStreaming() {
+ return supportsStreaming;
+ }
+
+ public SendVideo setSupportsStreaming(Boolean supportsStreaming) {
+ this.supportsStreaming = supportsStreaming;
+ return this;
+ }
+
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public SendVideo setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVoice.java
index ca5bd11e..25b493a5 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVoice.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/send/SendVoice.java
@@ -17,10 +17,9 @@ import java.util.Objects;
/**
* @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
+ * 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 extends PartialBotApiMethod {
public static final String PATH = "sendvoice";
@@ -32,6 +31,7 @@ public class SendVoice extends PartialBotApiMethod {
public static final String REPLYMARKUP_FIELD = "reply_markup";
public static final String DURATION_FIELD = "duration";
public static final String CAPTION_FIELD = "caption";
+ public static final String PARSEMODE_FIELD = "parse_mode";
private String chatId; ///< Unique identifier for the chat sent message to (Or username for channels)
private String voice; ///< Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
@@ -40,6 +40,7 @@ public class SendVoice extends PartialBotApiMethod {
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private Integer duration; ///< Optional. Duration of sent audio in seconds
private String caption; ///< Optional. Voice caption (may also be used when resending videos by file_id).
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
private boolean isNewVoice; ///< True to upload a new voice note, false to use a fileId
private String voiceName; ///< Name of the voice note
@@ -156,6 +157,15 @@ public class SendVoice extends PartialBotApiMethod {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public SendVoice setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
@@ -203,6 +213,7 @@ public class SendVoice extends PartialBotApiMethod {
", replyMarkup=" + replyMarkup +
", duration=" + duration +
", caption='" + caption + '\'' +
+ ", parseMode='" + parseMode + '\'' +
", isNewVoice=" + isNewVoice +
", voiceName='" + voiceName + '\'' +
", newVoiceFile=" + newVoiceFile +
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java
index cba6e216..2a4414d7 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java
@@ -16,9 +16,8 @@ import java.io.Serializable;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Use this method to edit captions of messages sent by the bot or via the bot (for inline
+ * Use this method to edit captions of messages sent by the bot or via the bot (for inline
* bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
- * @date 10 of April of 2016
*/
public class EditMessageCaption extends BotApiMethod {
public static final String PATH = "editmessagecaption";
@@ -28,6 +27,7 @@ public class EditMessageCaption extends BotApiMethod {
private static final String INLINE_MESSAGE_ID_FIELD = "inline_message_id";
private static final String CAPTION_FIELD = "caption";
private static final String REPLYMARKUP_FIELD = "reply_markup";
+ private static final String PARSEMODE_FIELD = "parse_mode";
/**
* Required if inline_message_id is not specified. Unique identifier for the chat to send the
@@ -49,6 +49,8 @@ public class EditMessageCaption extends BotApiMethod {
private String caption; ///< Optional. New caption of the message
@JsonProperty(REPLYMARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. A JSON-serialized object for an inline keyboard.
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public EditMessageCaption() {
super();
@@ -99,6 +101,15 @@ public class EditMessageCaption extends BotApiMethod {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public EditMessageCaption setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public String getMethod() {
return PATH;
@@ -155,11 +166,12 @@ public class EditMessageCaption extends BotApiMethod {
@Override
public String toString() {
return "EditMessageCaption{" +
- "chatId=" + chatId +
+ "chatId='" + chatId + '\'' +
", messageId=" + messageId +
- ", inlineMessageId=" + inlineMessageId +
- ", caption=" + caption +
+ ", inlineMessageId='" + inlineMessageId + '\'' +
+ ", caption='" + caption + '\'' +
", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java
index ee255316..76d56c1e 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/Message.java
@@ -56,6 +56,7 @@ public class Message implements BotApiObject {
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";
+ private static final String CONNECTEDWEBSITE_FIELD = "connected_website";
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId; ///< Integer Unique message identifier
@@ -174,7 +175,9 @@ public class Message implements BotApiObject {
@JsonProperty(FORWARDSIGNATURE_FIELD)
private String forwardSignature; ///< Optional. Post author signature for messages forwarded from channel chats
@JsonProperty(MEDIAGROUPID_FIELD)
- private String mediaGroupId;
+ private String mediaGroupId; ///< Optional. The unique identifier of a media message group this message belongs to
+ @JsonProperty(CONNECTEDWEBSITE_FIELD)
+ private String connectedWebsite; ///< Optional. The domain name of the website on which the user has logged in
public Message() {
super();
@@ -418,6 +421,10 @@ public class Message implements BotApiObject {
return mediaGroupId;
}
+ public String getConnectedWebsite() {
+ return connectedWebsite;
+ }
+
@Override
public String toString() {
return "Message{" +
@@ -462,6 +469,7 @@ public class Message implements BotApiObject {
", authorSignature='" + authorSignature + '\'' +
", forwardSignature='" + forwardSignature + '\'' +
", mediaGroupId='" + mediaGroupId + '\'' +
+ ", connectedWebsite='" + connectedWebsite + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultAudio.java
index 9cb42c4b..0a408ed4 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultAudio.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultAudio.java
@@ -9,12 +9,11 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to an mp3 audio file. By default, this audio file will be sent by the
+ * Represents a link to an mp3 audio file. By default, this audio file will be sent by the
* user. Alternatively, you can use input_message_content to send a message with the specified
* content instead of the audio.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
- * @date 10 of April of 2016
*/
public class InlineQueryResultAudio implements InlineQueryResult {
@@ -27,6 +26,7 @@ public class InlineQueryResultAudio implements InlineQueryResult {
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "audio"; ///< Type of the result, must be "audio"
@@ -46,6 +46,8 @@ public class InlineQueryResultAudio implements InlineQueryResult {
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultAudio() {
super();
@@ -127,6 +129,15 @@ public class InlineQueryResultAudio implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultAudio setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -146,7 +157,8 @@ public class InlineQueryResultAudio implements InlineQueryResult {
@Override
public String toString() {
return "InlineQueryResultAudio{" +
- "id='" + id + '\'' +
+ "type='" + type + '\'' +
+ ", id='" + id + '\'' +
", audioUrl='" + audioUrl + '\'' +
", title='" + title + '\'' +
", performer='" + performer + '\'' +
@@ -154,6 +166,7 @@ public class InlineQueryResultAudio implements InlineQueryResult {
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultDocument.java
index a63f8dc6..e5b0c9ef 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultDocument.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultDocument.java
@@ -9,13 +9,12 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to a file. By default, this file will be sent by the user with an
+ * Represents a link to a file. By default, this file will be sent by the user with an
* optional caption. Alternatively, you can use input_message_content to send a message with the
* specified content instead of the file.
* @note Currently, only .PDF and .ZIP files can be sent using this method.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
- * @date 01 of January of 2016
*/
public class InlineQueryResultDocument implements InlineQueryResult {
@@ -31,6 +30,7 @@ public class InlineQueryResultDocument implements InlineQueryResult {
private static final String THUMBURL_FIELD = "thumb_url";
private static final String THUMBWIDTH_FIELD = "thumb_width";
private static final String THUMBHEIGHT_FIELD = "thumb_height";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "document"; ///< Type of the result, must be "document"
@@ -56,6 +56,8 @@ public class InlineQueryResultDocument implements InlineQueryResult {
private Integer thumbWidth; ///< Optional. Thumbnail width
@JsonProperty(THUMBHEIGHT_FIELD)
private Integer thumbHeight; ///< Optional. Thumbnail height
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultDocument() {
super();
@@ -164,6 +166,15 @@ public class InlineQueryResultDocument implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultDocument setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -191,16 +202,17 @@ public class InlineQueryResultDocument implements InlineQueryResult {
return "InlineQueryResultDocument{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
- ", mimeType='" + mimeType + '\'' +
- ", documentUrl='" + documentUrl + '\'' +
- ", thumbHeight=" + thumbHeight +
- ", thumbWidth=" + thumbWidth +
- ", thumbUrl='" + thumbUrl + '\'' +
", title='" + title + '\'' +
+ ", documentUrl='" + documentUrl + '\'' +
+ ", mimeType='" + mimeType + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", replyMarkup=" + replyMarkup +
+ ", inputMessageContent=" + inputMessageContent +
+ ", thumbUrl='" + thumbUrl + '\'' +
+ ", thumbWidth=" + thumbWidth +
+ ", thumbHeight=" + thumbHeight +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultGif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultGif.java
index 5904adc1..294a85bd 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultGif.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultGif.java
@@ -9,13 +9,11 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to an animated GIF file. By default, this animated GIF file will be sent
+ * Represents a link to an animated GIF file. By default, this animated GIF file will be sent
* by the user with optional caption. Alternatively, you can use input_message_content to send a
* message with the specified content instead of the animation.
- * @date 01 of January of 2016
*/
public class InlineQueryResultGif implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String GIFURL_FIELD = "gif_url";
@@ -27,6 +25,7 @@ public class InlineQueryResultGif implements InlineQueryResult {
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String GIF_DURATION_FIELD = "gif_duration";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "gif"; ///< Type of the result, must be "gif"
@@ -50,6 +49,8 @@ public class InlineQueryResultGif implements InlineQueryResult {
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(GIF_DURATION_FIELD)
private Integer gifDuration; ///< Optional. Duration of the GIF
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultGif() {
super();
@@ -144,8 +145,18 @@ public class InlineQueryResultGif implements InlineQueryResult {
return gifDuration;
}
- public void setGifDuration(Integer gifDuration) {
+ public InlineQueryResultGif setGifDuration(Integer gifDuration) {
this.gifDuration = gifDuration;
+ return this;
+ }
+
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultGif setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
}
@Override
@@ -178,6 +189,7 @@ public class InlineQueryResultGif implements InlineQueryResult {
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", gifDuration=" + gifDuration +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultMpeg4Gif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultMpeg4Gif.java
index 015094f7..d72e66e9 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultMpeg4Gif.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultMpeg4Gif.java
@@ -27,6 +27,7 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String MPEG4_DURATION_FIELD = "mpeg4_duration";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif"
@@ -50,6 +51,8 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(MPEG4_DURATION_FIELD)
private Integer mpeg4Duration; ///< Optional. Video duration
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultMpeg4Gif() {
super();
@@ -144,8 +147,18 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
return mpeg4Duration;
}
- public void setMpeg4Duration(Integer mpeg4Duration) {
+ public InlineQueryResultMpeg4Gif setMpeg4Duration(Integer mpeg4Duration) {
this.mpeg4Duration = mpeg4Duration;
+ return this;
+ }
+
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultMpeg4Gif setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
}
@Override
@@ -178,6 +191,7 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", mpeg4Duration=" + mpeg4Duration +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultPhoto.java
index e9d6490d..cfe9fc65 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultPhoto.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultPhoto.java
@@ -9,13 +9,11 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to a photo. By default, this photo will be sent by the user with
+ * Represents a link to a photo. By default, this photo will be sent by the user with
* optional caption. Alternatively, you can use input_message_content to send a message with the
* specified content instead of the photo.
- * @date 01 of January of 2016
*/
public class InlineQueryResultPhoto implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String PHOTOURL_FIELD = "photo_url";
@@ -28,6 +26,7 @@ public class InlineQueryResultPhoto implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "photo"; ///< Type of the result, must be “photo”
@@ -53,6 +52,8 @@ public class InlineQueryResultPhoto implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultPhoto() {
super();
@@ -161,6 +162,15 @@ public class InlineQueryResultPhoto implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultPhoto setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -190,8 +200,9 @@ public class InlineQueryResultPhoto implements InlineQueryResult {
", title='" + title + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", inputMessageContent=" + inputMessageContent +
+ ", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVideo.java
index 30978694..46ac1f41 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVideo.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVideo.java
@@ -9,13 +9,11 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents link to a page containing an embedded video player or a video file.
+ * Represents link to a page containing an embedded video player or a video file.
* Alternatively, you can use input_message_content to send a message with the specified content
* instead of the video.
- * @date 01 of January of 2016
*/
public class InlineQueryResultVideo implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String MIMETYPE_FIELD = "mime_type";
@@ -29,6 +27,7 @@ public class InlineQueryResultVideo implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "video"; ///< Type of the result, must be "video"
@@ -56,6 +55,8 @@ public class InlineQueryResultVideo implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultVideo() {
super();
@@ -173,6 +174,15 @@ public class InlineQueryResultVideo implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultVideo setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -203,8 +213,9 @@ public class InlineQueryResultVideo implements InlineQueryResult {
", title='" + title + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", inputMessageContent=" + inputMessageContent +
+ ", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVoice.java
index 8cab871f..7ba42e71 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVoice.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/InlineQueryResultVoice.java
@@ -9,15 +9,13 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to a voice recording in an .ogg container encoded with OPUS. By default,
+ * Represents a link to a voice recording in an .ogg container encoded with OPUS. By default,
* this voice recording will be sent by the user. Alternatively, you can use input_message_content
* to send a message with the specified content instead of the the voice message.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
- * @date 10 of April of 2016
*/
public class InlineQueryResultVoice implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String VOICEURL_FIELD = "voice_url";
@@ -26,6 +24,7 @@ public class InlineQueryResultVoice implements InlineQueryResult {
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "voice"; ///< Type of the result, must be "voice"
@@ -43,6 +42,8 @@ public class InlineQueryResultVoice implements InlineQueryResult {
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Voice caption (may also be used when resending documents by file_id), 0-200 characters
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultVoice() {
super();
@@ -134,13 +135,15 @@ public class InlineQueryResultVoice implements InlineQueryResult {
@Override
public String toString() {
return "InlineQueryResultVoice{" +
- "id='" + id + '\'' +
+ "type='" + type + '\'' +
+ ", id='" + id + '\'' +
", voiceUrl='" + voiceUrl + '\'' +
", title='" + title + '\'' +
", voiceDuration=" + voiceDuration +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java
index 3478e0ba..179576f0 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedAudio.java
@@ -25,6 +25,7 @@ public class InlineQueryResultCachedAudio implements InlineQueryResult {
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "audio"; ///< Type of the result, must be "audio"
@@ -38,6 +39,8 @@ public class InlineQueryResultCachedAudio implements InlineQueryResult {
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Audio caption (may also be used when resending documents by file_id), 0-200 characters
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedAudio() {
super();
@@ -92,6 +95,15 @@ public class InlineQueryResultCachedAudio implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultCachedAudio setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -111,11 +123,13 @@ public class InlineQueryResultCachedAudio implements InlineQueryResult {
@Override
public String toString() {
return "InlineQueryResultCachedAudio{" +
- "id='" + id + '\'' +
+ "type='" + type + '\'' +
+ ", id='" + id + '\'' +
", audioFileId='" + audioFileId + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java
index 5d0bdbbd..2aef452d 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedDocument.java
@@ -10,13 +10,12 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to a file stored on the Telegram servers. By default, this file will be
+ * Represents a link to a file stored on the Telegram servers. By default, this file will be
* sent by the user with an optional caption. Alternatively, you can use input_message_content to
* send a message with the specified content instead of the file.
* @note Currently, only pdf-files and zip archives can be sent using this method.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
- * @date 10 of April of 2016
*/
public class InlineQueryResultCachedDocument implements InlineQueryResult {
@@ -28,6 +27,7 @@ public class InlineQueryResultCachedDocument implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "document"; ///< Type of the result, must be "document"
@@ -45,6 +45,8 @@ public class InlineQueryResultCachedDocument implements InlineQueryResult {
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(INPUTMESSAGECONTENT_FIELD)
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the file
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedDocument() {
super();
@@ -117,6 +119,15 @@ public class InlineQueryResultCachedDocument implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultCachedDocument setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -141,12 +152,13 @@ public class InlineQueryResultCachedDocument implements InlineQueryResult {
return "InlineQueryResultCachedDocument{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
- ", documentFileId='" + documentFileId + '\'' +
- ", caption='" + caption + '\'' +
", title='" + title + '\'' +
+ ", documentFileId='" + documentFileId + '\'' +
", description='" + description + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", caption='" + caption + '\'' +
+ ", replyMarkup=" + replyMarkup +
+ ", inputMessageContent=" + inputMessageContent +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java
index 9c8e4a75..fa184357 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedGif.java
@@ -10,13 +10,11 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to an animated GIF file stored on the Telegram servers. By default, this
+ * Represents a link to an animated GIF file stored on the Telegram servers. By default, this
* animated GIF file will be sent by the user with an optional caption. Alternatively, you can use
* input_message_content to send a message with specified content instead of the animation.
- * @date 10 of April of 2016
*/
public class InlineQueryResultCachedGif implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String GIF_FILE_ID_FIELD = "gif_file_id";
@@ -24,6 +22,7 @@ public class InlineQueryResultCachedGif implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "gif"; ///< Type of the result, must be "gif"
@@ -39,6 +38,8 @@ public class InlineQueryResultCachedGif implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the GIF animation
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedGif() {
super();
@@ -102,6 +103,15 @@ public class InlineQueryResultCachedGif implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultCachedGif setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -123,11 +133,12 @@ public class InlineQueryResultCachedGif implements InlineQueryResult {
return "InlineQueryResultCachedGif{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
- ", gifUrl='" + gifFileId + '\'' +
+ ", gifFileId='" + gifFileId + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", inputMessageContent=" + inputMessageContent +
+ ", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java
index cf840cc4..08d61904 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedMpeg4Gif.java
@@ -24,6 +24,7 @@ public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif"
@@ -39,6 +40,8 @@ public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedMpeg4Gif() {
super();
@@ -102,6 +105,15 @@ public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultCachedMpeg4Gif setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -123,11 +135,12 @@ public class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
return "InlineQueryResultCachedMpeg4Gif{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
- ", mpeg4Url='" + mpeg4FileId + '\'' +
+ ", mpeg4FileId='" + mpeg4FileId + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", inputMessageContent=" + inputMessageContent +
+ ", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java
index b15b5146..3e42d5b6 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedPhoto.java
@@ -10,13 +10,11 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to a photo stored on the Telegram servers. By default, this photo will
+ * Represents a link to a photo stored on the Telegram servers. By default, this photo will
* be sent by the user with an optional caption. Alternatively, you can use input_message_content to
* send a message with the specified content instead of the photo.
- * @date 10 of April of 2016
*/
public class InlineQueryResultCachedPhoto implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String PHOTOFILEID_FIELD = "photo_file_id";
@@ -25,6 +23,7 @@ public class InlineQueryResultCachedPhoto implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "photo"; ///< Type of the result, must be “photo”
@@ -42,6 +41,8 @@ public class InlineQueryResultCachedPhoto implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedPhoto() {
super();
@@ -114,6 +115,15 @@ public class InlineQueryResultCachedPhoto implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultCachedPhoto setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -139,8 +149,9 @@ public class InlineQueryResultCachedPhoto implements InlineQueryResult {
", title='" + title + '\'' +
", description='" + description + '\'' +
", caption='" + caption + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", inputMessageContent=" + inputMessageContent +
+ ", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java
index c0a526fb..71d3af36 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVideo.java
@@ -10,13 +10,11 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to a video file stored on the Telegram servers. By default, this video
+ * Represents a link to a video file stored on the Telegram servers. By default, this video
* file will be sent by the user with an optional caption. Alternatively, you can use
* input_message_content to send a message with the specified content instead of the video.
- * @date 10 of April of 2016
*/
public class InlineQueryResultCachedVideo implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String VIDEO_FILE_ID_FIELD = "video_file_id";
@@ -25,6 +23,7 @@ public class InlineQueryResultCachedVideo implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "video"; ///< Type of the result, must be "video"
@@ -42,6 +41,8 @@ public class InlineQueryResultCachedVideo implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedVideo() {
super();
@@ -114,6 +115,15 @@ public class InlineQueryResultCachedVideo implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultCachedVideo setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -135,12 +145,13 @@ public class InlineQueryResultCachedVideo implements InlineQueryResult {
return "InlineQueryResultCachedVideo{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
- ", caption='" + caption + '\'' +
", videoFileId='" + videoFileId + '\'' +
", title='" + title + '\'' +
", description='" + description + '\'' +
- ", inputMessageContent='" + inputMessageContent + '\'' +
- ", replyMarkup='" + replyMarkup + '\'' +
+ ", caption='" + caption + '\'' +
+ ", inputMessageContent=" + inputMessageContent +
+ ", replyMarkup=" + replyMarkup +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java
index 5a3539d2..665e25bd 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/inlinequery/result/chached/InlineQueryResultCachedVoice.java
@@ -10,15 +10,13 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Represents a link to a voice message stored on the Telegram servers. By default, this
+ * Represents a link to a voice message stored on the Telegram servers. By default, this
* voice message will be sent by the user. Alternatively, you can use input_message_content to send
* a message with the specified content instead of the voice message.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* ignore them.
- * @date 10 of April of 2016
*/
public class InlineQueryResultCachedVoice implements InlineQueryResult {
-
private static final String TYPE_FIELD = "type";
private static final String ID_FIELD = "id";
private static final String VOICE_FILE_ID_FIELD = "voice_file_id";
@@ -26,6 +24,7 @@ public class InlineQueryResultCachedVoice implements InlineQueryResult {
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String CAPTION_FIELD = "caption";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(TYPE_FIELD)
private final String type = "voice"; ///< Type of the result, must be "voice"
@@ -41,6 +40,8 @@ public class InlineQueryResultCachedVoice implements InlineQueryResult {
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Voice caption (may also be used when resending documents by file_id), 0-200 characters
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
public InlineQueryResultCachedVoice() {
super();
@@ -104,6 +105,15 @@ public class InlineQueryResultCachedVoice implements InlineQueryResult {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineQueryResultCachedVoice setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@@ -123,12 +133,14 @@ public class InlineQueryResultCachedVoice implements InlineQueryResult {
@Override
public String toString() {
return "InlineQueryResultCachedVoice{" +
- "id='" + id + '\'' +
+ "type='" + type + '\'' +
+ ", id='" + id + '\'' +
", voiceFileId='" + voiceFileId + '\'' +
", title='" + title + '\'' +
", inputMessageContent=" + inputMessageContent +
", replyMarkup=" + replyMarkup +
", caption='" + caption + '\'' +
+ ", parseMode='" + parseMode + '\'' +
'}';
}
}
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMedia.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMedia.java
index ff1a0ce2..327ffe32 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMedia.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMedia.java
@@ -17,6 +17,7 @@ public abstract class InputMedia implements InputBotApiObject, Validable {
protected static final String TYPE_FIELD = "type";
private static final String MEDIA_FIELD = "media";
private static final String CAPTION_FIELD = "caption";
+ private static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(MEDIA_FIELD)
/**
@@ -27,7 +28,8 @@ public abstract class InputMedia implements InputBotApiObject, Validable {
private String media;
@JsonProperty(CAPTION_FIELD)
private String caption; ///< Optional. Caption of the media to be sent, 0-200 characters
-
+ @JsonProperty(PARSEMODE_FIELD)
+ private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
@JsonIgnore
private boolean isNewMedia; ///< True to upload a new media, false to use a fileId or URL
@JsonIgnore
@@ -113,6 +115,15 @@ public abstract class InputMedia implements InputBotApiObject, Validable {
return this;
}
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InputMedia setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
@Override
public void validate() throws TelegramApiValidationException {
if (isNewMedia) {
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMediaVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMediaVideo.java
index 94475198..a4d90f2e 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMediaVideo.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/media/InputMediaVideo.java
@@ -16,6 +16,7 @@ public class InputMediaVideo extends InputMedia {
private static final String WIDTH_FIELD = "width";
private static final String HEIGHT_FIELD = "height";
private static final String DURATION_FIELD = "duration";
+ private static final String SUPPORTSSTREAMING_FIELD = "supports_streaming";
@JsonProperty(WIDTH_FIELD)
private int width; ///< Optional. Video width
@@ -23,6 +24,8 @@ public class InputMediaVideo extends InputMedia {
private int height; ///< Optional. Video height
@JsonProperty(DURATION_FIELD)
private int duration; ///< Optional. Video duration
+ @JsonProperty(SUPPORTSSTREAMING_FIELD)
+ private Boolean supportsStreaming; ///< Optional. Pass True, if the uploaded video is suitable for streaming
public InputMediaVideo() {
super();
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ForceReplyKeyboard.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ForceReplyKeyboard.java
index d34b5543..a68c9542 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ForceReplyKeyboard.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ForceReplyKeyboard.java
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
+import java.util.Objects;
+
/**
* @author Ruben Bermudez
* @version 1.0
@@ -56,6 +58,25 @@ public class ForceReplyKeyboard implements ReplyKeyboard {
}
}
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof ForceReplyKeyboard)) {
+ return false;
+ }
+ ForceReplyKeyboard forceReplyKeyboard = (ForceReplyKeyboard) o;
+ return Objects.equals(forceReply, forceReplyKeyboard.forceReply)
+ && Objects.equals(selective, forceReplyKeyboard.selective)
+ ;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ forceReply,
+ selective);
+ }
+
@Override
public String toString() {
return "ForceReplyKeyboard{" +
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java
index b3ae10bc..c5bf9d62 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java
@@ -7,6 +7,7 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* @author Ruben Bermudez
@@ -50,6 +51,21 @@ public class InlineKeyboardMarkup implements ReplyKeyboard {
}
}
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof InlineKeyboardMarkup)) {
+ return false;
+ }
+ InlineKeyboardMarkup inlineKeyboardMarkup = (InlineKeyboardMarkup) o;
+ return Objects.equals(keyboard, inlineKeyboardMarkup.keyboard);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(keyboard);
+ }
+
@Override
public String toString() {
return "InlineKeyboardMarkup{" +
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardMarkup.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardMarkup.java
index 6486eb88..c410907c 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardMarkup.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardMarkup.java
@@ -7,6 +7,7 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* @author Ruben Bermudez
@@ -87,6 +88,29 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
}
}
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof ReplyKeyboardMarkup)) {
+ return false;
+ }
+ ReplyKeyboardMarkup replyKeyboardMarkup = (ReplyKeyboardMarkup) o;
+ return Objects.equals(keyboard, replyKeyboardMarkup.keyboard)
+ && Objects.equals(oneTimeKeyboard, replyKeyboardMarkup.oneTimeKeyboard)
+ && Objects.equals(resizeKeyboard, replyKeyboardMarkup.resizeKeyboard)
+ && Objects.equals(selective, replyKeyboardMarkup.selective)
+ ;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ keyboard,
+ oneTimeKeyboard,
+ resizeKeyboard,
+ selective);
+ }
+
@Override
public String toString() {
return "ReplyKeyboardMarkup{" +
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardRemove.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardRemove.java
index 250106fa..279101ea 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardRemove.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/ReplyKeyboardRemove.java
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
+import java.util.Objects;
+
/**
* @author Ruben Bermudez
* @version 1.0
@@ -52,6 +54,25 @@ public class ReplyKeyboardRemove implements ReplyKeyboard {
}
}
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof ReplyKeyboardRemove)) {
+ return false;
+ }
+ ReplyKeyboardRemove replyKeyboardRemove = (ReplyKeyboardRemove) o;
+ return Objects.equals(removeKeyboard, replyKeyboardRemove.removeKeyboard)
+ && Objects.equals(selective, replyKeyboardRemove.selective)
+ ;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ removeKeyboard,
+ selective);
+ }
+
@Override
public String toString() {
return "ReplyKeyboardRemove{" +
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/InlineKeyboardButton.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/InlineKeyboardButton.java
index 419d0175..d40cdfff 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/InlineKeyboardButton.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/InlineKeyboardButton.java
@@ -6,6 +6,8 @@ import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.api.objects.games.CallbackGame;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
+import java.util.Objects;
+
import static com.google.common.base.Preconditions.checkNotNull;
/**
@@ -146,6 +148,35 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
}
}
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof InlineKeyboardButton)) {
+ return false;
+ }
+ InlineKeyboardButton inlineKeyboardButton = (InlineKeyboardButton) o;
+ return Objects.equals(callbackData, inlineKeyboardButton.callbackData)
+ && Objects.equals(callbackGame, inlineKeyboardButton.callbackGame)
+ && Objects.equals(pay, inlineKeyboardButton.pay)
+ && Objects.equals(switchInlineQuery, inlineKeyboardButton.switchInlineQuery)
+ && Objects.equals(switchInlineQueryCurrentChat, inlineKeyboardButton.switchInlineQueryCurrentChat)
+ && Objects.equals(text, inlineKeyboardButton.text)
+ && Objects.equals(url, inlineKeyboardButton.url)
+ ;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ callbackData,
+ callbackGame,
+ pay,
+ switchInlineQuery,
+ switchInlineQueryCurrentChat,
+ text,
+ url);
+ }
+
@Override
public String toString() {
return "InlineKeyboardButton{" +
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/KeyboardButton.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/KeyboardButton.java
index db313c59..42575dcd 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/KeyboardButton.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/buttons/KeyboardButton.java
@@ -6,6 +6,8 @@ import org.telegram.telegrambots.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
+import java.util.Objects;
+
/**
* @author Ruben Bermudez
* @version 1.0
@@ -88,6 +90,27 @@ public class KeyboardButton implements InputBotApiObject, Validable {
}
}
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof KeyboardButton)) {
+ return false;
+ }
+ KeyboardButton keyboardButton = (KeyboardButton) o;
+ return Objects.equals(requestContact, keyboardButton.requestContact)
+ && Objects.equals(requestLocation, keyboardButton.requestLocation)
+ && Objects.equals(text, keyboardButton.text)
+ ;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ requestContact,
+ requestLocation,
+ text);
+ }
+
@Override
public String toString() {
return "KeyboardButton{" +
diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/api/methods/send/SendMessageTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/api/methods/send/SendMessageTest.java
new file mode 100644
index 00000000..d5854ece
--- /dev/null
+++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/api/methods/send/SendMessageTest.java
@@ -0,0 +1,25 @@
+package org.telegram.telegrambots.api.methods.send;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class SendMessageTest {
+
+ @Test
+ public void comparison() throws Exception {
+ SendMessage sm1 = new SendMessage().setChatId(1L).setText("Hello World");
+ SendMessage sm2 = new SendMessage().setChatId(1L).setText("Hello World");
+ SendMessage noMessage = new SendMessage().setChatId(1L);
+ SendMessage disabledNotification = new SendMessage().setChatId(1L).setText("Hello World").disableNotification();
+
+ assertTrue(sm1.equals(sm2));
+ assertFalse(sm1.equals(noMessage));
+ assertFalse(sm1.equals(disabledNotification));
+
+ assertTrue(sm1.hashCode() == sm2.hashCode());
+ assertFalse(sm1.hashCode() == noMessage.hashCode());
+ assertFalse(sm1.hashCode() == disabledNotification.hashCode());
+ }
+
+}
\ No newline at end of file
diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml
index bf4ef83d..cf56f9bb 100644
--- a/telegrambots/pom.xml
+++ b/telegrambots/pom.xml
@@ -5,7 +5,7 @@
4.0.0
org.telegram
telegrambots
- 3.5
+ 3.6
jar
Telegram Bots
@@ -66,7 +66,7 @@
2.8.7
2.8.0
2.5
- 3.5
+ 3.6
diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
index b592594b..52d88b08 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
@@ -51,7 +51,7 @@ import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
public abstract class DefaultAbsSender extends AbsSender {
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
- private final ExecutorService exe;
+ protected final ExecutorService exe;
private final ObjectMapper objectMapper = new ObjectMapper();
private final DefaultBotOptions options;
private volatile CloseableHttpClient httpclient;
@@ -157,6 +157,9 @@ public abstract class DefaultAbsSender extends AbsSender {
}
if (sendDocument.getCaption() != null) {
builder.addTextBody(SendDocument.CAPTION_FIELD, sendDocument.getCaption(), TEXT_PLAIN_CONTENT_TYPE);
+ if (sendDocument.getParseMode() != null) {
+ builder.addTextBody(SendDocument.PARSEMODE_FIELD, sendDocument.getParseMode(), TEXT_PLAIN_CONTENT_TYPE);
+ }
}
if (sendDocument.getDisableNotification() != null) {
builder.addTextBody(SendDocument.DISABLENOTIFICATION_FIELD, sendDocument.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE);
@@ -202,6 +205,9 @@ public abstract class DefaultAbsSender extends AbsSender {
}
if (sendPhoto.getCaption() != null) {
builder.addTextBody(SendPhoto.CAPTION_FIELD, sendPhoto.getCaption(), TEXT_PLAIN_CONTENT_TYPE);
+ if (sendPhoto.getParseMode() != null) {
+ builder.addTextBody(SendPhoto.PARSEMODE_FIELD, sendPhoto.getParseMode(), TEXT_PLAIN_CONTENT_TYPE);
+ }
}
if (sendPhoto.getDisableNotification() != null) {
builder.addTextBody(SendPhoto.DISABLENOTIFICATION_FIELD, sendPhoto.getDisableNotification().toString(), TEXT_PLAIN_CONTENT_TYPE);
@@ -247,6 +253,12 @@ public abstract class DefaultAbsSender extends AbsSender {
}
if (sendVideo.getCaption() != null) {
builder.addTextBody(SendVideo.CAPTION_FIELD, sendVideo.getCaption(), TEXT_PLAIN_CONTENT_TYPE);
+ if (sendVideo.getParseMode() != null) {
+ builder.addTextBody(SendVideo.PARSEMODE_FIELD, sendVideo.getParseMode(), TEXT_PLAIN_CONTENT_TYPE);
+ }
+ }
+ if (sendVideo.getSupportsStreaming() != null) {
+ builder.addTextBody(SendVideo.SUPPORTSSTREAMING_FIELD, sendVideo.getSupportsStreaming().toString(), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendVideo.getDuration() != null) {
builder.addTextBody(SendVideo.DURATION_FIELD, sendVideo.getDuration().toString(), TEXT_PLAIN_CONTENT_TYPE);
@@ -408,6 +420,9 @@ public abstract class DefaultAbsSender extends AbsSender {
}
if (sendAudio.getCaption() != null) {
builder.addTextBody(SendAudio.CAPTION_FIELD, sendAudio.getCaption(), TEXT_PLAIN_CONTENT_TYPE);
+ if (sendAudio.getParseMode() != null) {
+ builder.addTextBody(SendAudio.PARSEMODE_FIELD, sendAudio.getParseMode(), TEXT_PLAIN_CONTENT_TYPE);
+ }
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
@@ -462,6 +477,9 @@ public abstract class DefaultAbsSender extends AbsSender {
}
if (sendVoice.getCaption() != null) {
builder.addTextBody(SendVoice.CAPTION_FIELD, sendVoice.getCaption(), TEXT_PLAIN_CONTENT_TYPE);
+ if (sendVoice.getParseMode() != null) {
+ builder.addTextBody(SendVoice.PARSEMODE_FIELD, sendVoice.getParseMode(), TEXT_PLAIN_CONTENT_TYPE);
+ }
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java
index 50da8e71..8a3508de 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/TelegramLongPollingBot.java
@@ -55,4 +55,10 @@ public abstract class TelegramLongPollingBot extends DefaultAbsSender implements
throw new TelegramApiRequestException("Error executing setWebook method", e);
}
}
+
+ @Override
+ public void onClosing() {
+ exe.shutdown();
+ }
+
}
diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java
index 8de4ba24..2e310b33 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java
@@ -69,7 +69,7 @@ public class DefaultBotSession implements BotSession {
lastReceivedUpdate = 0;
- readerThread = new ReaderThread(updatesSupplier);
+ readerThread = new ReaderThread(updatesSupplier, this);
readerThread.setName(callback.getBotUsername() + " Telegram Connection");
readerThread.start();
@@ -135,12 +135,14 @@ public class DefaultBotSession implements BotSession {
private class ReaderThread extends Thread implements UpdatesReader {
private final UpdatesSupplier updatesSupplier;
+ private final Object lock;
private CloseableHttpClient httpclient;
private ExponentialBackOff exponentialBackOff;
private RequestConfig requestConfig;
- public ReaderThread(UpdatesSupplier updatesSupplier) {
+ public ReaderThread(UpdatesSupplier updatesSupplier, Object lock) {
this.updatesSupplier = Optional.ofNullable(updatesSupplier).orElse(this::getUpdatesFromServer);
+ this.lock = lock;
}
@Override
@@ -183,48 +185,52 @@ public class DefaultBotSession implements BotSession {
public void run() {
setPriority(Thread.MIN_PRIORITY);
while (running) {
- try {
- List updates = updatesSupplier.getUpdates();
- if (updates.isEmpty()) {
- synchronized (this) {
- this.wait(500);
- }
- } else {
- updates.removeIf(x -> x.getUpdateId() < lastReceivedUpdate);
- lastReceivedUpdate = updates.parallelStream()
- .map(
- Update::getUpdateId)
- .max(Integer::compareTo)
- .orElse(0);
- receivedUpdates.addAll(updates);
+ synchronized (lock) {
+ if (running) {
+ try {
+ List updates = updatesSupplier.getUpdates();
+ if (updates.isEmpty()) {
+ lock.wait(500);
+ } else {
+ updates.removeIf(x -> x.getUpdateId() < lastReceivedUpdate);
+ lastReceivedUpdate = updates.parallelStream()
+ .map(
+ Update::getUpdateId)
+ .max(Integer::compareTo)
+ .orElse(0);
+ receivedUpdates.addAll(updates);
- synchronized (receivedUpdates) {
- receivedUpdates.notifyAll();
+ synchronized (receivedUpdates) {
+ receivedUpdates.notifyAll();
+ }
+ }
+ } catch (InterruptedException e) {
+ if (!running) {
+ receivedUpdates.clear();
+ }
+ BotLogger.debug(LOGTAG, e);
+ interrupt();
+ } catch (Exception global) {
+ BotLogger.severe(LOGTAG, global);
+ try {
+ synchronized (lock) {
+ lock.wait(exponentialBackOff.nextBackOffMillis());
+ }
+ } catch (InterruptedException e) {
+ if (!running) {
+ receivedUpdates.clear();
+ }
+ BotLogger.debug(LOGTAG, e);
+ interrupt();
+ }
}
}
- } catch (InterruptedException e) {
- if (!running) {
- receivedUpdates.clear();
- }
- BotLogger.debug(LOGTAG, e);
- } catch (Exception global) {
- BotLogger.severe(LOGTAG, global);
- try {
- synchronized (this) {
- this.wait(exponentialBackOff.nextBackOffMillis());
- }
- } catch (InterruptedException e) {
- if (!running) {
- receivedUpdates.clear();
- }
- BotLogger.debug(LOGTAG, e);
- }
}
}
BotLogger.debug(LOGTAG, "Reader thread has being closed");
}
- private List getUpdatesFromServer() throws InterruptedException, Exception {
+ private List getUpdatesFromServer() throws IOException {
GetUpdates request = new GetUpdates()
.setLimit(100)
.setTimeout(ApiConstants.GETUPDATES_TIMEOUT)
@@ -248,8 +254,8 @@ public class DefaultBotSession implements BotSession {
if (response.getStatusLine().getStatusCode() >= 500) {
BotLogger.warn(LOGTAG, responseContent);
- synchronized (this) {
- this.wait(500);
+ synchronized (lock) {
+ lock.wait(500);
}
} else {
try {
@@ -260,14 +266,13 @@ public class DefaultBotSession implements BotSession {
BotLogger.severe(responseContent, LOGTAG, e);
}
}
- } catch (SocketException e) {
- if (!e.getMessage().equals("Socket Closed")) {
- BotLogger.severe(LOGTAG, e);
- }
+ } catch (SocketException | InvalidObjectException | TelegramApiRequestException e) {
+ BotLogger.severe(LOGTAG, e);
} catch (SocketTimeoutException e) {
BotLogger.fine(LOGTAG, e);
- } catch (InvalidObjectException | TelegramApiRequestException e) {
- BotLogger.severe(LOGTAG, e);
+ } catch (InterruptedException e) {
+ BotLogger.fine(LOGTAG, e);
+ interrupt();
}
return Collections.emptyList();
}
@@ -275,7 +280,7 @@ public class DefaultBotSession implements BotSession {
public interface UpdatesSupplier {
- List getUpdates() throws InterruptedException, Exception;
+ List getUpdates() throws Exception;
}
private List getUpdateList() {
@@ -306,6 +311,7 @@ public class DefaultBotSession implements BotSession {
callback.onUpdatesReceived(updates);
} catch (InterruptedException e) {
BotLogger.debug(LOGTAG, e);
+ interrupt();
} catch (Exception e) {
BotLogger.severe(LOGTAG, e);
}
diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
index 23dbfc6d..992ee446 100644
--- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
+++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
@@ -3,11 +3,17 @@ package org.telegram.telegrambots.test;
import org.junit.Test;
import org.mockito.Mockito;
import org.telegram.telegrambots.api.objects.Update;
+import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
+import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
import static java.util.Arrays.asList;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyList;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
public class TelegramLongPollingBotTest {
@@ -21,4 +27,41 @@ public class TelegramLongPollingBotTest {
Mockito.verify(bot).onUpdateReceived(update1);
Mockito.verify(bot).onUpdateReceived(update2);
}
-}
\ No newline at end of file
+
+ @Test
+ public void testExecutorShutdown() throws Exception {
+ TestBot bot = Mockito.spy(new TestBot());
+ DefaultBotSession session = new DefaultBotSession();
+ session.setCallback(bot);
+ session.setOptions(new DefaultBotOptions());
+ session.start();
+ session.stop();
+ Mockito.verify(bot).onClosing();
+ ExecutorService executor = bot.getExecutor();
+ assertThat("Executor was not shut down", executor.isShutdown(), is(true));
+ executor.awaitTermination(1, TimeUnit.SECONDS);
+ assertThat("Executor could not terminate", executor.isTerminated(), is(true));
+ }
+
+ private static class TestBot extends TelegramLongPollingBot {
+
+ @Override
+ public void onUpdateReceived(Update update) {
+ }
+
+ ExecutorService getExecutor() {
+ return exe;
+ }
+
+ @Override
+ public String getBotUsername() {
+ return "";
+ }
+
+ @Override
+ public String getBotToken() {
+ return "";
+ }
+ }
+
+}