Skip to content

Commit 508bc2c

Browse files
committed
Api Version 9.0
1 parent 26dcc36 commit 508bc2c

File tree

126 files changed

+5565
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+5565
-111
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>org.telegram</groupId>
88
<artifactId>Bots</artifactId>
99
<packaging>pom</packaging>
10-
<version>8.3.0</version>
10+
<version>9.0.0</version>
1111

1212
<modules>
1313
<module>telegrambots-meta</module>

telegrambots-abilities/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.telegram</groupId>
99
<artifactId>Bots</artifactId>
10-
<version>8.3.0</version>
10+
<version>9.0.0</version>
1111
</parent>
1212

1313
<artifactId>telegrambots-abilities</artifactId>
@@ -104,12 +104,12 @@
104104
<dependency>
105105
<groupId>org.telegram</groupId>
106106
<artifactId>telegrambots-webhook</artifactId>
107-
<version>8.3.0</version>
107+
<version>9.0.0</version>
108108
</dependency>
109109
<dependency>
110110
<groupId>org.telegram</groupId>
111111
<artifactId>telegrambots-longpolling</artifactId>
112-
<version>8.3.0</version>
112+
<version>9.0.0</version>
113113
</dependency>
114114

115115
<dependency>

telegrambots-client-jetty-adapter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.telegram</groupId>
99
<artifactId>Bots</artifactId>
10-
<version>8.3.0</version>
10+
<version>9.0.0</version>
1111
</parent>
1212

1313
<name>Telegram Bots Client Jetty HttpClient adapter</name>

telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.telegram.telegrambots.client;
22

33
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod;
4+
import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto;
45
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto;
56
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
67
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
@@ -96,6 +97,15 @@ public Message execute(SendSticker sendSticker) throws TelegramApiException {
9697
}
9798
}
9899

