Skip to content

Commit 314ae46

Browse files
committed
All send* methods take chat_id as Object type, to support Long for chats, String for channels or Integer for users and groups
1 parent c0b0c2d commit 314ae46

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,91 +36,91 @@ public GetMeResponse getMe() {
3636
return botApi.getMe();
3737
}
3838

39-
public SendResponse sendMessage(Long chatId, String text, ParseMode parse_mode, Boolean disableWebPagePreview, Integer replyToMessageId, Keyboard replyMarkup) {
39+
public SendResponse sendMessage(Object chatId, String text, ParseMode parse_mode, Boolean disableWebPagePreview, Integer replyToMessageId, Keyboard replyMarkup) {
4040
return botApi.sendMessage(String.valueOf(chatId), text, parse_mode, disableWebPagePreview, replyToMessageId, replyMarkup);
4141
}
4242

43-
public SendResponse forwardMessage(Long chatId, Long fromChatId, Integer messageId) {
43+
public SendResponse forwardMessage(Object chatId, Object fromChatId, Integer messageId) {
4444
return botApi.forwardMessage(String.valueOf(chatId), String.valueOf(fromChatId), messageId);
4545
}
4646

47-
public SendResponse sendPhoto(Long chatId, String photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
47+
public SendResponse sendPhoto(Object chatId, String photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
4848
return botApi.sendPhoto(String.valueOf(chatId), photo, caption, replyToMessageId, replyMarkup);
4949
}
5050

51-
public SendResponse sendPhoto(Long chatId, InputFile photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
51+
public SendResponse sendPhoto(Object chatId, InputFile photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
5252
return botApi.sendPhoto(String.valueOf(chatId), photo, caption, replyToMessageId, replyMarkup);
5353
}
5454

55-
public SendResponse sendPhoto(Long chatId, InputFileBytes photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
55+
public SendResponse sendPhoto(Object chatId, InputFileBytes photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
5656
return botApi.sendPhoto(String.valueOf(chatId), photo, caption, replyToMessageId, replyMarkup);
5757
}
5858

59-
public SendResponse sendAudio(Long chatId, String audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
59+
public SendResponse sendAudio(Object chatId, String audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
6060
return botApi.sendAudio(String.valueOf(chatId), audio, duration, performer, title, replyToMessageId, replyMarkup);
6161
}
6262

63-
public SendResponse sendAudio(Long chatId, InputFile audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
63+
public SendResponse sendAudio(Object chatId, InputFile audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
6464
return botApi.sendAudio(String.valueOf(chatId), audio, duration, performer, title, replyToMessageId, replyMarkup);
6565
}
6666

67-
public SendResponse sendAudio(Long chatId, InputFileBytes audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
67+
public SendResponse sendAudio(Object chatId, InputFileBytes audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
6868
return botApi.sendAudio(String.valueOf(chatId), audio, duration, performer, title, replyToMessageId, replyMarkup);
6969
}
7070

71-
public SendResponse sendDocument(Long chatId, String document, Integer replyToMessageId, Keyboard replyMarkup) {
71+
public SendResponse sendDocument(Object chatId, String document, Integer replyToMessageId, Keyboard replyMarkup) {
7272
return botApi.sendDocument(String.valueOf(chatId), document, replyToMessageId, replyMarkup);
7373
}
7474

75-
public SendResponse sendDocument(Long chatId, InputFile document, Integer replyToMessageId, Keyboard replyMarkup) {
75+
public SendResponse sendDocument(Object chatId, InputFile document, Integer replyToMessageId, Keyboard replyMarkup) {
7676
return botApi.sendDocument(String.valueOf(chatId), document, replyToMessageId, replyMarkup);
7777
}
7878

79-
public SendResponse sendDocument(Long chatId, InputFileBytes document, Integer replyToMessageId, Keyboard replyMarkup) {
79+
public SendResponse sendDocument(Object chatId, InputFileBytes document, Integer replyToMessageId, Keyboard replyMarkup) {
8080
return botApi.sendDocument(String.valueOf(chatId), document, replyToMessageId, replyMarkup);
8181
}
8282

83-
public SendResponse sendSticker(Long chatId, String sticker, Integer replyToMessageId, Keyboard replyMarkup) {
83+
public SendResponse sendSticker(Object chatId, String sticker, Integer replyToMessageId, Keyboard replyMarkup) {
8484
return botApi.sendSticker(String.valueOf(chatId), sticker, replyToMessageId, replyMarkup);
8585
}
8686

87-
public SendResponse sendSticker(Long chatId, InputFile sticker, Integer replyToMessageId, Keyboard replyMarkup) {
87+
public SendResponse sendSticker(Object chatId, InputFile sticker, Integer replyToMessageId, Keyboard replyMarkup) {
8888
return botApi.sendSticker(String.valueOf(chatId), sticker, replyToMessageId, replyMarkup);
8989
}
9090

91-
public SendResponse sendSticker(Long chatId, InputFileBytes sticker, Integer replyToMessageId, Keyboard replyMarkup) {
91+
public SendResponse sendSticker(Object chatId, InputFileBytes sticker, Integer replyToMessageId, Keyboard replyMarkup) {
9292
return botApi.sendSticker(String.valueOf(chatId), sticker, replyToMessageId, replyMarkup);
9393
}
9494

95-
public SendResponse sendVideo(Long chatId, String video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
95+
public SendResponse sendVideo(Object chatId, String video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
9696
return botApi.sendVideo(String.valueOf(chatId), video, duration, caption, replyToMessageId, replyMarkup);
9797
}
9898

99-
public SendResponse sendVideo(Long chatId, InputFile video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
99+
public SendResponse sendVideo(Object chatId, InputFile video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
100100
return botApi.sendVideo(String.valueOf(chatId), video, duration, caption, replyToMessageId, replyMarkup);
101101
}
102102

103-
public SendResponse sendVideo(Long chatId, InputFileBytes video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
103+
public SendResponse sendVideo(Object chatId, InputFileBytes video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
104104
return botApi.sendVideo(String.valueOf(chatId), video, duration, caption, replyToMessageId, replyMarkup);
105105
}
106106

107-
public SendResponse sendVoice(Long chatId, String voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
107+
public SendResponse sendVoice(Object chatId, String voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
108108
return botApi.sendVoice(String.valueOf(chatId), voice, duration, replyToMessageId, replyMarkup);
109109
}
110110

111-
public SendResponse sendVoice(Long chatId, InputFile voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
111+
public SendResponse sendVoice(Object chatId, InputFile voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
112112
return botApi.sendVoice(String.valueOf(chatId), voice, duration, replyToMessageId, replyMarkup);
113113
}
114114

115-
public SendResponse sendVoice(Long chatId, InputFileBytes voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
115+
public SendResponse sendVoice(Object chatId, InputFileBytes voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
116116
return botApi.sendVoice(String.valueOf(chatId), voice, duration, replyToMessageId, replyMarkup);
117117
}
118118

119-
public SendResponse sendLocation(Long chatId, Float latitude, Float longitude, Integer replyToMessageId, Keyboard replyMarkup) {
119+
public SendResponse sendLocation(Object chatId, Float latitude, Float longitude, Integer replyToMessageId, Keyboard replyMarkup) {
120120
return botApi.sendLocation(String.valueOf(chatId), latitude, longitude, replyToMessageId, replyMarkup);
121121
}
122122

123-
public SendChatActionResponse sendChatAction(Long chatId, ChatAction action) {
123+
public SendChatActionResponse sendChatAction(Object chatId, ChatAction action) {
124124
return botApi.sendChatAction(String.valueOf(chatId), action);
125125
}
126126

src/test/java/com/pengrad/telegrambot/TelegramBotTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
public class TelegramBotTest {
2525

2626
TelegramBot bot;
27-
Long chatId;
28-
Integer forwardMessageId;
27+
Integer chatId, forwardMessageId;
28+
String channelName = "@bottest";
29+
Long channelId = -1001002720332L;
2930
String stickerId;
3031
String imagefile = getClass().getClassLoader().getResource("image.png").getFile();
3132
String audioFile = getClass().getClassLoader().getResource("beep.mp3").getFile();
@@ -36,7 +37,7 @@ public TelegramBotTest() throws IOException {
3637
Properties properties = new Properties();
3738
properties.load(new FileInputStream("local.properties"));
3839
bot = TelegramBotAdapter.buildDebug(properties.getProperty("TEST_TOKEN"));
39-
chatId = Long.parseLong(properties.getProperty("CHAT_ID"));
40+
chatId = Integer.parseInt(properties.getProperty("CHAT_ID"));
4041
forwardMessageId = Integer.parseInt(properties.getProperty("FORWARD_MESSAGE"));
4142
stickerId = properties.getProperty("STICKER_FILE_ID");
4243
}
@@ -66,8 +67,11 @@ public void testForwardMessage() throws Exception {
6667
@Test
6768
public void testSendMessage() throws Exception {
6869
SendResponse sendResponse = bot.sendMessage(chatId, "sendMessage _italic_ *markdown*", ParseMode.Markdown, false, forwardMessageId, new ReplyKeyboardMarkup(new String[]{"ok", "test"}).oneTimeKeyboard(true));
69-
Message message = sendResponse.message();
70-
MessageTest.checkTextdMessage(message);
70+
MessageTest.checkTextdMessage(sendResponse.message());
71+
sendResponse = bot.sendMessage(channelName, "to channel _italic_ *markdown*", ParseMode.Markdown, false, null, null);
72+
MessageTest.checkTextdMessage(sendResponse.message());
73+
sendResponse = bot.sendMessage(channelId, "explicit to channel id _italic_ *markdown*", ParseMode.Markdown, false, null, null);
74+
MessageTest.checkTextdMessage(sendResponse.message());
7175
}
7276

7377
@Test
@@ -138,7 +142,7 @@ public void testSendChatAction() throws Exception {
138142

139143
@Test
140144
public void testGetUserProfilePhotos() throws Exception {
141-
GetUserProfilePhotosResponse userProfilePhotosResponse = bot.getUserProfilePhotos(chatId.intValue(), 0, 5);
145+
GetUserProfilePhotosResponse userProfilePhotosResponse = bot.getUserProfilePhotos(chatId, 0, 5);
142146
UserProfilePhotosTest.check(userProfilePhotosResponse.photos());
143147
}
144148

0 commit comments

Comments
 (0)