Skip to content

Commit 56028c7

Browse files
authored
Merge branch 'master' into api_5.4
2 parents 492f1ce + ade59a3 commit 56028c7

33 files changed

+547
-41
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Java Telegram Bot API
22
[![Maven Central](https://img.shields.io/maven-central/v/com.github.pengrad/java-telegram-bot-api.svg)](https://search.maven.org/artifact/com.github.pengrad/java-telegram-bot-api)
3-
[![Build Status](https://travis-ci.org/pengrad/java-telegram-bot-api.svg?branch=master)](https://travis-ci.org/pengrad/java-telegram-bot-api)
3+
[![Build Status](https://travis-ci.com/pengrad/java-telegram-bot-api.svg?branch=master)](https://app.travis-ci.com/github/pengrad/java-telegram-bot-api)
44
[![codecov](https://codecov.io/gh/pengrad/java-telegram-bot-api/branch/master/graph/badge.svg)](https://codecov.io/gh/pengrad/java-telegram-bot-api)
55

66
Java library for interacting with [Telegram Bot API](https://core.telegram.org/bots/api)
7-
- Full support of all Bot API 5.1 methods
7+
- Full support of all Bot API 5.3 methods
88
- Telegram [Passport](https://core.telegram.org/passport) and Decryption API
99
- Bot [Payments](https://core.telegram.org/bots/payments)
1010
- [Gaming Platform](https://telegram.org/blog/games)
@@ -13,14 +13,14 @@ Java library for interacting with [Telegram Bot API](https://core.telegram.org/b
1313

1414
Gradle:
1515
```groovy
16-
implementation 'com.github.pengrad:java-telegram-bot-api:5.1.0'
16+
implementation 'com.github.pengrad:java-telegram-bot-api:5.3.0'
1717
```
1818
Maven:
1919
```xml
2020
<dependency>
2121
<groupId>com.github.pengrad</groupId>
2222
<artifactId>java-telegram-bot-api</artifactId>
23-
<version>5.1.0</version>
23+
<version>5.3.0</version>
2424
</dependency>
2525
```
2626
[JAR with all dependencies on release page](https://github.com/pengrad/java-telegram-bot-api/releases)

README_RU.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Java Telegram Bot Api
22
[![Maven Central](https://img.shields.io/maven-central/v/com.github.pengrad/java-telegram-bot-api.svg)](https://search.maven.org/artifact/com.github.pengrad/java-telegram-bot-api)
3-
[![Build Status](https://travis-ci.org/pengrad/java-telegram-bot-api.svg?branch=master)](https://travis-ci.org/pengrad/java-telegram-bot-api)
3+
[![Build Status](https://travis-ci.com/pengrad/java-telegram-bot-api.svg?branch=master)](https://app.travis-ci.com/github/pengrad/java-telegram-bot-api)
44
[![codecov](https://codecov.io/gh/pengrad/java-telegram-bot-api/branch/master/graph/badge.svg)](https://codecov.io/gh/pengrad/java-telegram-bot-api)
55

66
Java библиотека, созданная для работы с [Telegram Bot API](https://core.telegram.org/bots/api)
7-
- Полная поддержка всех методов BOT API 5.1
7+
- Полная поддержка всех методов BOT API 5.3
88
- Поддержка Telegram [паспорта](https://core.telegram.org/passport) и дешифровки (Decryption API);
99
- Поддержка [платежей](https://core.telegram.org/bots/payments);
1010
- [Игровая платформа](https://telegram.org/blog/games).
@@ -13,14 +13,14 @@ Java библиотека, созданная для работы с [Telegram B
1313

1414
Gradle:
1515
```groovy
16-
implementation 'com.github.pengrad:java-telegram-bot-api:5.1.0'
16+
implementation 'com.github.pengrad:java-telegram-bot-api:5.3.0'
1717
```
1818
Maven:
1919
```xml
2020
<dependency>
2121
<groupId>com.github.pengrad</groupId>
2222
<artifactId>java-telegram-bot-api</artifactId>
23-
<version>5.1.0</version>
23+
<version>5.3.0</version>
2424
</dependency>
2525
```
2626
Также JAR со всеми зависимостями можно найти [в релизах](https://github.com/pengrad/java-telegram-bot-api/releases).

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=com.github.pengrad
2-
VERSION_NAME=5.1.0
2+
VERSION_NAME=5.3.0
33

44
POM_DESCRIPTION=Java API for Telegram Bot API
55
POM_URL=https://github.com/pengrad/java-telegram-bot-api/

library/src/main/java/com/pengrad/telegrambot/TelegramBot.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
public class TelegramBot {
2626

27+
private final String token;
2728
private final TelegramBotClient api;
2829
private final FileApi fileApi;
2930
private final UpdatesHandler updatesHandler;
@@ -33,6 +34,7 @@ public TelegramBot(String botToken) {
3334
}
3435

3536
TelegramBot(Builder builder) {
37+
this.token = builder.botToken;
3638
this.api = builder.api;
3739
this.fileApi = builder.fileApi;
3840
this.updatesHandler = builder.updatesHandler;
@@ -46,6 +48,10 @@ public <T extends BaseRequest<T, R>, R extends BaseResponse> void execute(T requ
4648
api.send(request, callback);
4749
}
4850

51+
public String getToken() {
52+
return token;
53+
}
54+
4955
public String getFullFilePath(File file) {
5056
return fileApi.getFullFilePath(file.filePath());
5157
}
@@ -78,6 +84,10 @@ public void removeGetUpdatesListener() {
7884
updatesHandler.stop();
7985
}
8086

87+
public void shutdown() {
88+
api.shutdown();
89+
}
90+
8191
public static final class Builder {
8292

8393
static final String API_URL = "https://api.telegram.org/bot";

library/src/main/java/com/pengrad/telegrambot/impl/TelegramBotClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public <T extends BaseRequest<T, R>, R extends BaseResponse> R send(final BaseRe
7575
}
7676
}
7777

78+
public void shutdown() {
79+
client.dispatcher().executorService().shutdown();
80+
}
81+
7882
private OkHttpClient getOkHttpClient(BaseRequest<?, ?> request) {
7983
int timeoutMillis = request.getTimeoutSeconds() * 1000;
8084

library/src/main/java/com/pengrad/telegrambot/impl/UpdatesHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.pengrad.telegrambot.response.GetUpdatesResponse;
77

88
import java.io.IOException;
9+
import java.util.Collections;
910
import java.util.List;
1011
import java.util.logging.Level;
1112
import java.util.logging.Logger;
@@ -68,6 +69,7 @@ public void onResponse(GetUpdates request, GetUpdatesResponse response) {
6869
}
6970

7071
List<Update> updates = response.updates();
72+
if (updates == null) updates = Collections.emptyList();
7173
int lastConfirmedUpdate = listener.process(updates);
7274

7375
if (lastConfirmedUpdate != CONFIRMED_UPDATES_NONE) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import com.pengrad.telegrambot.model.botcommandscope.BotCommandScope;
4+
import com.pengrad.telegrambot.request.BaseRequest;
5+
import com.pengrad.telegrambot.response.BaseResponse;
6+
7+
public class DeleteMyCommands extends BaseRequest<DeleteMyCommands, BaseResponse> {
8+
9+
public DeleteMyCommands() {
10+
super(BaseResponse.class);
11+
}
12+
13+
/**
14+
*
15+
* @param scope An object that extends the BotCommandScope class. For example: new BotCommandScopeAllPrivateChats()
16+
* @return
17+
*/
18+
public DeleteMyCommands scope(BotCommandScope scope) {
19+
add("scope", scope);
20+
return this;
21+
}
22+
23+
/**
24+
*
25+
* @param languageCode A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
26+
* @return
27+
*/
28+
public DeleteMyCommands languageCode(String languageCode) {
29+
add("language_code", languageCode);
30+
return this;
31+
}
32+
}

library/src/main/java/com/pengrad/telegrambot/model/InlineQuery.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class InlineQuery implements Serializable {
1414
private Location location;
1515
private String query;
1616
private String offset;
17+
private String chat_type;
1718

1819
public String id() {
1920
return id;
@@ -35,6 +36,10 @@ public String offset() {
3536
return offset;
3637
}
3738

39+
public String chatType() {
40+
return chat_type;
41+
}
42+
3843
@Override
3944
public boolean equals(Object o) {
4045
if (this == o) return true;
@@ -46,8 +51,9 @@ public boolean equals(Object o) {
4651
if (from != null ? !from.equals(that.from) : that.from != null) return false;
4752
if (location != null ? !location.equals(that.location) : that.location != null) return false;
4853
if (query != null ? !query.equals(that.query) : that.query != null) return false;
49-
return offset != null ? offset.equals(that.offset) : that.offset == null;
54+
if (chat_type != null ? !chat_type.equals(that.chat_type) : that.chat_type != null) return false;
5055

56+
return offset != null ? offset.equals(that.offset) : that.offset == null;
5157
}
5258

5359
@Override
@@ -63,6 +69,7 @@ public String toString() {
6369
", location=" + location +
6470
", query='" + query + '\'' +
6571
", offset='" + offset + '\'' +
72+
", chat_type='" + chat_type + '\'' +
6673
'}';
6774
}
6875
}

library/src/main/java/com/pengrad/telegrambot/model/Message.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class Message implements Serializable {
6868
private VoiceChatStarted voice_chat_started;
6969
private VoiceChatEnded voice_chat_ended;
7070
private VoiceChatParticipantsInvited voice_chat_participants_invited;
71+
private VoiceChatScheduled voice_chat_scheduled;
7172
private InlineKeyboardMarkup reply_markup;
7273

7374
public Integer messageId() {
@@ -286,6 +287,10 @@ public VoiceChatParticipantsInvited voiceChatParticipantsInvited() {
286287
return voice_chat_participants_invited;
287288
}
288289

290+
public VoiceChatScheduled voiceChatScheduled() {
291+
return voice_chat_scheduled;
292+
}
293+
289294
public InlineKeyboardMarkup replyMarkup() {
290295
return reply_markup;
291296
}
@@ -349,6 +354,7 @@ public boolean equals(Object o) {
349354
Objects.equals(voice_chat_started, message.voice_chat_started) &&
350355
Objects.equals(voice_chat_ended, message.voice_chat_ended) &&
351356
Objects.equals(voice_chat_participants_invited, message.voice_chat_participants_invited) &&
357+
Objects.equals(voice_chat_scheduled, message.voice_chat_scheduled) &&
352358
Objects.equals(reply_markup, message.reply_markup);
353359
}
354360

@@ -414,6 +420,7 @@ public String toString() {
414420
", voice_chat_started=" + voice_chat_started +
415421
", voice_chat_ended=" + voice_chat_ended +
416422
", voice_chat_participants_invited=" + voice_chat_participants_invited +
423+
", voice_chat_scheduled=" + voice_chat_scheduled +
417424
", reply_markup=" + reply_markup +
418425
'}';
419426
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import java.io.Serializable;
4+
import java.util.Objects;
5+
6+
public class VoiceChatScheduled implements Serializable {
7+
8+
private final static long serialVersionUID = 0L;
9+
10+
private Integer start_date;
11+
12+
public Integer startDate() {
13+
return start_date;
14+
}
15+
16+
@Override
17+
public boolean equals(Object o) {
18+
if (this == o) return true;
19+
if (o == null || getClass() != o.getClass()) return false;
20+
VoiceChatScheduled that = (VoiceChatScheduled) o;
21+
return Objects.equals(start_date, that.start_date);
22+
}
23+
24+
@Override
25+
public int hashCode() {
26+
return Objects.hash(start_date);
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return "VoiceChatScheduled{" +
32+
"start_date=" + start_date +
33+
'}';
34+
}
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
import java.io.Serializable;
4+
5+
public abstract class BotCommandScope implements Serializable {
6+
private final static long serialVersionUID = 0L;
7+
8+
protected String type = "default";
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
public class BotCommandScopeAllChatAdministrators extends BotCommandScope {
4+
5+
public BotCommandScopeAllChatAdministrators() {
6+
this.type = "all_chat_administrators";
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
public class BotCommandScopeAllGroupChats extends BotCommandScope {
4+
5+
public BotCommandScopeAllGroupChats() {
6+
this.type = "all_group_chats";
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
public class BotCommandScopeAllPrivateChats extends BotCommandScope {
4+
5+
public BotCommandScopeAllPrivateChats() {
6+
this.type = "all_private_chats";
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
public class BotCommandScopeDefault extends BotCommandScope {
4+
5+
public BotCommandScopeDefault() {
6+
this.type = "default";
7+
}
8+
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
public class BotCommandsScopeChat extends BotCommandScope {
4+
5+
private Object chat_id;
6+
7+
/**
8+
*
9+
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
10+
*/
11+
public BotCommandsScopeChat(Object chatId) {
12+
this.type = "chat";
13+
this.chat_id = chatId;
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
public class BotCommandsScopeChatAdministrators extends BotCommandScope {
4+
5+
private Object chat_id;
6+
7+
/**
8+
*
9+
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
10+
*/
11+
public BotCommandsScopeChatAdministrators(Object chatId) {
12+
this.type = "chat_administrators";
13+
this.chat_id = chatId;
14+
}
15+
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.pengrad.telegrambot.model.botcommandscope;
2+
3+
public class BotCommandsScopeChatMember extends BotCommandScope {
4+
5+
private Object chat_id;
6+
private long user_id;
7+
8+
/**
9+
*
10+
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
11+
* @param userId Unique identifier of the target user
12+
*/
13+
public BotCommandsScopeChatMember(Object chatId, long userId) {
14+
this.type = "chat_member";
15+
this.chat_id = chatId;
16+
this.user_id = userId;
17+
}
18+
19+
}

0 commit comments

Comments
 (0)