Skip to content

Commit 3a0d9c8

Browse files
committed
Added the sendVideoNote method, the new field video_note to Message, the fields record_video_note or upload_video_note to sendChatAction
1 parent 7a475d0 commit 3a0d9c8

File tree

7 files changed

+180
-11
lines changed

7 files changed

+180
-11
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ public class Message implements Serializable {
2929
private Sticker sticker;
3030
private Video video;
3131
private Voice voice;
32+
private VideoNote video_note;
33+
private User[] new_chat_members;
3234
private String caption;
3335
private Contact contact;
3436
private Location location;
3537
private Venue venue;
3638
private User new_chat_member;
37-
private User[] new_chat_members;
3839
private User left_chat_member;
3940
private String new_chat_title;
4041
private PhotoSize[] new_chat_photo;
@@ -122,6 +123,14 @@ public Voice voice() {
122123
return voice;
123124
}
124125

126+
public VideoNote videoNote() {
127+
return video_note;
128+
}
129+
130+
public User[] newChatMembers() {
131+
return new_chat_members;
132+
}
133+
125134
public String caption() {
126135
return caption;
127136
}
@@ -146,10 +155,6 @@ public User newChatMember() {
146155
return new_chat_member;
147156
}
148157

149-
public User[] newChatMembers() {
150-
return new_chat_members;
151-
}
152-
153158
public User leftChatMember() {
154159
return left_chat_member;
155160
}
@@ -221,12 +226,15 @@ public boolean equals(Object o) {
221226
if (sticker != null ? !sticker.equals(message.sticker) : message.sticker != null) return false;
222227
if (video != null ? !video.equals(message.video) : message.video != null) return false;
223228
if (voice != null ? !voice.equals(message.voice) : message.voice != null) return false;
229+
if (video_note != null ? !video_note.equals(message.video_note) : message.video_note != null) return false;
230+
// Probably incorrect - comparing Object[] arrays with Arrays.equals
231+
if (!Arrays.equals(new_chat_members, message.new_chat_members)) return false;
224232
if (caption != null ? !caption.equals(message.caption) : message.caption != null) return false;
225233
if (contact != null ? !contact.equals(message.contact) : message.contact != null) return false;
226234
if (location != null ? !location.equals(message.location) : message.location != null) return false;
227235
if (venue != null ? !venue.equals(message.venue) : message.venue != null) return false;
228-
// Probably incorrect - comparing Object[] arrays with Arrays.equals
229-
if (!Arrays.equals(new_chat_members, message.new_chat_members)) return false;
236+
if (new_chat_member != null ? !new_chat_member.equals(message.new_chat_member) : message.new_chat_member != null)
237+
return false;
230238
if (left_chat_member != null ? !left_chat_member.equals(message.left_chat_member) : message.left_chat_member != null)
231239
return false;
232240
if (new_chat_title != null ? !new_chat_title.equals(message.new_chat_title) : message.new_chat_title != null)
@@ -246,7 +254,6 @@ public boolean equals(Object o) {
246254
if (migrate_from_chat_id != null ? !migrate_from_chat_id.equals(message.migrate_from_chat_id) : message.migrate_from_chat_id != null)
247255
return false;
248256
return pinned_message != null ? pinned_message.equals(message.pinned_message) : message.pinned_message == null;
249-
250257
}
251258

252259
@Override
@@ -276,11 +283,13 @@ public String toString() {
276283
", sticker=" + sticker +
277284
", video=" + video +
278285
", voice=" + voice +
286+
", video_note=" + video_note +
287+
", new_chat_members=" + Arrays.toString(new_chat_members) +
279288
", caption='" + caption + '\'' +
280289
", contact=" + contact +
281290
", location=" + location +
282291
", venue=" + venue +
283-
", new_chat_members=" + Arrays.toString(new_chat_members) +
292+
", new_chat_member=" + new_chat_member +
284293
", left_chat_member=" + left_chat_member +
285294
", new_chat_title='" + new_chat_title + '\'' +
286295
", new_chat_photo=" + Arrays.toString(new_chat_photo) +
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Stas Parshin
7+
* 23 May 2017
8+
*/
9+
public class VideoNote implements Serializable {
10+
private final static long serialVersionUID = 0L;
11+
12+
private String file_id;
13+
private Integer length;
14+
private Integer duration;
15+
private PhotoSize thumb;
16+
private Integer file_size;
17+
18+
public String fileId() {
19+
return file_id;
20+
}
21+
22+
public Integer length() {
23+
return length;
24+
}
25+
26+
public Integer duration() {
27+
return duration;
28+
}
29+
30+
public PhotoSize thumb() {
31+
return thumb;
32+
}
33+
34+
public Integer fileSize() {
35+
return file_size;
36+
}
37+
38+
@Override
39+
public boolean equals(Object o) {
40+
if (this == o) return true;
41+
if (o == null || getClass() != o.getClass()) return false;
42+
43+
VideoNote videoNote = (VideoNote) o;
44+
45+
if (file_id != null ? !file_id.equals(videoNote.file_id) : videoNote.file_id != null) return false;
46+
if (length != null ? !length.equals(videoNote.length) : videoNote.length != null) return false;
47+
if (duration != null ? !duration.equals(videoNote.duration) : videoNote.duration != null) return false;
48+
if (thumb != null ? !thumb.equals(videoNote.thumb) : videoNote.thumb != null) return false;
49+
return file_size != null ? file_size.equals(videoNote.file_size) : videoNote.file_size == null;
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
return file_id != null ? file_id.hashCode() : 0;
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return "VideoNote{" +
60+
"file_id='" + file_id + '\'' +
61+
", length=" + length +
62+
", duration=" + duration +
63+
", thumb=" + thumb +
64+
", file_size=" + file_size +
65+
'}';
66+
}
67+
}

library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
* 10/21/15.
66
*/
77
public enum ChatAction {
8-
typing, upload_photo, record_video, upload_video, record_audio, upload_audio, upload_document, find_location
8+
typing, upload_photo, record_video, upload_video, record_audio, upload_audio, upload_document, find_location,
9+
record_video_note, upload_video_note
910
}

library/src/main/java/com/pengrad/telegrambot/request/SendChatAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.pengrad.telegrambot.request;
22

3+
import com.pengrad.telegrambot.model.request.ChatAction;
34
import com.pengrad.telegrambot.response.BaseResponse;
45

56
/**
@@ -12,4 +13,9 @@ public SendChatAction(Object chatId, String action) {
1213
super(BaseResponse.class);
1314
add("chat_id", chatId).add("action", action);
1415
}
16+
17+
public SendChatAction(Object chatId, ChatAction action) {
18+
super(BaseResponse.class);
19+
add("chat_id", chatId).add("action", action.name());
20+
}
1521
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.pengrad.telegrambot.request;
2+
3+
import java.io.File;
4+
5+
/**
6+
* Stas Parshin
7+
* 24 May 2017
8+
*/
9+
public class SendVideoNote extends AbstractMultipartRequest<SendVideoNote> {
10+
11+
public SendVideoNote(Object chatId, String videoNote) {
12+
super(chatId, videoNote);
13+
}
14+
15+
public SendVideoNote(Object chatId, File videoNote) {
16+
super(chatId, videoNote);
17+
}
18+
19+
public SendVideoNote(Object chatId, byte[] videoNote) {
20+
super(chatId, videoNote);
21+
}
22+
23+
public SendVideoNote duration(int duration) {
24+
return add("duration", duration);
25+
}
26+
27+
public SendVideoNote length(int length) {
28+
return add("length", length);
29+
}
30+
31+
@Override
32+
protected String getFileParamName() {
33+
return "video_note";
34+
}
35+
36+
@Override
37+
public String getContentType() {
38+
return ContentTypes.VIDEO_MIME_TYPE;
39+
}
40+
41+
@Override
42+
protected String getDefaultFileName() {
43+
return ContentTypes.VIDEO_FILE_NAME;
44+
}
45+
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void getMe() {
6464

6565
@Test
6666
public void getUpdates() {
67-
GetUpdatesResponse response = bot.execute(new GetUpdates().offset(279824711).allowedUpdates("callback_query"));
67+
GetUpdatesResponse response = bot.execute(new GetUpdates());
6868
System.out.println(response);
6969
}
7070

@@ -281,4 +281,24 @@ public void deleteMessage() {
281281
BaseResponse response = bot.execute(new DeleteMessage(chatId, message.messageId()));
282282
assertTrue(response.isOk());
283283
}
284+
285+
@Test
286+
public void sendChatAction() {
287+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.typing)).isOk());
288+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_photo)).isOk());
289+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.record_video)).isOk());
290+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_video)).isOk());
291+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.record_audio)).isOk());
292+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_audio)).isOk());
293+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_document)).isOk());
294+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.find_location)).isOk());
295+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.record_video_note)).isOk());
296+
assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_video_note)).isOk());
297+
}
298+
299+
@Test
300+
public void sendVideoNote() {
301+
SendResponse response = bot.execute(new SendVideoNote(chatId, "DQADAgADmQADYgwpSbum1JrxPsbmAg").length(240));
302+
VideoNoteCheck.check(response.message().videoNote());
303+
}
284304
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.model.VideoNote;
4+
5+
import static org.junit.Assert.assertNotNull;
6+
7+
/**
8+
* Stas Parshin
9+
* 24 May 2017
10+
*/
11+
public class VideoNoteCheck {
12+
13+
public static void check(VideoNote videoNote) {
14+
assertNotNull(videoNote.fileId());
15+
assertNotNull(videoNote.length());
16+
assertNotNull(videoNote.duration());
17+
assertNotNull(videoNote.fileSize());
18+
PhotoSizeTest.checkPhotos(videoNote.thumb());
19+
}
20+
21+
}

0 commit comments

Comments
 (0)