commit
15ff562dac
@ -15,7 +15,7 @@ Both ways are supported, but I recommend long polling method.
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Just import add the library to your project using [Maven, Gradly, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.4) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.4)
|
Just import add the library to your project using [Maven, Gradle, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.3.5) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.3.5)
|
||||||
|
|
||||||
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.
|
||||||
|
|
||||||
|
30
pom.xml
30
pom.xml
@ -6,7 +6,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<groupId>org.telegram</groupId>
|
<groupId>org.telegram</groupId>
|
||||||
<artifactId>telegrambots</artifactId>
|
<artifactId>telegrambots</artifactId>
|
||||||
<version>2.3.3.4</version>
|
<version>2.3.3.5</version>
|
||||||
|
|
||||||
<name>Telegram Bots</name>
|
<name>Telegram Bots</name>
|
||||||
<url>https://telegram.me/JavaBotsApi</url>
|
<url>https://telegram.me/JavaBotsApi</url>
|
||||||
@ -145,6 +145,34 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.4.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||||
|
<createDependencyReducedPom>true</createDependencyReducedPom>
|
||||||
|
<artifactSet>
|
||||||
|
<includes>
|
||||||
|
<include>org.apache.httpcomponents:*</include>
|
||||||
|
</includes>
|
||||||
|
</artifactSet>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.apache.http</pattern>
|
||||||
|
<shadedPattern>embedded.org.apache.http</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -105,7 +105,6 @@ public class TelegramBotsApi {
|
|||||||
* @param webHookURL
|
* @param webHookURL
|
||||||
* @param botToken
|
* @param botToken
|
||||||
* @param publicCertificatePath
|
* @param publicCertificatePath
|
||||||
* @param publicCertificateName
|
|
||||||
* @throws TelegramApiException
|
* @throws TelegramApiException
|
||||||
*/
|
*/
|
||||||
private static void setWebhook(String webHookURL, String botToken, String publicCertificatePath) throws TelegramApiException {
|
private static void setWebhook(String webHookURL, String botToken, String publicCertificatePath) throws TelegramApiException {
|
||||||
@ -145,7 +144,7 @@ public class TelegramBotsApi {
|
|||||||
*/
|
*/
|
||||||
public BotSession registerBot(TelegramLongPollingBot bot) throws TelegramApiException {
|
public BotSession registerBot(TelegramLongPollingBot bot) throws TelegramApiException {
|
||||||
setWebhook(bot.getBotToken(), null);
|
setWebhook(bot.getBotToken(), null);
|
||||||
return new BotSession(bot.getBotToken(), bot);
|
return new BotSession(bot.getBotToken(), bot, bot.getOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,7 +109,7 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "AnswerInlineQuery{" +
|
return "AnswerCallbackQuery{" +
|
||||||
"callbackQueryId='" + callbackQueryId + '\'' +
|
"callbackQueryId='" + callbackQueryId + '\'' +
|
||||||
", text=" + text +
|
", text=" + text +
|
||||||
", showAlert=" + showAlert + '\'' +
|
", showAlert=" + showAlert + '\'' +
|
||||||
|
@ -19,7 +19,7 @@ import java.io.IOException;
|
|||||||
* @date 20 of May of 2016
|
* @date 20 of May of 2016
|
||||||
*/
|
*/
|
||||||
public class GetChatMember extends BotApiMethod<ChatMember> {
|
public class GetChatMember extends BotApiMethod<ChatMember> {
|
||||||
public static final String PATH = "getChatAdministrators";
|
public static final String PATH = "getChatMember";
|
||||||
|
|
||||||
private static final String CHATID_FIELD = "chat_id";
|
private static final String CHATID_FIELD = "chat_id";
|
||||||
private static final String USERID_FIELD = "user_id";
|
private static final String USERID_FIELD = "user_id";
|
||||||
|
@ -17,7 +17,7 @@ import java.io.IOException;
|
|||||||
* @date 20 of May of 2016
|
* @date 20 of May of 2016
|
||||||
*/
|
*/
|
||||||
public class GetChatMemberCount extends BotApiMethod<Integer> {
|
public class GetChatMemberCount extends BotApiMethod<Integer> {
|
||||||
public static final String PATH = "getChatAdministrators";
|
public static final String PATH = "getChatMembersCount";
|
||||||
|
|
||||||
private static final String CHATID_FIELD = "chat_id";
|
private static final String CHATID_FIELD = "chat_id";
|
||||||
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
|
||||||
|
@ -90,7 +90,7 @@ public class KickChatMember extends BotApiMethod<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SendMessage{" +
|
return "KickChatMember{" +
|
||||||
"chatId='" + chatId + '\'' +
|
"chatId='" + chatId + '\'' +
|
||||||
", userId='" + userId +
|
", userId='" + userId +
|
||||||
'}';
|
'}';
|
||||||
|
@ -86,7 +86,7 @@ public class UnbanChatMember extends BotApiMethod<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SendMessage{" +
|
return "UnbanChatMember{" +
|
||||||
"chatId='" + chatId + '\'' +
|
"chatId='" + chatId + '\'' +
|
||||||
", userId='" + userId +
|
", userId='" + userId +
|
||||||
'}';
|
'}';
|
||||||
|
@ -207,7 +207,7 @@ public class SendContact extends BotApiMethod<Message> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SendLocation{" +
|
return "SendContact{" +
|
||||||
"chatId='" + chatId + '\'' +
|
"chatId='" + chatId + '\'' +
|
||||||
", phoneNumber=" + phoneNumber +
|
", phoneNumber=" + phoneNumber +
|
||||||
", firstName=" + firstName +
|
", firstName=" + firstName +
|
||||||
|
@ -233,7 +233,7 @@ public class SendVenue extends BotApiMethod<Message> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SendLocation{" +
|
return "SendVenue{" +
|
||||||
"chatId='" + chatId + '\'' +
|
"chatId='" + chatId + '\'' +
|
||||||
", latitude=" + latitude +
|
", latitude=" + latitude +
|
||||||
", longitude=" + longitude +
|
", longitude=" + longitude +
|
||||||
|
@ -107,7 +107,7 @@ public class CallbackQuery implements IBotApiObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Contact{" +
|
return "CallbackQuery{" +
|
||||||
"id='" + id + '\'' +
|
"id='" + id + '\'' +
|
||||||
", from='" + from + '\'' +
|
", from='" + from + '\'' +
|
||||||
", message='" + message + '\'' +
|
", message='" + message + '\'' +
|
||||||
|
@ -119,7 +119,7 @@ public class MessageEntity implements IBotApiObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PhotoSize{" +
|
return "MessageEntity{" +
|
||||||
"type='" + type + '\'' +
|
"type='" + type + '\'' +
|
||||||
", offset=" + offset +
|
", offset=" + offset +
|
||||||
", length=" + length +
|
", length=" + length +
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.telegram.telegrambots.bots;
|
package org.telegram.telegrambots.bots;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
@ -77,18 +78,25 @@ public abstract class AbsSender {
|
|||||||
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
|
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
private final ExecutorService exe = Executors.newSingleThreadExecutor();
|
private final ExecutorService exe = Executors.newSingleThreadExecutor();
|
||||||
|
private final BotOptions options;
|
||||||
private volatile CloseableHttpClient httpclient;
|
private volatile CloseableHttpClient httpclient;
|
||||||
private volatile RequestConfig requestConfig;
|
private volatile RequestConfig requestConfig;
|
||||||
private static final int SOCKET_TIMEOUT = 75 * 1000;
|
private static final int SOCKET_TIMEOUT = 75 * 1000;
|
||||||
|
|
||||||
AbsSender() {
|
AbsSender(BotOptions options) {
|
||||||
|
this.options = options;
|
||||||
httpclient = HttpClientBuilder.create()
|
httpclient = HttpClientBuilder.create()
|
||||||
.setSSLHostnameVerifier(new NoopHostnameVerifier())
|
.setSSLHostnameVerifier(new NoopHostnameVerifier())
|
||||||
.setConnectionTimeToLive(70, TimeUnit.SECONDS)
|
.setConnectionTimeToLive(70, TimeUnit.SECONDS)
|
||||||
.setMaxConnTotal(100)
|
.setMaxConnTotal(100)
|
||||||
.build();
|
.build();
|
||||||
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
|
|
||||||
.setSocketTimeout(SOCKET_TIMEOUT)
|
RequestConfig.Builder configBuilder = RequestConfig.copy(RequestConfig.custom().build());
|
||||||
|
if (options.hasProxy()) {
|
||||||
|
configBuilder.setProxy(new HttpHost(options.getProxyHost(), options.getProxyPort()));
|
||||||
|
}
|
||||||
|
|
||||||
|
requestConfig = configBuilder.setSocketTimeout(SOCKET_TIMEOUT)
|
||||||
.setConnectTimeout(SOCKET_TIMEOUT)
|
.setConnectTimeout(SOCKET_TIMEOUT)
|
||||||
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
|
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
|
||||||
}
|
}
|
||||||
@ -99,9 +107,13 @@ public abstract class AbsSender {
|
|||||||
*/
|
*/
|
||||||
public abstract String getBotToken();
|
public abstract String getBotToken();
|
||||||
|
|
||||||
|
public final BotOptions getOptions() {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
// Send Requests
|
// Send Requests
|
||||||
|
|
||||||
public Message sendMessage(SendMessage sendMessage) throws TelegramApiException {
|
public final Message sendMessage(SendMessage sendMessage) throws TelegramApiException {
|
||||||
if (sendMessage == null) {
|
if (sendMessage == null) {
|
||||||
throw new TelegramApiException("Parameter sendMessage can not be null");
|
throw new TelegramApiException("Parameter sendMessage can not be null");
|
||||||
}
|
}
|
||||||
@ -109,7 +121,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(sendMessage);
|
return sendApiMethod(sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean answerInlineQuery(AnswerInlineQuery answerInlineQuery) throws TelegramApiException {
|
public final Boolean answerInlineQuery(AnswerInlineQuery answerInlineQuery) throws TelegramApiException {
|
||||||
if (answerInlineQuery == null) {
|
if (answerInlineQuery == null) {
|
||||||
throw new TelegramApiException("Parameter answerInlineQuery can not be null");
|
throw new TelegramApiException("Parameter answerInlineQuery can not be null");
|
||||||
}
|
}
|
||||||
@ -117,7 +129,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(answerInlineQuery);
|
return sendApiMethod(answerInlineQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean sendChatAction(SendChatAction sendChatAction) throws TelegramApiException {
|
public final Boolean sendChatAction(SendChatAction sendChatAction) throws TelegramApiException {
|
||||||
if (sendChatAction == null) {
|
if (sendChatAction == null) {
|
||||||
throw new TelegramApiException("Parameter sendChatAction can not be null");
|
throw new TelegramApiException("Parameter sendChatAction can not be null");
|
||||||
}
|
}
|
||||||
@ -125,7 +137,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(sendChatAction);
|
return sendApiMethod(sendChatAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message forwardMessage(ForwardMessage forwardMessage) throws TelegramApiException {
|
public final Message forwardMessage(ForwardMessage forwardMessage) throws TelegramApiException {
|
||||||
if (forwardMessage == null) {
|
if (forwardMessage == null) {
|
||||||
throw new TelegramApiException("Parameter forwardMessage can not be null");
|
throw new TelegramApiException("Parameter forwardMessage can not be null");
|
||||||
}
|
}
|
||||||
@ -133,7 +145,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(forwardMessage);
|
return sendApiMethod(forwardMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message sendLocation(SendLocation sendLocation) throws TelegramApiException {
|
public final Message sendLocation(SendLocation sendLocation) throws TelegramApiException {
|
||||||
if (sendLocation == null) {
|
if (sendLocation == null) {
|
||||||
throw new TelegramApiException("Parameter sendLocation can not be null");
|
throw new TelegramApiException("Parameter sendLocation can not be null");
|
||||||
}
|
}
|
||||||
@ -141,7 +153,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(sendLocation);
|
return sendApiMethod(sendLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message sendVenue(SendVenue sendVenue) throws TelegramApiException {
|
public final Message sendVenue(SendVenue sendVenue) throws TelegramApiException {
|
||||||
if (sendVenue == null) {
|
if (sendVenue == null) {
|
||||||
throw new TelegramApiException("Parameter sendVenue can not be null");
|
throw new TelegramApiException("Parameter sendVenue can not be null");
|
||||||
}
|
}
|
||||||
@ -149,7 +161,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(sendVenue);
|
return sendApiMethod(sendVenue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message sendContact(SendContact sendContact) throws TelegramApiException {
|
public final Message sendContact(SendContact sendContact) throws TelegramApiException {
|
||||||
if (sendContact == null) {
|
if (sendContact == null) {
|
||||||
throw new TelegramApiException("Parameter sendContact can not be null");
|
throw new TelegramApiException("Parameter sendContact can not be null");
|
||||||
}
|
}
|
||||||
@ -157,84 +169,84 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(sendContact);
|
return sendApiMethod(sendContact);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean kickMember(KickChatMember kickChatMember) throws TelegramApiException {
|
public final Boolean kickMember(KickChatMember kickChatMember) throws TelegramApiException {
|
||||||
if (kickChatMember == null) {
|
if (kickChatMember == null) {
|
||||||
throw new TelegramApiException("Parameter kickChatMember can not be null");
|
throw new TelegramApiException("Parameter kickChatMember can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(kickChatMember);
|
return sendApiMethod(kickChatMember);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean unbanMember(UnbanChatMember unbanChatMember) throws TelegramApiException {
|
public final Boolean unbanMember(UnbanChatMember unbanChatMember) throws TelegramApiException {
|
||||||
if (unbanChatMember == null) {
|
if (unbanChatMember == null) {
|
||||||
throw new TelegramApiException("Parameter unbanChatMember can not be null");
|
throw new TelegramApiException("Parameter unbanChatMember can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(unbanChatMember);
|
return sendApiMethod(unbanChatMember);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean leaveChat(LeaveChat leaveChat) throws TelegramApiException {
|
public final Boolean leaveChat(LeaveChat leaveChat) throws TelegramApiException {
|
||||||
if (leaveChat == null) {
|
if (leaveChat == null) {
|
||||||
throw new TelegramApiException("Parameter leaveChat can not be null");
|
throw new TelegramApiException("Parameter leaveChat can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(leaveChat);
|
return sendApiMethod(leaveChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chat getChat(GetChat getChat) throws TelegramApiException {
|
public final Chat getChat(GetChat getChat) throws TelegramApiException {
|
||||||
if (getChat == null) {
|
if (getChat == null) {
|
||||||
throw new TelegramApiException("Parameter getChat can not be null");
|
throw new TelegramApiException("Parameter getChat can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(getChat);
|
return sendApiMethod(getChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ChatMember> getChatAdministrators(GetChatAdministrators getChatAdministrators) throws TelegramApiException {
|
public final List<ChatMember> getChatAdministrators(GetChatAdministrators getChatAdministrators) throws TelegramApiException {
|
||||||
if (getChatAdministrators == null) {
|
if (getChatAdministrators == null) {
|
||||||
throw new TelegramApiException("Parameter getChatAdministrators can not be null");
|
throw new TelegramApiException("Parameter getChatAdministrators can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(getChatAdministrators);
|
return sendApiMethod(getChatAdministrators);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatMember getChatMember(GetChatMember getChatMember) throws TelegramApiException {
|
public final ChatMember getChatMember(GetChatMember getChatMember) throws TelegramApiException {
|
||||||
if (getChatMember == null) {
|
if (getChatMember == null) {
|
||||||
throw new TelegramApiException("Parameter getChatMember can not be null");
|
throw new TelegramApiException("Parameter getChatMember can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(getChatMember);
|
return sendApiMethod(getChatMember);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getChatMemberCount(GetChatMemberCount getChatMemberCount) throws TelegramApiException {
|
public final Integer getChatMemberCount(GetChatMemberCount getChatMemberCount) throws TelegramApiException {
|
||||||
if (getChatMemberCount == null) {
|
if (getChatMemberCount == null) {
|
||||||
throw new TelegramApiException("Parameter getChatMemberCount can not be null");
|
throw new TelegramApiException("Parameter getChatMemberCount can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(getChatMemberCount);
|
return sendApiMethod(getChatMemberCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message editMessageText(EditMessageText editMessageText) throws TelegramApiException {
|
public final Message editMessageText(EditMessageText editMessageText) throws TelegramApiException {
|
||||||
if (editMessageText == null) {
|
if (editMessageText == null) {
|
||||||
throw new TelegramApiException("Parameter editMessageText can not be null");
|
throw new TelegramApiException("Parameter editMessageText can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(editMessageText);
|
return sendApiMethod(editMessageText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException {
|
public final Message editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException {
|
||||||
if (editMessageCaption == null) {
|
if (editMessageCaption == null) {
|
||||||
throw new TelegramApiException("Parameter editMessageCaption can not be null");
|
throw new TelegramApiException("Parameter editMessageCaption can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(editMessageCaption);
|
return sendApiMethod(editMessageCaption);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException {
|
public final Message editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException {
|
||||||
if (editMessageReplyMarkup == null) {
|
if (editMessageReplyMarkup == null) {
|
||||||
throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null");
|
throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(editMessageReplyMarkup);
|
return sendApiMethod(editMessageReplyMarkup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean answerCallbackQuery(AnswerCallbackQuery answerCallbackQuery) throws TelegramApiException {
|
public final Boolean answerCallbackQuery(AnswerCallbackQuery answerCallbackQuery) throws TelegramApiException {
|
||||||
if (answerCallbackQuery == null) {
|
if (answerCallbackQuery == null) {
|
||||||
throw new TelegramApiException("Parameter answerCallbackQuery can not be null");
|
throw new TelegramApiException("Parameter answerCallbackQuery can not be null");
|
||||||
}
|
}
|
||||||
return sendApiMethod(answerCallbackQuery);
|
return sendApiMethod(answerCallbackQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserProfilePhotos getUserProfilePhotos(GetUserProfilePhotos getUserProfilePhotos) throws TelegramApiException {
|
public final UserProfilePhotos getUserProfilePhotos(GetUserProfilePhotos getUserProfilePhotos) throws TelegramApiException {
|
||||||
if (getUserProfilePhotos == null) {
|
if (getUserProfilePhotos == null) {
|
||||||
throw new TelegramApiException("Parameter getUserProfilePhotos can not be null");
|
throw new TelegramApiException("Parameter getUserProfilePhotos can not be null");
|
||||||
}
|
}
|
||||||
@ -242,7 +254,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(getUserProfilePhotos);
|
return sendApiMethod(getUserProfilePhotos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile(GetFile getFile) throws TelegramApiException{
|
public final File getFile(GetFile getFile) throws TelegramApiException{
|
||||||
if(getFile == null){
|
if(getFile == null){
|
||||||
throw new TelegramApiException("Parameter getFile can not be null");
|
throw new TelegramApiException("Parameter getFile can not be null");
|
||||||
}
|
}
|
||||||
@ -252,7 +264,7 @@ public abstract class AbsSender {
|
|||||||
return sendApiMethod(getFile);
|
return sendApiMethod(getFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getMe() throws TelegramApiException {
|
public final User getMe() throws TelegramApiException {
|
||||||
GetMe getMe = new GetMe();
|
GetMe getMe = new GetMe();
|
||||||
|
|
||||||
return sendApiMethod(getMe);
|
return sendApiMethod(getMe);
|
||||||
@ -260,7 +272,7 @@ public abstract class AbsSender {
|
|||||||
|
|
||||||
// Send Requests Async
|
// Send Requests Async
|
||||||
|
|
||||||
public void sendMessageAsync(SendMessage sendMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void sendMessageAsync(SendMessage sendMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (sendMessage == null) {
|
if (sendMessage == null) {
|
||||||
throw new TelegramApiException("Parameter sendMessage can not be null");
|
throw new TelegramApiException("Parameter sendMessage can not be null");
|
||||||
}
|
}
|
||||||
@ -272,7 +284,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(sendMessage, sentCallback);
|
sendApiMethodAsync(sendMessage, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void answerInlineQueryAsync(AnswerInlineQuery answerInlineQuery, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
public final void answerInlineQueryAsync(AnswerInlineQuery answerInlineQuery, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
||||||
if (answerInlineQuery == null) {
|
if (answerInlineQuery == null) {
|
||||||
throw new TelegramApiException("Parameter answerInlineQuery can not be null");
|
throw new TelegramApiException("Parameter answerInlineQuery can not be null");
|
||||||
}
|
}
|
||||||
@ -284,7 +296,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(answerInlineQuery, sentCallback);
|
sendApiMethodAsync(answerInlineQuery, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChatActionAsync(SendChatAction sendChatAction, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
public final void sendChatActionAsync(SendChatAction sendChatAction, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
||||||
if (sendChatAction == null) {
|
if (sendChatAction == null) {
|
||||||
throw new TelegramApiException("Parameter sendChatAction can not be null");
|
throw new TelegramApiException("Parameter sendChatAction can not be null");
|
||||||
}
|
}
|
||||||
@ -296,7 +308,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(sendChatAction, sentCallback);
|
sendApiMethodAsync(sendChatAction, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forwardMessageAsync(ForwardMessage forwardMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void forwardMessageAsync(ForwardMessage forwardMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (forwardMessage == null) {
|
if (forwardMessage == null) {
|
||||||
throw new TelegramApiException("Parameter forwardMessage can not be null");
|
throw new TelegramApiException("Parameter forwardMessage can not be null");
|
||||||
}
|
}
|
||||||
@ -308,7 +320,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(forwardMessage, sentCallback);
|
sendApiMethodAsync(forwardMessage, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLocationAsync(SendLocation sendLocation, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void sendLocationAsync(SendLocation sendLocation, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (sendLocation == null) {
|
if (sendLocation == null) {
|
||||||
throw new TelegramApiException("Parameter sendLocation can not be null");
|
throw new TelegramApiException("Parameter sendLocation can not be null");
|
||||||
}
|
}
|
||||||
@ -320,7 +332,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(sendLocation, sentCallback);
|
sendApiMethodAsync(sendLocation, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendVenueAsync(SendVenue sendVenue, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void sendVenueAsync(SendVenue sendVenue, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (sendVenue == null) {
|
if (sendVenue == null) {
|
||||||
throw new TelegramApiException("Parameter sendVenue can not be null");
|
throw new TelegramApiException("Parameter sendVenue can not be null");
|
||||||
}
|
}
|
||||||
@ -332,7 +344,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(sendVenue, sentCallback);
|
sendApiMethodAsync(sendVenue, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendContactAsync(SendContact sendContact, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void sendContactAsync(SendContact sendContact, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (sendContact == null) {
|
if (sendContact == null) {
|
||||||
throw new TelegramApiException("Parameter sendContact can not be null");
|
throw new TelegramApiException("Parameter sendContact can not be null");
|
||||||
}
|
}
|
||||||
@ -343,7 +355,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(sendContact, sentCallback);
|
sendApiMethodAsync(sendContact, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kickMemberAsync(KickChatMember kickChatMember, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
public final void kickMemberAsync(KickChatMember kickChatMember, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
||||||
if (kickChatMember == null) {
|
if (kickChatMember == null) {
|
||||||
throw new TelegramApiException("Parameter kickChatMember can not be null");
|
throw new TelegramApiException("Parameter kickChatMember can not be null");
|
||||||
}
|
}
|
||||||
@ -354,7 +366,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(kickChatMember, sentCallback);
|
sendApiMethodAsync(kickChatMember, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbanMemberAsync(UnbanChatMember unbanChatMember, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
public final void unbanMemberAsync(UnbanChatMember unbanChatMember, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
||||||
if (unbanChatMember == null) {
|
if (unbanChatMember == null) {
|
||||||
throw new TelegramApiException("Parameter unbanChatMember can not be null");
|
throw new TelegramApiException("Parameter unbanChatMember can not be null");
|
||||||
}
|
}
|
||||||
@ -365,7 +377,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(unbanChatMember, sentCallback);
|
sendApiMethodAsync(unbanChatMember, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leaveChatAsync(LeaveChat leaveChat, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
public final void leaveChatAsync(LeaveChat leaveChat, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
||||||
if (leaveChat == null) {
|
if (leaveChat == null) {
|
||||||
throw new TelegramApiException("Parameter leaveChat can not be null");
|
throw new TelegramApiException("Parameter leaveChat can not be null");
|
||||||
}
|
}
|
||||||
@ -375,7 +387,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(leaveChat, sentCallback);
|
sendApiMethodAsync(leaveChat, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getChatAsync(GetChat getChat, SentCallback<Chat> sentCallback) throws TelegramApiException {
|
public final void getChatAsync(GetChat getChat, SentCallback<Chat> sentCallback) throws TelegramApiException {
|
||||||
if (getChat == null) {
|
if (getChat == null) {
|
||||||
throw new TelegramApiException("Parameter getChat can not be null");
|
throw new TelegramApiException("Parameter getChat can not be null");
|
||||||
}
|
}
|
||||||
@ -385,7 +397,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(getChat, sentCallback);
|
sendApiMethodAsync(getChat, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getChatAdministratorsAsync(GetChatAdministrators getChatAdministrators, SentCallback<ArrayList<ChatMember>> sentCallback) throws TelegramApiException {
|
public final void getChatAdministratorsAsync(GetChatAdministrators getChatAdministrators, SentCallback<ArrayList<ChatMember>> sentCallback) throws TelegramApiException {
|
||||||
if (getChatAdministrators == null) {
|
if (getChatAdministrators == null) {
|
||||||
throw new TelegramApiException("Parameter getChatAdministrators can not be null");
|
throw new TelegramApiException("Parameter getChatAdministrators can not be null");
|
||||||
}
|
}
|
||||||
@ -395,7 +407,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(getChatAdministrators, sentCallback);
|
sendApiMethodAsync(getChatAdministrators, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getChatMemberAsync(GetChatMember getChatMember, SentCallback<ChatMember> sentCallback) throws TelegramApiException {
|
public final void getChatMemberAsync(GetChatMember getChatMember, SentCallback<ChatMember> sentCallback) throws TelegramApiException {
|
||||||
if (getChatMember == null) {
|
if (getChatMember == null) {
|
||||||
throw new TelegramApiException("Parameter getChatMember can not be null");
|
throw new TelegramApiException("Parameter getChatMember can not be null");
|
||||||
}
|
}
|
||||||
@ -405,7 +417,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(getChatMember, sentCallback);
|
sendApiMethodAsync(getChatMember, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getChatMemberCountAsync(GetChatMemberCount getChatMemberCount, SentCallback<Integer> sentCallback) throws TelegramApiException {
|
public final void getChatMemberCountAsync(GetChatMemberCount getChatMemberCount, SentCallback<Integer> sentCallback) throws TelegramApiException {
|
||||||
if (getChatMemberCount == null) {
|
if (getChatMemberCount == null) {
|
||||||
throw new TelegramApiException("Parameter getChatMemberCount can not be null");
|
throw new TelegramApiException("Parameter getChatMemberCount can not be null");
|
||||||
}
|
}
|
||||||
@ -417,7 +429,7 @@ public abstract class AbsSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void editMessageTextAsync(EditMessageText editMessageText, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void editMessageTextAsync(EditMessageText editMessageText, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (editMessageText == null) {
|
if (editMessageText == null) {
|
||||||
throw new TelegramApiException("Parameter editMessageText can not be null");
|
throw new TelegramApiException("Parameter editMessageText can not be null");
|
||||||
}
|
}
|
||||||
@ -428,7 +440,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(editMessageText, sentCallback);
|
sendApiMethodAsync(editMessageText, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (editMessageCaption == null) {
|
if (editMessageCaption == null) {
|
||||||
throw new TelegramApiException("Parameter editMessageCaption can not be null");
|
throw new TelegramApiException("Parameter editMessageCaption can not be null");
|
||||||
}
|
}
|
||||||
@ -439,7 +451,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(editMessageCaption, sentCallback);
|
sendApiMethodAsync(editMessageCaption, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback<Message> sentCallback) throws TelegramApiException {
|
public final void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback<Message> sentCallback) throws TelegramApiException {
|
||||||
if (editMessageReplyMarkup == null) {
|
if (editMessageReplyMarkup == null) {
|
||||||
throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null");
|
throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null");
|
||||||
}
|
}
|
||||||
@ -450,7 +462,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(editMessageReplyMarkup, sentCallback);
|
sendApiMethodAsync(editMessageReplyMarkup, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void answerCallbackQueryAsync(AnswerCallbackQuery answerCallbackQuery, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
public final void answerCallbackQueryAsync(AnswerCallbackQuery answerCallbackQuery, SentCallback<Boolean> sentCallback) throws TelegramApiException {
|
||||||
if (answerCallbackQuery == null) {
|
if (answerCallbackQuery == null) {
|
||||||
throw new TelegramApiException("Parameter answerCallbackQuery can not be null");
|
throw new TelegramApiException("Parameter answerCallbackQuery can not be null");
|
||||||
}
|
}
|
||||||
@ -461,7 +473,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(answerCallbackQuery, sentCallback);
|
sendApiMethodAsync(answerCallbackQuery, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getUserProfilePhotosAsync(GetUserProfilePhotos getUserProfilePhotos, SentCallback<UserProfilePhotos> sentCallback) throws TelegramApiException {
|
public final void getUserProfilePhotosAsync(GetUserProfilePhotos getUserProfilePhotos, SentCallback<UserProfilePhotos> sentCallback) throws TelegramApiException {
|
||||||
if (getUserProfilePhotos == null) {
|
if (getUserProfilePhotos == null) {
|
||||||
throw new TelegramApiException("Parameter getUserProfilePhotos can not be null");
|
throw new TelegramApiException("Parameter getUserProfilePhotos can not be null");
|
||||||
}
|
}
|
||||||
@ -473,7 +485,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(getUserProfilePhotos, sentCallback);
|
sendApiMethodAsync(getUserProfilePhotos, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getFileAsync(GetFile getFile, SentCallback<File> sentCallback) throws TelegramApiException {
|
public final void getFileAsync(GetFile getFile, SentCallback<File> sentCallback) throws TelegramApiException {
|
||||||
if (getFile == null) {
|
if (getFile == null) {
|
||||||
throw new TelegramApiException("Parameter getFile can not be null");
|
throw new TelegramApiException("Parameter getFile can not be null");
|
||||||
} else if (getFile.getFileId() == null) {
|
} else if (getFile.getFileId() == null) {
|
||||||
@ -483,7 +495,7 @@ public abstract class AbsSender {
|
|||||||
sendApiMethodAsync(getFile, sentCallback);
|
sendApiMethodAsync(getFile, sentCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getMeAsync(SentCallback<User> sentCallback) throws TelegramApiException {
|
public final void getMeAsync(SentCallback<User> sentCallback) throws TelegramApiException {
|
||||||
if (sentCallback == null) {
|
if (sentCallback == null) {
|
||||||
throw new TelegramApiException("Parameter sentCallback can not be null");
|
throw new TelegramApiException("Parameter sentCallback can not be null");
|
||||||
}
|
}
|
||||||
@ -494,7 +506,7 @@ public abstract class AbsSender {
|
|||||||
|
|
||||||
// Specific Send Requests
|
// Specific Send Requests
|
||||||
|
|
||||||
public Message sendDocument(SendDocument sendDocument) throws TelegramApiException {
|
public final Message sendDocument(SendDocument sendDocument) throws TelegramApiException {
|
||||||
String responseContent;
|
String responseContent;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -561,7 +573,7 @@ public abstract class AbsSender {
|
|||||||
return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT));
|
return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message sendPhoto(SendPhoto sendPhoto) throws TelegramApiException {
|
public final Message sendPhoto(SendPhoto sendPhoto) throws TelegramApiException {
|
||||||
String responseContent;
|
String responseContent;
|
||||||
try {
|
try {
|
||||||
String url = getBaseUrl() + SendPhoto.PATH;
|
String url = getBaseUrl() + SendPhoto.PATH;
|
||||||
@ -627,7 +639,7 @@ public abstract class AbsSender {
|
|||||||
return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT));
|
return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message sendVideo(SendVideo sendVideo) throws TelegramApiException {
|
public final Message sendVideo(SendVideo sendVideo) throws TelegramApiException {
|
||||||
String responseContent;
|
String responseContent;
|
||||||
try {
|
try {
|
||||||
String url = getBaseUrl() + SendVideo.PATH;
|
String url = getBaseUrl() + SendVideo.PATH;
|
||||||
@ -711,7 +723,7 @@ public abstract class AbsSender {
|
|||||||
return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT));
|
return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message sendSticker(SendSticker sendSticker) throws TelegramApiException {
|
public final Message sendSticker(SendSticker sendSticker) throws TelegramApiException {
|
||||||
String responseContent;
|
String responseContent;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -778,7 +790,7 @@ public abstract class AbsSender {
|
|||||||
* @return If success, the sent Message is returned
|
* @return If success, the sent Message is returned
|
||||||
* @throws TelegramApiException If there is any error sending the audio
|
* @throws TelegramApiException If there is any error sending the audio
|
||||||
*/
|
*/
|
||||||
public Message sendAudio(SendAudio sendAudio) throws TelegramApiException {
|
public final Message sendAudio(SendAudio sendAudio) throws TelegramApiException {
|
||||||
String responseContent;
|
String responseContent;
|
||||||
|
|
||||||
|
|
||||||
@ -868,7 +880,7 @@ public abstract class AbsSender {
|
|||||||
* @return If success, the sent Message is returned
|
* @return If success, the sent Message is returned
|
||||||
* @throws TelegramApiException If there is any error sending the audio
|
* @throws TelegramApiException If there is any error sending the audio
|
||||||
*/
|
*/
|
||||||
public Message sendVoice(SendVoice sendVoice) throws TelegramApiException {
|
public final Message sendVoice(SendVoice sendVoice) throws TelegramApiException {
|
||||||
String responseContent;
|
String responseContent;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
35
src/main/java/org/telegram/telegrambots/bots/BotOptions.java
Normal file
35
src/main/java/org/telegram/telegrambots/bots/BotOptions.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package org.telegram.telegrambots.bots;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ruben Bermudez
|
||||||
|
* @version 1.0
|
||||||
|
* @brief Configurations for the Bot
|
||||||
|
* @date 21 of July of 2016
|
||||||
|
*/
|
||||||
|
public class BotOptions {
|
||||||
|
private String proxyHost;
|
||||||
|
private int proxyPort;
|
||||||
|
|
||||||
|
public BotOptions() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxyHost() {
|
||||||
|
return proxyHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProxyPort() {
|
||||||
|
return proxyPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyHost(String proxyHost) {
|
||||||
|
this.proxyHost = proxyHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyPort(int proxyPort) {
|
||||||
|
this.proxyPort = proxyPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasProxy() {
|
||||||
|
return proxyHost != null && !proxyHost.isEmpty() && proxyPort > 0;
|
||||||
|
}
|
||||||
|
}
|
@ -7,5 +7,11 @@ package org.telegram.telegrambots.bots;
|
|||||||
* @date 14 of January of 2016
|
* @date 14 of January of 2016
|
||||||
*/
|
*/
|
||||||
public abstract class TelegramLongPollingBot extends AbsSender implements ITelegramLongPollingBot {
|
public abstract class TelegramLongPollingBot extends AbsSender implements ITelegramLongPollingBot {
|
||||||
|
public TelegramLongPollingBot() {
|
||||||
|
this(new BotOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
public TelegramLongPollingBot(BotOptions options) {
|
||||||
|
super(options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,15 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
|||||||
* Use ICommandRegistry's methods on this bot to register commands
|
* Use ICommandRegistry's methods on this bot to register commands
|
||||||
*/
|
*/
|
||||||
public TelegramLongPollingCommandBot() {
|
public TelegramLongPollingCommandBot() {
|
||||||
super();
|
this(new BotOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* construct creates CommandRegistry for this bot.
|
||||||
|
* Use ICommandRegistry's methods on this bot to register commands
|
||||||
|
*/
|
||||||
|
public TelegramLongPollingCommandBot(BotOptions options) {
|
||||||
|
super(options);
|
||||||
this.commandRegistry = new CommandRegistry();
|
this.commandRegistry = new CommandRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +40,7 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
|||||||
public final void onUpdateReceived(Update update) {
|
public final void onUpdateReceived(Update update) {
|
||||||
if (update.hasMessage()) {
|
if (update.hasMessage()) {
|
||||||
Message message = update.getMessage();
|
Message message = update.getMessage();
|
||||||
if (message.isCommand()) {
|
if (message.isCommand() && !filter(message)) {
|
||||||
if (commandRegistry.executeCommand(this, message)) {
|
if (commandRegistry.executeCommand(this, message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -41,6 +49,23 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
|||||||
processNonCommandUpdate(update);
|
processNonCommandUpdate(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function message filter.
|
||||||
|
* Override this function in your bot implementation to filter messages with commands
|
||||||
|
*
|
||||||
|
* For example, if you want to prevent commands execution incoming from group chat:
|
||||||
|
* #
|
||||||
|
* # return !message.getChat().isGroupChat();
|
||||||
|
* #
|
||||||
|
*
|
||||||
|
* @param message Received message
|
||||||
|
* @return true if the message must be ignored by the command bot and treated as a non command message,
|
||||||
|
* false otherwise
|
||||||
|
*/
|
||||||
|
protected boolean filter(Message message) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean register(BotCommand botCommand) {
|
public final boolean register(BotCommand botCommand) {
|
||||||
return commandRegistry.register(botCommand);
|
return commandRegistry.register(botCommand);
|
||||||
@ -71,6 +96,11 @@ public abstract class TelegramLongPollingCommandBot extends TelegramLongPollingB
|
|||||||
commandRegistry.registerDefaultAction(defaultConsumer);
|
commandRegistry.registerDefaultAction(defaultConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final BotCommand getRegisteredCommand(String commandIdentifier) {
|
||||||
|
return commandRegistry.getRegisteredCommand(commandIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process all updates, that are not commands.
|
* Process all updates, that are not commands.
|
||||||
* @warning Commands that have valid syntax but are not registered on this bot,
|
* @warning Commands that have valid syntax but are not registered on this bot,
|
||||||
|
@ -7,4 +7,11 @@ package org.telegram.telegrambots.bots;
|
|||||||
* @date 14 of January of 2016
|
* @date 14 of January of 2016
|
||||||
*/
|
*/
|
||||||
public abstract class TelegramWebhookBot extends AbsSender implements ITelegramWebhookBot {
|
public abstract class TelegramWebhookBot extends AbsSender implements ITelegramWebhookBot {
|
||||||
|
public TelegramWebhookBot() {
|
||||||
|
this(new BotOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
public TelegramWebhookBot(BotOptions options) {
|
||||||
|
super(options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,11 @@ public final class CommandRegistry implements ICommandRegistry {
|
|||||||
return commandRegistryMap.values();
|
return commandRegistryMap.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final BotCommand getRegisteredCommand(String commandIdentifier) {
|
||||||
|
return commandRegistryMap.get(commandIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a command action if the command is registered.
|
* Executes a command action if the command is registered.
|
||||||
*
|
*
|
||||||
|
@ -62,4 +62,10 @@ public interface ICommandRegistry {
|
|||||||
*/
|
*/
|
||||||
Collection<BotCommand> getRegisteredCommands();
|
Collection<BotCommand> getRegisteredCommands();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get registered command
|
||||||
|
*
|
||||||
|
* @return registered command if exists or null if not
|
||||||
|
*/
|
||||||
|
BotCommand getRegisteredCommand(String commandIdentifier);
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package org.telegram.telegrambots.updatesreceivers;
|
package org.telegram.telegrambots.updatesreceivers;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
@ -18,6 +19,7 @@ import org.telegram.telegrambots.Constants;
|
|||||||
import org.telegram.telegrambots.TelegramApiException;
|
import org.telegram.telegrambots.TelegramApiException;
|
||||||
import org.telegram.telegrambots.api.methods.updates.GetUpdates;
|
import org.telegram.telegrambots.api.methods.updates.GetUpdates;
|
||||||
import org.telegram.telegrambots.api.objects.Update;
|
import org.telegram.telegrambots.api.objects.Update;
|
||||||
|
import org.telegram.telegrambots.bots.BotOptions;
|
||||||
import org.telegram.telegrambots.bots.ITelegramLongPollingBot;
|
import org.telegram.telegrambots.bots.ITelegramLongPollingBot;
|
||||||
import org.telegram.telegrambots.logging.BotLogger;
|
import org.telegram.telegrambots.logging.BotLogger;
|
||||||
|
|
||||||
@ -47,8 +49,19 @@ public class BotSession {
|
|||||||
private volatile CloseableHttpClient httpclient;
|
private volatile CloseableHttpClient httpclient;
|
||||||
private volatile RequestConfig requestConfig;
|
private volatile RequestConfig requestConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor present just to keep backward compatibility will be removed in next mayor release.
|
||||||
|
*
|
||||||
|
* @deprecated @deprecated use {@link #BotSession(String, ITelegramLongPollingBot, BotOptions)}
|
||||||
|
* @param token Token of the bot
|
||||||
|
* @param callback Callback for incomming updates
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public BotSession(String token, ITelegramLongPollingBot callback) {
|
public BotSession(String token, ITelegramLongPollingBot callback) {
|
||||||
|
this(token, callback, new BotOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BotSession(String token, ITelegramLongPollingBot callback, BotOptions options) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
|
||||||
@ -58,8 +71,12 @@ public class BotSession {
|
|||||||
.setMaxConnTotal(100)
|
.setMaxConnTotal(100)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
|
RequestConfig.Builder configBuilder = RequestConfig.copy(RequestConfig.custom().build());
|
||||||
.setSocketTimeout(SOCKET_TIMEOUT)
|
if (options.hasProxy()) {
|
||||||
|
configBuilder.setProxy(new HttpHost(options.getProxyHost(), options.getProxyPort()));
|
||||||
|
}
|
||||||
|
|
||||||
|
requestConfig = configBuilder.setSocketTimeout(SOCKET_TIMEOUT)
|
||||||
.setConnectTimeout(SOCKET_TIMEOUT)
|
.setConnectTimeout(SOCKET_TIMEOUT)
|
||||||
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
|
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user