100+
@Override
101+
public Boolean execute(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) throws TelegramApiException {
102+
try {
103+
return executeAsync(setBusinessAccountProfilePhoto).get();
104+
} catch (Exception e) {
105+
throw mapException(e, setBusinessAccountProfilePhoto.getMethod());
106+
}
107+
}
108+
99109
@Override
100110
public Message execute(SendAudio sendAudio) throws TelegramApiException {
101111
try {

telegrambots-client-jetty-adapter/src/main/java/org/telegram/telegrambots/client/jetty/JettyTelegramClient.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.telegram.telegrambots.meta.TelegramUrl;
1515
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod;
1616
import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod;
17+
import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto;
1718
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto;
1819
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
1920
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
@@ -42,6 +43,8 @@
4243
import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMedia;
4344
import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMediaVideo;
4445
import org.telegram.telegrambots.meta.api.objects.message.Message;
46+
import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoAnimated;
47+
import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic;
4548
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
4649
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
4750

@@ -141,6 +144,40 @@ public CompletableFuture<Message> executeAsync(SendPhoto sendPhoto) {
141144
.addJsonPart(SendPhoto.CAPTION_ENTITIES_FIELD, sendPhoto.getCaptionEntities()));
142145
}
143146

147+
@Override
148+
public CompletableFuture<Boolean> executeAsync(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) {
149+
try {
150+
assertParamNotNull(setBusinessAccountProfilePhoto, "method");
151+
152+
setBusinessAccountProfilePhoto.validate();
153+
154+
URI url = buildUrl(setBusinessAccountProfilePhoto.getMethod());
155+
156+
JettyMultipartBuilder builder = new JettyMultipartBuilder(objectMapper);
157+
158+
builder.addPart(SetBusinessAccountProfilePhoto.BUSINESS_CONNECTION_ID_FIELD, setBusinessAccountProfilePhoto.getBusinessConnectionId())
159+
.addPart(SetBusinessAccountProfilePhoto.IS_PUBLIC_FIELD, setBusinessAccountProfilePhoto.getIsPublic());
160+
161+
if (InputProfilePhotoStatic.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) {
162+
InputProfilePhotoStatic photo = (InputProfilePhotoStatic) setBusinessAccountProfilePhoto.getPhoto();
163+
builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo)
164+
.addInputFile(InputProfilePhotoStatic.PHOTO_FIELD, photo.getPhoto(), false);
165+
} else if (InputProfilePhotoAnimated.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) {
166+
InputProfilePhotoAnimated photo = (InputProfilePhotoAnimated) setBusinessAccountProfilePhoto.getPhoto();
167+
builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo)
168+
.addInputFile(InputProfilePhotoAnimated.ANIMATION_FIELD, photo.getAnimation(), false);
169+
}
170+
171+
Request httpPost = client.POST(url).body(builder.build());
172+
173+
return sendRequest(setBusinessAccountProfilePhoto, httpPost);
174+
} catch (TelegramApiException e) {
175+
return CompletableFuture.failedFuture(e);
176+
} catch (IOException e) {
177+
return CompletableFuture.failedFuture(new TelegramApiException("Unable to execute " + setBusinessAccountProfilePhoto.getMethod(), e));
178+
}
179+
}
180+
144181
@Override
145182
public CompletableFuture<Boolean> executeAsync(SetWebhook setWebhook) {
146183
try {

telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
import org.telegram.telegrambots.client.jetty.JettyTelegramClient;
1515
import org.telegram.telegrambots.meta.TelegramUrl;
1616
import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod;
17-
import org.telegram.telegrambots.meta.api.methods.send.*;
17+
import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto;
18+
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
19+
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
20+
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
21+
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
22+
import org.telegram.telegrambots.meta.api.methods.send.SendPhoto;
23+
import org.telegram.telegrambots.meta.api.methods.send.SendSticker;
24+
import org.telegram.telegrambots.meta.api.methods.send.SendVideo;
25+
import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote;
26+
import org.telegram.telegrambots.meta.api.methods.send.SendVoice;
1827
import org.telegram.telegrambots.meta.api.objects.InputFile;
1928
import org.telegram.telegrambots.meta.api.objects.message.Message;
29+
import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic;
2030
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
2131
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
2232

@@ -25,7 +35,10 @@
2535
import java.io.Serializable;
2636
import java.nio.charset.StandardCharsets;
2737

28-
import static org.junit.jupiter.api.Assertions.*;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
import static org.junit.jupiter.api.Assertions.assertFalse;
40+
import static org.junit.jupiter.api.Assertions.assertNotNull;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
2942

3043
public class TestTelegramClientIntegration {
3144
private MockWebServer webServer;
@@ -261,6 +274,43 @@ void testSendAnimationException() {
261274
assertEquals(404, exception.getErrorCode());
262275
}
263276

277+
@Test
278+
void testSetBusinessAccountProfilePhoto() throws TelegramApiException {
279+
InputFile inputFile = new InputFile(getTestFile());
280+
InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder()
281+
.photo(inputFile)
282+
.build();
283+
284+
SetBusinessAccountProfilePhoto method = SetBusinessAccountProfilePhoto.builder()
285+
.businessConnectionId("test-connection-id")
286+
.photo(profilePhoto)
287+
.isPublic(true)
288+
.build();
289+
290+
mockMethod(method, Boolean.TRUE);
291+
292+
assertTrue(client.execute(method));
293+
}
294+
295+
@Test
296+
void testSetBusinessAccountProfilePhotoException() {
297+
InputFile inputFile = new InputFile(getTestFile());
298+
InputProfilePhotoStatic profilePhoto = InputProfilePhotoStatic.builder()
299+
.photo(inputFile)
300+
.build();
301+
302+
SetBusinessAccountProfilePhoto method = SetBusinessAccountProfilePhoto.builder()
303+
.businessConnectionId("test-connection-id")
304+
.photo(profilePhoto)
305+
.isPublic(true)
306+
.build();
307+
308+
mockErrorMethod(method);
309+
310+
TelegramApiRequestException exception = Assertions.assertThrows(TelegramApiRequestException.class, () -> client.execute(method));
311+
assertEquals(404, exception.getErrorCode());
312+
}
313+
264314
@NotNull
265315
private File getTestFile() {
266316
ClassLoader classLoader = getClass().getClassLoader();

telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramMultipartBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.junit.jupiter.api.Test;
88
import org.telegram.telegrambots.client.jetty.JettyMultipartBuilder;
99
import org.telegram.telegrambots.meta.api.objects.InputFile;
10-
import org.telegram.telegrambots.meta.api.objects.Location;
10+
import org.telegram.telegrambots.meta.api.objects.location.Location;
1111
import org.telegram.telegrambots.meta.api.objects.media.InputMediaDocument;
1212
import org.telegram.telegrambots.meta.api.objects.stickers.InputSticker;
1313

@@ -18,7 +18,9 @@
1818
import java.util.ArrayDeque;
1919
import java.util.List;
2020

21-
import static org.junit.jupiter.api.Assertions.*;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.fail;
2224

2325
public class TestTelegramMultipartBuilder {
2426
private JettyMultipartBuilder multipartBuilder;

telegrambots-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.telegram</groupId>
99
<artifactId>Bots</artifactId>
10-
<version>8.3.0</version>
10+
<version>9.0.0</version>
1111
</parent>
1212

1313
<name>Telegram Bots Client</name>

telegrambots-client/src/main/java/org/telegram/telegrambots/client/AbstractTelegramClient.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
package org.telegram.telegrambots.client;
22

33
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod;
4+
import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto;
45
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto;
5-
import org.telegram.telegrambots.meta.api.methods.send.*;
6-
import org.telegram.telegrambots.meta.api.methods.stickers.*;
6+
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
7+
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
8+
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
9+
import org.telegram.telegrambots.meta.api.methods.send.SendMediaGroup;
10+
import org.telegram.telegrambots.meta.api.methods.send.SendPaidMedia;
11+
import org.telegram.telegrambots.meta.api.methods.send.SendPhoto;
12+
import org.telegram.telegrambots.meta.api.methods.send.SendSticker;
13+
import org.telegram.telegrambots.meta.api.methods.send.SendVideo;
14+
import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote;
15+
import org.telegram.telegrambots.meta.api.methods.send.SendVoice;
16+
import org.telegram.telegrambots.meta.api.methods.stickers.AddStickerToSet;
17+
import org.telegram.telegrambots.meta.api.methods.stickers.CreateNewStickerSet;
18+
import org.telegram.telegrambots.meta.api.methods.stickers.ReplaceStickerInSet;
19+
import org.telegram.telegrambots.meta.api.methods.stickers.SetStickerSetThumbnail;
20+
import org.telegram.telegrambots.meta.api.methods.stickers.UploadStickerFile;
721
import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
822
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageMedia;
923
import org.telegram.telegrambots.meta.api.objects.File;
@@ -83,6 +97,15 @@ public Message execute(SendSticker sendSticker) throws TelegramApiException {
8397
}
8498
}
8599

100+
@Override
101+
public Boolean execute(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) throws TelegramApiException {
102+
try {
103+
return executeAsync(setBusinessAccountProfilePhoto).get();
104+
} catch (Exception e) {
105+
throw mapException(e, setBusinessAccountProfilePhoto.getMethod());
106+
}
107+
}
108+
86109
@Override
87110
public Message execute(SendAudio sendAudio) throws TelegramApiException {
88111
try {

telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.telegram.telegrambots.meta.TelegramUrl;
1616
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod;
1717
import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod;
18+
import org.telegram.telegrambots.meta.api.methods.business.SetBusinessAccountProfilePhoto;
1819
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto;
1920
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
2021
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
@@ -43,6 +44,8 @@
4344
import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMedia;
4445
import org.telegram.telegrambots.meta.api.objects.media.paid.InputPaidMediaVideo;
4546
import org.telegram.telegrambots.meta.api.objects.message.Message;
47+
import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoAnimated;
48+
import org.telegram.telegrambots.meta.api.objects.photo.input.InputProfilePhotoStatic;
4649
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
4750

4851
import java.io.IOException;
@@ -108,6 +111,38 @@ public <T extends Serializable, Method extends BotApiMethod<T>> CompletableFutur
108111
}
109112
}
110113

114+
@Override
115+
public CompletableFuture<Boolean> executeAsync(SetBusinessAccountProfilePhoto setBusinessAccountProfilePhoto) {
116+
try {
117+
assertParamNotNull(setBusinessAccountProfilePhoto, "setBusinessAccountProfilePhoto");
118+
setBusinessAccountProfilePhoto.validate();
119+
120+
HttpUrl url = buildUrl(setBusinessAccountProfilePhoto.getMethod());
121+
122+
TelegramMultipartBuilder builder = new TelegramMultipartBuilder(objectMapper);
123+
124+
builder.addPart(SetBusinessAccountProfilePhoto.BUSINESS_CONNECTION_ID_FIELD, setBusinessAccountProfilePhoto.getBusinessConnectionId())
125+
.addPart(SetBusinessAccountProfilePhoto.IS_PUBLIC_FIELD, setBusinessAccountProfilePhoto.getIsPublic());
126+
127+
if (InputProfilePhotoStatic.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) {
128+
InputProfilePhotoStatic photo = (InputProfilePhotoStatic) setBusinessAccountProfilePhoto.getPhoto();
129+
builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo)
130+
.addInputFile(InputProfilePhotoStatic.PHOTO_FIELD, photo.getPhoto(), false);
131+
} else if (InputProfilePhotoAnimated.TYPE.equals(setBusinessAccountProfilePhoto.getPhoto().getType())) {
132+
InputProfilePhotoAnimated photo = (InputProfilePhotoAnimated) setBusinessAccountProfilePhoto.getPhoto();
133+
builder.addJsonPart(SetBusinessAccountProfilePhoto.PHOTO_FIELD, photo)
134+
.addInputFile(InputProfilePhotoAnimated.ANIMATION_FIELD, photo.getAnimation(), false);
135+
}
136+
137+
Request httpPost = new Request.Builder().url(url).post(builder.build()).build();
138+
return sendRequest(setBusinessAccountProfilePhoto, httpPost);
139+
} catch (TelegramApiException e) {
140+
return CompletableFuture.failedFuture(e);
141+
} catch (IOException e) {
142+
return CompletableFuture.failedFuture(new TelegramApiException("Unable to execute " + setBusinessAccountProfilePhoto.getMethod(), e));
143+
}
144+
}
145+
111146
@Override
112147
public CompletableFuture<Message> executeAsync(SendDocument sendDocument) {
113148
return executeMediaMethod(sendDocument, builder -> {

0 commit comments

Comments
 (0)