├── src ├── test │ ├── resource │ │ ├── board │ │ │ └── deleteComment │ │ │ │ └── success.json │ │ ├── json │ │ │ └── response │ │ │ │ ├── get_updates_failed_1_5_110.json │ │ │ │ ├── empty_updates_sample_5_110.json │ │ │ │ ├── get_long_poll_server_response_sample_5_110.json │ │ │ │ ├── messages_send │ │ │ │ └── message_send_responses_sample_5_110.json │ │ │ │ ├── board_post_delete │ │ │ │ └── board_post_delete_sample_5_110.json │ │ │ │ ├── message_typing_state │ │ │ │ └── message_typing_state_sample_5_111.json │ │ │ │ ├── wall_reply_delete │ │ │ │ └── wall_reply_delete_sample_5_110.json │ │ │ │ ├── video_comment_delete │ │ │ │ └── video_comment_delete_sample_5_110.json │ │ │ │ ├── photo_comment_delete │ │ │ │ └── photo_comment_delete_sample_5_110.json │ │ │ │ ├── board_post_new │ │ │ │ └── board_post_new_sample_5_110.json │ │ │ │ ├── board_post_edit │ │ │ │ └── board_post_edit_sample_5_110.json │ │ │ │ ├── like_remove │ │ │ │ └── like_remove_sample_5_110.json │ │ │ │ ├── board_post_restore │ │ │ │ └── board_post_restore_sample_5_110.json │ │ │ │ ├── group_change_settings │ │ │ │ └── group_change_settings_sample_5_110.json │ │ │ │ ├── like_add │ │ │ │ └── like_add_sample_5_110.json │ │ │ │ ├── photo_comment_new │ │ │ │ └── photo_comment_new_sample_5_110.json │ │ │ │ ├── video_comment_edit │ │ │ │ └── video_comment_edit_sample_5_110.json │ │ │ │ ├── photo_comment_edit │ │ │ │ └── photo_comment_edit_sample_5_110.json │ │ │ │ ├── video_comment_new │ │ │ │ └── video_comment_new_sample_5_110.json │ │ │ │ ├── photo_comment_restore │ │ │ │ └── photo_comment_restore_sample_5_110.json │ │ │ │ ├── video_comment_restore │ │ │ │ └── video_comment_restore_sample_5_110.json │ │ │ │ ├── wall_reply_new │ │ │ │ └── wall_reply_new_sample_5_110.json │ │ │ │ ├── wall_reply_edit │ │ │ │ └── wall_reply_edit_sample_5_110.json │ │ │ │ ├── wall_reply_restore │ │ │ │ └── wall_reply_restore_sample_5_110.json │ │ │ │ ├── get_long_poll_server_response_error_sample_5_110.json │ │ │ │ ├── message_reply │ │ │ │ └── message_reply_sample_5_110.json │ │ │ │ ├── audio_new │ │ │ │ └── audio_new_sample_5_110.json │ │ │ │ ├── message_edit │ │ │ │ └── message_edit_sample_5_110.json │ │ │ │ ├── message_event │ │ │ │ └── message_event_payload_sample_5_118.json │ │ │ │ ├── wall_post_new │ │ │ │ └── wall_post_new_sample_5_110.json │ │ │ │ ├── wall_repost │ │ │ │ └── wall_repost_sample_5_110.json │ │ │ │ ├── message_new │ │ │ │ ├── message_new_text_sample_5_110.json │ │ │ │ ├── message_new_start_button_sample_5_110.json │ │ │ │ ├── message_new_bomb_sample_5_118.json │ │ │ │ ├── message_new_geo_sample_5_110.json │ │ │ │ ├── message_new_reply_sample_5_110.json │ │ │ │ ├── message_new_fwd_sample_5_110.json │ │ │ │ ├── message_new_payload_sample_5_118.json │ │ │ │ ├── message_new_graffiti_sample_5_110.json │ │ │ │ ├── message_new_doc_no_preview_sample_5_118.json │ │ │ │ ├── message_new_wall_reply_sample_5_110.json │ │ │ │ └── message_new_audio_sample_5_110.json │ │ │ │ └── video_new │ │ │ │ └── video_new_sample_5_110.json │ │ ├── groups │ │ │ └── getLongPollServer │ │ │ │ └── success.json │ │ └── log4j2.xml │ └── java │ │ ├── api │ │ └── longpoll │ │ │ └── bots │ │ │ ├── methods │ │ │ └── impl │ │ │ │ └── board │ │ │ │ ├── DeleteCommentTest.java │ │ │ │ └── RestoreCommentTest.java │ │ │ └── converters │ │ │ ├── response │ │ │ └── messages │ │ │ │ └── MessagesSendResultConverterTest.java │ │ │ └── events │ │ │ └── messages │ │ │ └── MessagesGetHistoryAttachmentsResultConverterTest.java │ │ └── parse │ │ └── response │ │ ├── GroupsGroupsGetLongPollServerResponseParseTest.java │ │ ├── message │ │ ├── MessageTypingStateParseTest.java │ │ ├── MessageReplyParseTest.java │ │ └── MessageEditParseTest.java │ │ ├── UpdatesParseTest.java │ │ ├── board │ │ ├── BoardPostDeleteParseTest.java │ │ ├── BoardReplyNewParseTest.java │ │ └── BoardPostEditParseTest.java │ │ ├── likes │ │ ├── LikeAddParseTest.java │ │ └── LikeRemoveParseTest.java │ │ ├── wall │ │ ├── WallCommentDeleteParseTest.java │ │ ├── WallCommentNewParseTest.java │ │ ├── WallCommentEditParseTest.java │ │ └── WallCommentRestoreParseTest.java │ │ ├── video │ │ ├── VideoCommentDeleteParseTest.java │ │ ├── VideoCommentParseTest.java │ │ ├── VideoCommentNewParseTest.java │ │ ├── VideoCommentRestoreParseTest.java │ │ └── VideoNewParseTest.java │ │ ├── audio │ │ └── AudioNewParseTest.java │ │ ├── photo │ │ ├── PhotoCommentDeleteParseTest.java │ │ ├── PhotoNewParseTest.java │ │ ├── PhotoCommentNewParseTest.java │ │ ├── PhotoCommentEditParseTest.java │ │ └── PhotoCommentRestoreParseTest.java │ │ └── other │ │ └── GroupChangeSettingsParseTest.java └── main │ └── java │ └── api │ └── longpoll │ └── bots │ ├── package-info.java │ ├── http │ ├── package-info.java │ ├── PathRequestBody.java │ └── InputStreamRequestBody.java │ ├── model │ ├── package-info.java │ ├── events │ │ ├── package-info.java │ │ ├── likes │ │ │ └── package-info.java │ │ ├── market │ │ │ ├── package-info.java │ │ │ └── MarketComment.java │ │ ├── other │ │ │ ├── package-info.java │ │ │ └── GroupChangePhoto.java │ │ ├── photos │ │ │ ├── package-info.java │ │ │ └── PhotoComment.java │ │ ├── users │ │ │ ├── package-info.java │ │ │ ├── GroupJoin.java │ │ │ ├── GroupLeave.java │ │ │ └── UserUnblock.java │ │ ├── video │ │ │ ├── package-info.java │ │ │ └── VideoComment.java │ │ ├── messages │ │ │ ├── package-info.java │ │ │ ├── MessageDeny.java │ │ │ ├── MessageAllow.java │ │ │ ├── MessageNew.java │ │ │ └── MessageTypingState.java │ │ ├── boards │ │ │ ├── package-info.java │ │ │ ├── BoardPost.java │ │ │ └── BoardPostDelete.java │ │ ├── wall │ │ │ └── comments │ │ │ │ ├── package-info.java │ │ │ │ └── WallReply.java │ │ └── poll │ │ │ └── PollVoteNew.java │ ├── response │ │ ├── package-info.java │ │ ├── IntegerResponseBody.java │ │ ├── GenericResponseBody.java │ │ └── ExtendedVkList.java │ └── objects │ │ ├── basic │ │ └── package-info.java │ │ ├── media │ │ ├── package-info.java │ │ ├── UploadTypes.java │ │ └── Gift.java │ │ └── additional │ │ ├── package-info.java │ │ ├── buttons │ │ ├── package-info.java │ │ ├── LocationButton.java │ │ ├── VKPayButton.java │ │ └── OpenLinkButton.java │ │ ├── carousel │ │ ├── package-info.java │ │ └── Carousel.java │ │ ├── Lang.java │ │ ├── Template.java │ │ ├── NameCase.java │ │ ├── Currency.java │ │ ├── Country.java │ │ ├── VkList.java │ │ ├── Image.java │ │ ├── Price.java │ │ └── Keyboard.java │ ├── utils │ ├── package-info.java │ ├── ParamUtils.java │ └── VkMethods.java │ ├── methods │ ├── package-info.java │ ├── impl │ │ ├── other │ │ │ ├── package-info.java │ │ │ └── Execute.java │ │ ├── package-info.java │ │ ├── upload │ │ │ ├── package-info.java │ │ │ ├── UploadDoc.java │ │ │ └── UploadStory.java │ │ ├── docs │ │ │ ├── package-info.java │ │ │ ├── GetWallUploadServer.java │ │ │ ├── Search.java │ │ │ └── Save.java │ │ ├── groups │ │ │ ├── package-info.java │ │ │ ├── EnableOnline.java │ │ │ ├── DisableOnline.java │ │ │ ├── DeleteAddress.java │ │ │ ├── DeleteCallbackServer.java │ │ │ ├── SetSettings.java │ │ │ └── EditCallbackServer.java │ │ ├── market │ │ │ ├── package-info.java │ │ │ ├── GetOrderById.java │ │ │ └── GetGroupOrders.java │ │ ├── photos │ │ │ ├── package-info.java │ │ │ └── GetChatUploadServer.java │ │ ├── users │ │ │ └── package-info.java │ │ ├── utils │ │ │ ├── package-info.java │ │ │ └── GetServerTime.java │ │ ├── messages │ │ │ ├── package-info.java │ │ │ ├── Unpin.java │ │ │ ├── EditChat.java │ │ │ ├── Restore.java │ │ │ ├── Pin.java │ │ │ ├── SetActivity.java │ │ │ ├── RemoveChatUser.java │ │ │ ├── MarkAsAnsweredConversation.java │ │ │ ├── MarkAsImportantConversation.java │ │ │ ├── MarkAsRead.java │ │ │ ├── CreateChat.java │ │ │ └── SendEventAnswer.java │ │ ├── stories │ │ │ ├── package-info.java │ │ │ ├── HideReply.java │ │ │ ├── Save.java │ │ │ ├── HideAllReplies.java │ │ │ ├── Delete.java │ │ │ └── Get.java │ │ ├── wall │ │ │ ├── package-info.java │ │ │ ├── OpenComments.java │ │ │ └── CloseComments.java │ │ ├── events │ │ │ └── package-info.java │ │ └── board │ │ │ ├── package-info.java │ │ │ ├── DeleteComment.java │ │ │ └── RestoreComment.java │ ├── UsersMethods.java │ ├── OtherMethods.java │ ├── BoardMethods.java │ ├── WallMethods.java │ ├── DocsMethods.java │ ├── MarketMethods.java │ ├── UtilsMethods.java │ ├── VkBotsMethods.java │ └── PhotosMethods.java │ ├── validator │ ├── package-info.java │ └── VkResponseBodyValidator.java │ ├── helpers │ └── attachments │ │ ├── package-info.java │ │ └── UploadableFile.java │ ├── exceptions │ ├── package-info.java │ ├── VkResponseException.java │ └── VkApiException.java │ └── adapters │ └── deserializers │ ├── package-info.java │ ├── BoolIntDeserializer.java │ ├── CoordinatesDeserializer.java │ ├── SendResponseBodyDeserializer.java │ ├── PayloadDeserializer.java │ ├── IsMemberResponseBodyDeserializer.java │ └── GetMemberResponseBodyDeserializer.java ├── .gitignore ├── .github ├── dependabot.yml ├── workflows │ └── build-maven-project.yml └── ISSUE_TEMPLATE │ └── receiving-vk-api-exeption.md └── LICENSE /src/test/resource/board/deleteComment/success.json: -------------------------------------------------------------------------------- 1 | { 2 | "response": 1 3 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/get_updates_failed_1_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "failed": 1, 3 | "ts": 2593 4 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Main classes. 3 | */ 4 | package api.longpoll.bots; -------------------------------------------------------------------------------- /src/test/resource/json/response/empty_updates_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2587", 3 | "updates": [] 4 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/http/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * HTTP wrappers. 3 | */ 4 | package api.longpoll.bots.http; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * VK API model. 3 | */ 4 | package api.longpoll.bots.model; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utils classes. 3 | */ 4 | package api.longpoll.bots.utils; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * VK API methods. 3 | */ 4 | package api.longpoll.bots.methods; 5 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Event objects. 3 | */ 4 | package api.longpoll.bots.model.events; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/validator/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * VK response validators. 3 | */ 4 | package api.longpoll.bots.validator; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/likes/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * "Like" events. 3 | */ 4 | package api.longpoll.bots.model.events.likes; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/market/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Market events. 3 | */ 4 | package api.longpoll.bots.model.events.market; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/other/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Other events. 3 | */ 4 | package api.longpoll.bots.model.events.other; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/photos/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Photo events. 3 | */ 4 | package api.longpoll.bots.model.events.photos; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/users/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * User events. 3 | */ 4 | package api.longpoll.bots.model.events.users; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/video/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Video events. 3 | */ 4 | package api.longpoll.bots.model.events.video; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/response/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * VK response objects. 3 | */ 4 | package api.longpoll.bots.model.response; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/other/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Other VK methods. 3 | */ 4 | package api.longpoll.bots.methods.impl.other; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Implementation of VK API methods. 3 | */ 4 | package api.longpoll.bots.methods.impl; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/messages/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Message events. 3 | */ 4 | package api.longpoll.bots.model.events.messages; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/basic/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * VK main objects. 3 | */ 4 | package api.longpoll.bots.model.objects.basic; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/media/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * VK media objects. 3 | */ 4 | package api.longpoll.bots.model.objects.media; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/upload/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to upload files. 3 | */ 4 | package api.longpoll.bots.methods.impl.upload; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | *.png 4 | target 5 | ~*.xlsx 6 | src/test/java/*.java 7 | *.jar 8 | replacement.properties 9 | replace.bat 10 | revertReplace.bat -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/docs/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with documents. 3 | */ 4 | package api.longpoll.bots.methods.impl.docs; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/groups/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with groups. 3 | */ 4 | package api.longpoll.bots.methods.impl.groups; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/market/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with market. 3 | */ 4 | package api.longpoll.bots.methods.impl.market; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/photos/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with photos. 3 | */ 4 | package api.longpoll.bots.methods.impl.photos; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/users/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with users. 3 | */ 4 | package api.longpoll.bots.methods.impl.users; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with utils. 3 | */ 4 | package api.longpoll.bots.methods.impl.utils; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with messages. 3 | */ 4 | package api.longpoll.bots.methods.impl.messages; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/stories/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with stories. 3 | */ 4 | package api.longpoll.bots.methods.impl.stories; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/wall/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with community wall. 3 | */ 4 | package api.longpoll.bots.methods.impl.wall; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/boards/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Community discussion board events. 3 | */ 4 | package api.longpoll.bots.model.events.boards; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/wall/comments/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Wall comment events. 3 | */ 4 | package api.longpoll.bots.model.events.wall.comments; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Addition VK objects. 3 | */ 4 | package api.longpoll.bots.model.objects.additional; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/helpers/attachments/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper classes to upload attachments. 3 | */ 4 | package api.longpoll.bots.helpers.attachments; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/events/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with community events. 3 | */ 4 | package api.longpoll.bots.methods.impl.events; -------------------------------------------------------------------------------- /src/test/resource/json/response/get_long_poll_server_response_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "response": { 3 | "key": "aaa", 4 | "server": "bbb", 5 | "ts": "2587" 6 | } 7 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/exceptions/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Exceptions occur in Java VK Bots Long Poll API library. 3 | */ 4 | package api.longpoll.bots.exceptions; 5 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/board/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Methods to work with community discussion board. 3 | */ 4 | package api.longpoll.bots.methods.impl.board; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/buttons/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Objects to create buttons. 3 | */ 4 | package api.longpoll.bots.model.objects.additional.buttons; -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/adapters/deserializers/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains JSON deserializer for specific POJOs. 3 | */ 4 | package api.longpoll.bots.adapters.deserializers; 5 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/carousel/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Objects to create carousel. 3 | */ 4 | package api.longpoll.bots.model.objects.additional.carousel; -------------------------------------------------------------------------------- /src/test/resource/groups/getLongPollServer/success.json: -------------------------------------------------------------------------------- 1 | { 2 | "response": { 3 | "key": "27aed56f6d2f47ba45920e4e1f539fe103961f0a", 4 | "server": "https://lp.vk.com/wh168975658", 5 | "ts": "3394" 6 | } 7 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/messages_send/message_send_responses_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "response": [ 3 | { 4 | "peer_id": 111, 5 | "message_id": 287 6 | }, 7 | { 8 | "peer_id": 222, 9 | "message_id": 288 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/response/IntegerResponseBody.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.response; 2 | 3 | /** 4 | * Simple response object like: 5 | *
 6 |  * {
 7 |  *     response: 1
 8 |  * }
 9 |  * 
10 | */ 11 | public class IntegerResponseBody extends GenericResponseBody { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/exceptions/VkResponseException.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.exceptions; 2 | 3 | /** 4 | * Occurs when VK returns "error" of "failed" response. 5 | */ 6 | public class VkResponseException extends VkApiException { 7 | public VkResponseException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/resource/json/response/board_post_delete/board_post_delete_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2638", 3 | "updates": [ 4 | { 5 | "type": "board_post_delete", 6 | "object": { 7 | "topic_owner_id": -111, 8 | "id": 3, 9 | "topic_id": 333 10 | }, 11 | "group_id": 123, 12 | "event_id": "aaa" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/message_typing_state/message_typing_state_sample_5_111.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "666", 3 | "updates": [ 4 | { 5 | "type": "message_typing_state", 6 | "object": { 7 | "state": "typing", 8 | "from_id": 789, 9 | "to_id": -456 10 | }, 11 | "group_id": 123, 12 | "event_id": "abc" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/media/UploadTypes.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.media; 2 | 3 | /** 4 | * Type of file to be uploaded to VK server. 5 | */ 6 | public class UploadTypes { 7 | public static final String FILE = "file"; 8 | public static final String PHOTO = "photo"; 9 | public static final String VIDEO_FILE = "video_file"; 10 | } 11 | -------------------------------------------------------------------------------- /src/test/resource/json/response/wall_reply_delete/wall_reply_delete_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2633", 3 | "updates": [ 4 | { 5 | "type": "wall_reply_delete", 6 | "object": { 7 | "owner_id": -111, 8 | "id": 4, 9 | "deleter_id": 222, 10 | "post_id": 3 11 | }, 12 | "group_id": 333, 13 | "event_id": "aaa" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/video_comment_delete/video_comment_delete_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2622", 3 | "updates": [ 4 | { 5 | "type": "video_comment_delete", 6 | "object": { 7 | "owner_id": -111, 8 | "id": 1, 9 | "deleter_id": 222, 10 | "video_id": 333 11 | }, 12 | "group_id": 444, 13 | "event_id": "aaa" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/exceptions/VkApiException.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.exceptions; 2 | 3 | /** 4 | * A common exception that occurs in Java VK Bots Long Poll API library. 5 | */ 6 | public class VkApiException extends Exception { 7 | public VkApiException(Throwable cause) { 8 | super(cause); 9 | } 10 | 11 | public VkApiException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/resource/json/response/photo_comment_delete/photo_comment_delete_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2615", 3 | "updates": [ 4 | { 5 | "type": "photo_comment_delete", 6 | "object": { 7 | "owner_id": -111, 8 | "id": 333, 9 | "deleter_id": 222, 10 | "photo_id": 444, 11 | "user_id": 555 12 | }, 13 | "group_id": 666, 14 | "event_id": "aaa" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/board_post_new/board_post_new_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2635", 3 | "updates": [ 4 | { 5 | "type": "board_post_new", 6 | "object": { 7 | "id": 2, 8 | "from_id": 111, 9 | "date": 1595841380, 10 | "text": "test", 11 | "topic_owner_id": -222, 12 | "topic_id": 333 13 | }, 14 | "group_id": 444, 15 | "event_id": "aaa" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/board_post_edit/board_post_edit_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2636", 3 | "updates": [ 4 | { 5 | "type": "board_post_edit", 6 | "object": { 7 | "id": 2, 8 | "from_id": 123, 9 | "date": 1595841380, 10 | "text": "testtest", 11 | "topic_owner_id": -111, 12 | "topic_id": 222 13 | }, 14 | "group_id": 333, 15 | "event_id": "aaa" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/like_remove/like_remove_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2630", 3 | "updates": [ 4 | { 5 | "type": "like_remove", 6 | "object": { 7 | "liker_id": 111, 8 | "object_type": "post", 9 | "object_owner_id": -222, 10 | "object_id": 3, 11 | "thread_reply_id": 0, 12 | "post_id": 0 13 | }, 14 | "group_id": 333, 15 | "event_id": "aaa" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/board_post_restore/board_post_restore_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2639", 3 | "updates": [ 4 | { 5 | "type": "board_post_restore", 6 | "object": { 7 | "id": 3, 8 | "from_id": 111, 9 | "date": 1596652625, 10 | "text": "t", 11 | "topic_owner_id": -222, 12 | "topic_id": 333 13 | }, 14 | "group_id": 444, 15 | "event_id": "aaa" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /src/test/resource/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/resource/json/response/group_change_settings/group_change_settings_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2644", 3 | "updates": [ 4 | { 5 | "type": "group_change_settings", 6 | "object": { 7 | "user_id": 111, 8 | "changes": { 9 | "description": { 10 | "old_value": "test", 11 | "new_value": "test1" 12 | } 13 | } 14 | }, 15 | "group_id": 222, 16 | "event_id": "aaa" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/Lang.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | /** 4 | * Lang. 5 | */ 6 | public enum Lang { 7 | RU(0), 8 | UK(1), 9 | BE(2), 10 | EN(3), 11 | ES(4), 12 | FI(5), 13 | DE(6), 14 | IT(7); 15 | 16 | /** 17 | * Lang code. 18 | */ 19 | private final int code; 20 | 21 | Lang(int code) { 22 | this.code = code; 23 | } 24 | 25 | public int getCode() { 26 | return code; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/resource/json/response/like_add/like_add_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2629", 3 | "updates": [ 4 | { 5 | "type": "like_add", 6 | "object": { 7 | "liker_id": 111, 8 | "object_type": "post", 9 | "object_owner_id": -222, 10 | "object_id": 3, 11 | "thread_reply_id": 0, 12 | "post_id": 0 13 | }, 14 | "group_id": 333, 15 | "event_id": "aaa" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/photo_comment_new/photo_comment_new_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2613", 3 | "updates": [ 4 | { 5 | "type": "photo_comment_new", 6 | "object": { 7 | "id": 3, 8 | "from_id": 111, 9 | "parents_stack": [], 10 | "date": 1594285508, 11 | "text": "t", 12 | "thread": { 13 | "count": 0 14 | }, 15 | "photo_owner_id": -222, 16 | "photo_id": 333 17 | }, 18 | "group_id": 444, 19 | "event_id": "aaa" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/video_comment_edit/video_comment_edit_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2621", 3 | "updates": [ 4 | { 5 | "type": "video_comment_edit", 6 | "object": { 7 | "id": 1, 8 | "from_id": 111, 9 | "parents_stack": [], 10 | "date": 222, 11 | "text": "check2", 12 | "thread": { 13 | "count": 0 14 | }, 15 | "video_owner_id": -333, 16 | "video_id": 444 17 | }, 18 | "group_id": 555, 19 | "event_id": "aaa" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/photo_comment_edit/photo_comment_edit_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2614", 3 | "updates": [ 4 | { 5 | "type": "photo_comment_edit", 6 | "object": { 7 | "id": 111, 8 | "from_id": 222, 9 | "parents_stack": [], 10 | "date": 1594285508, 11 | "text": "tt", 12 | "thread": { 13 | "count": 0 14 | }, 15 | "photo_owner_id": -333, 16 | "photo_id": 444 17 | }, 18 | "group_id": 555, 19 | "event_id": "aaa" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/video_comment_new/video_comment_new_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2619", 3 | "updates": [ 4 | { 5 | "type": "video_comment_new", 6 | "object": { 7 | "id": 1, 8 | "from_id": 111, 9 | "parents_stack": [], 10 | "date": 1594823317, 11 | "text": "check", 12 | "thread": { 13 | "count": 0 14 | }, 15 | "video_owner_id": -222, 16 | "video_id": 333 17 | }, 18 | "group_id": 444, 19 | "event_id": "aaa" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/photo_comment_restore/photo_comment_restore_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2616", 3 | "updates": [ 4 | { 5 | "type": "photo_comment_restore", 6 | "object": { 7 | "id": 3, 8 | "from_id": 111, 9 | "parents_stack": [], 10 | "date": 1594285508, 11 | "text": "tt", 12 | "thread": { 13 | "count": 0 14 | }, 15 | "photo_owner_id": -222, 16 | "photo_id": 333 17 | }, 18 | "group_id": 444, 19 | "event_id": "aaa" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/video_comment_restore/video_comment_restore_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2625", 3 | "updates": [ 4 | { 5 | "type": "video_comment_restore", 6 | "object": { 7 | "id": 2, 8 | "from_id": 111, 9 | "parents_stack": [], 10 | "date": 1594834849, 11 | "text": "t", 12 | "thread": { 13 | "count": 0 14 | }, 15 | "video_owner_id": -222, 16 | "video_id": 333 17 | }, 18 | "group_id": 444, 19 | "event_id": "aaa" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/wall_reply_new/wall_reply_new_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2631", 3 | "updates": [ 4 | { 5 | "type": "wall_reply_new", 6 | "object": { 7 | "id": 4, 8 | "from_id": 111, 9 | "post_id": 3, 10 | "owner_id": -222, 11 | "parents_stack": [], 12 | "date": 1594972082, 13 | "text": "test", 14 | "thread": { 15 | "count": 0 16 | }, 17 | "post_owner_id": -333 18 | }, 19 | "group_id": 444, 20 | "event_id": "aaa" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/wall_reply_edit/wall_reply_edit_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2632", 3 | "updates": [ 4 | { 5 | "type": "wall_reply_edit", 6 | "object": { 7 | "id": 4, 8 | "from_id": 111, 9 | "post_id": 3, 10 | "owner_id": -222, 11 | "parents_stack": [], 12 | "date": 1594972082, 13 | "text": "test1", 14 | "thread": { 15 | "count": 0 16 | }, 17 | "post_owner_id": -333 18 | }, 19 | "group_id": 444, 20 | "event_id": "aaa" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/wall_reply_restore/wall_reply_restore_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2634", 3 | "updates": [ 4 | { 5 | "type": "wall_reply_restore", 6 | "object": { 7 | "id": 4, 8 | "from_id": 111, 9 | "post_id": 3, 10 | "owner_id": -222, 11 | "parents_stack": [], 12 | "date": 1594972082, 13 | "text": "test1", 14 | "thread": { 15 | "count": 0 16 | }, 17 | "post_owner_id": -333 18 | }, 19 | "group_id": 444, 20 | "event_id": "aaa" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/get_long_poll_server_response_error_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": { 3 | "error_code": 5, 4 | "error_msg": "User authorization failed: no access_token passed.", 5 | "request_params": [ 6 | { 7 | "key": "group_id", 8 | "value": "111" 9 | }, 10 | { 11 | "key": "v", 12 | "value": "5.107" 13 | }, 14 | { 15 | "key": "method", 16 | "value": "groups.getLongPollServer" 17 | }, 18 | { 19 | "key": "oauth", 20 | "value": "1" 21 | } 22 | ] 23 | } 24 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | assignees: 13 | - "bivashy" 14 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/UsersMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.users.Get; 4 | 5 | import java.util.function.Supplier; 6 | 7 | /** 8 | * Provides Users methods. 9 | */ 10 | public class UsersMethods { 11 | /** 12 | * {@code access_token}. 13 | */ 14 | private final Supplier accessTokenSupplier; 15 | 16 | public UsersMethods(Supplier accessTokenSupplier) { 17 | this.accessTokenSupplier = accessTokenSupplier; 18 | } 19 | 20 | public Get get() { 21 | return new Get(accessTokenSupplier.get()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/buttons/LocationButton.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional.buttons; 2 | 3 | import com.google.gson.JsonElement; 4 | 5 | /** 6 | * A button to send user location. 7 | */ 8 | public class LocationButton extends Button { 9 | public LocationButton(Action action) { 10 | super(action); 11 | } 12 | 13 | public static class Action extends Button.Action { 14 | public Action() { 15 | this(null); 16 | } 17 | 18 | public Action(JsonElement payload) { 19 | super("location", payload); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/Template.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Marks special message. 7 | */ 8 | public abstract class Template { 9 | /** 10 | * Type of message. 11 | */ 12 | @SerializedName("type") 13 | private final String type; 14 | 15 | public Template(String type) { 16 | this.type = type; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "Template{" + 22 | "type='" + type + '\'' + 23 | '}'; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/utils/ParamUtils.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.utils; 2 | 3 | import java.util.stream.Collectors; 4 | import java.util.stream.StreamSupport; 5 | 6 | /** 7 | * Param utils. 8 | */ 9 | public class ParamUtils { 10 | /** 11 | * Converts values into CSV-formatted string. 12 | * 13 | * @param values values to convert. 14 | * @return CSV-formatted string. 15 | */ 16 | public static String csv(Iterable values) { 17 | return StreamSupport.stream(values.spliterator(), false) 18 | .map(String::valueOf) 19 | .collect(Collectors.joining(",")); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/OtherMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.other.Execute; 4 | 5 | import java.util.function.Supplier; 6 | 7 | /** 8 | * Provides other methods. 9 | */ 10 | public class OtherMethods { 11 | /** 12 | * {@code access_token}. 13 | */ 14 | private final Supplier accessTokenSupplier; 15 | 16 | public OtherMethods(Supplier accessTokenSupplier) { 17 | this.accessTokenSupplier = accessTokenSupplier; 18 | } 19 | 20 | public Execute execute() { 21 | return new Execute(accessTokenSupplier.get()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_reply/message_reply_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2610", 3 | "updates": [ 4 | { 5 | "type": "message_reply", 6 | "object": { 7 | "date": 1594282112, 8 | "from_id": 111, 9 | "id": 222, 10 | "out": 1, 11 | "peer_id": 333, 12 | "text": "test", 13 | "conversation_message_id": 261, 14 | "fwd_messages": [], 15 | "important": false, 16 | "random_id": 0, 17 | "attachments": [], 18 | "admin_author_id": 444, 19 | "is_hidden": false 20 | }, 21 | "group_id": 555, 22 | "event_id": "aaa" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/audio_new/audio_new_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2618", 3 | "updates": [ 4 | { 5 | "type": "audio_new", 6 | "object": { 7 | "artist": "Rick Astley", 8 | "id": 456239017, 9 | "owner_id": -111, 10 | "title": "Never Gonna Give You Up", 11 | "duration": 211, 12 | "is_explicit": false, 13 | "is_focus_track": false, 14 | "track_code": "aaa", 15 | "url": "", 16 | "date": 1594822421, 17 | "short_videos_allowed": false, 18 | "stories_allowed": false 19 | }, 20 | "group_id": 123, 21 | "event_id": "abc" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/message_edit/message_edit_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2611", 3 | "updates": [ 4 | { 5 | "type": "message_edit", 6 | "object": { 7 | "date": 1594282377, 8 | "from_id": -111, 9 | "id": 276, 10 | "out": 1, 11 | "peer_id": 222, 12 | "text": "tests", 13 | "conversation_message_id": 261, 14 | "fwd_messages": [], 15 | "important": false, 16 | "random_id": 0, 17 | "attachments": [], 18 | "admin_author_id": 333, 19 | "is_hidden": false, 20 | "update_time": 1594282377 21 | }, 22 | "group_id": 444, 23 | "event_id": "aaa" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/adapters/deserializers/BoolIntDeserializer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.adapters.deserializers; 2 | 3 | import com.google.gson.JsonDeserializationContext; 4 | import com.google.gson.JsonDeserializer; 5 | import com.google.gson.JsonElement; 6 | import com.google.gson.JsonParseException; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | /** 11 | * Deserializes Integer JSON value to {@link Boolean}. (0 = false, 1 = true) 12 | */ 13 | public class BoolIntDeserializer implements JsonDeserializer { 14 | @Override 15 | public final Boolean deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { 16 | return jsonElement.getAsInt() == 1; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_event/message_event_payload_sample_5_118.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "3482", 3 | "updates": [ 4 | { 5 | "type": "message_event", 6 | "object": { 7 | "user_id": 918650328, 8 | "peer_id": 918650328, 9 | "event_id": "5bba1af2abf1", 10 | "payload": { 11 | "data": "clicked", 12 | "time": 1622386091581, 13 | "values": [ 14 | 11, 15 | 22, 16 | 33 17 | ], 18 | "status": { 19 | "active": true 20 | } 21 | }, 22 | "conversation_message_id": 833 23 | }, 24 | "group_id": 886761559, 25 | "event_id": "e82ea61c19c93ee32c8f4a26886b139009539d02" 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/helpers/attachments/UploadableFile.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.helpers.attachments; 2 | 3 | import api.longpoll.bots.exceptions.VkApiException; 4 | import api.longpoll.bots.model.objects.additional.UploadedFile; 5 | 6 | import java.util.concurrent.CompletableFuture; 7 | 8 | /** 9 | * Uploads file. 10 | */ 11 | public interface UploadableFile { 12 | /** 13 | * Uploads file synchronously. 14 | * 15 | * @return uploaded file. 16 | * @throws VkApiException if errors occur. 17 | */ 18 | UploadedFile upload() throws VkApiException; 19 | 20 | /** 21 | * Uploads file asynchronously. 22 | * 23 | * @return uploaded file. 24 | */ 25 | CompletableFuture uploadAsync(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/response/GenericResponseBody.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.response; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Generic VK response which contains only one field. 7 | * 8 | * @param field type. 9 | */ 10 | public class GenericResponseBody { 11 | /** 12 | * Response object. 13 | */ 14 | @SerializedName("response") 15 | private T response; 16 | 17 | public T getResponse() { 18 | return response; 19 | } 20 | 21 | public void setResponse(T response) { 22 | this.response = response; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "GenericResponseBody{" + 28 | "response=" + response + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/validator/VkResponseBodyValidator.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.validator; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonElement; 5 | 6 | import java.util.function.Predicate; 7 | 8 | /** 9 | * Validates Vk HTTP response body. 10 | */ 11 | public class VkResponseBodyValidator implements Predicate { 12 | /** 13 | * {@link Gson} object. 14 | */ 15 | private final Gson gson = new Gson(); 16 | 17 | @Override 18 | public boolean test(String responseBody) { 19 | JsonElement jsonElement = gson.fromJson(responseBody, JsonElement.class); 20 | return !jsonElement.isJsonObject() 21 | || !jsonElement.getAsJsonObject().has("error") 22 | && !jsonElement.getAsJsonObject().has("failed"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/resource/json/response/wall_post_new/wall_post_new_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2626", 3 | "updates": [ 4 | { 5 | "type": "wall_post_new", 6 | "object": { 7 | "id": 1, 8 | "from_id": 111, 9 | "owner_id": -222, 10 | "date": 1594888935, 11 | "marked_as_ads": 0, 12 | "post_type": "post", 13 | "text": "test", 14 | "can_edit": 1, 15 | "created_by": 333, 16 | "can_delete": 1, 17 | "comments": { 18 | "count": 0 19 | }, 20 | "is_favorite": false, 21 | "copyright": { 22 | "type": "external_link", 23 | "name": "github.com", 24 | "link": "https://github.com/" 25 | } 26 | }, 27 | "group_id": 444, 28 | "event_id": "aaa" 29 | } 30 | ] 31 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/messages/MessageDeny.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.messages; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes message_deny event object. 8 | */ 9 | public class MessageDeny implements Update.Object { 10 | /** 11 | * User ID. 12 | */ 13 | @SerializedName("user_id") 14 | private Integer userId; 15 | 16 | public Integer getUserId() { 17 | return userId; 18 | } 19 | 20 | public void setUserId(Integer userId) { 21 | this.userId = userId; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "MessageDenyEvent{" + 27 | "userId=" + userId + 28 | '}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/build-maven-project.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: Set up JDK 8 13 | uses: actions/setup-java@v3 14 | with: 15 | java-version: '8' 16 | distribution: 'adopt' 17 | - name: Cache Maven packages 18 | uses: actions/cache@v2 19 | with: 20 | path: ~/.m2 21 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 22 | restore-keys: ${{ runner.os }}-m2 23 | - name: Build with Maven 24 | run: mvn package --file pom.xml 25 | # - name: Coveralls GitHub Action 26 | # uses: codecov/codecov-action@v1 27 | # with: 28 | # file: ./**/target/site/jacoco/jacoco.xml 29 | # name: codecov -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/BoardMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.board.DeleteComment; 4 | import api.longpoll.bots.methods.impl.board.RestoreComment; 5 | 6 | import java.util.function.Supplier; 7 | 8 | /** 9 | * Provides Board methods. 10 | */ 11 | public class BoardMethods { 12 | /** 13 | * {@code access_token}. 14 | */ 15 | private final Supplier accessTokenSupplier; 16 | 17 | public BoardMethods(Supplier accessTokenSupplier) { 18 | this.accessTokenSupplier = accessTokenSupplier; 19 | } 20 | 21 | public DeleteComment deleteComment() { 22 | return new DeleteComment(accessTokenSupplier.get()); 23 | } 24 | 25 | public RestoreComment restoreComment() { 26 | return new RestoreComment(accessTokenSupplier.get()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/NameCase.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | /** 4 | * Case for declension of user name and surname. 5 | */ 6 | public enum NameCase { 7 | /** 8 | * Nominative. 9 | */ 10 | NOMINATIVE("nom"), 11 | 12 | /** 13 | * Genitive. 14 | */ 15 | GENITIVE("gen"), 16 | 17 | /** 18 | * Dative. 19 | */ 20 | DATIVE("dat"), 21 | 22 | /** 23 | * Accusative. 24 | */ 25 | ACCUSATIVE("acc"), 26 | 27 | /** 28 | * Instrumental. 29 | */ 30 | INSTRUMENTAL("ins"), 31 | 32 | /** 33 | * Prepositional. 34 | */ 35 | PREPOSITIONAL("abl"); 36 | 37 | /** 38 | * Param value. 39 | */ 40 | private final String value; 41 | 42 | NameCase(String value) { 43 | this.value = value; 44 | } 45 | 46 | public String getValue() { 47 | return value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/resource/json/response/wall_repost/wall_repost_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2628", 3 | "updates": [ 4 | { 5 | "type": "wall_repost", 6 | "object": { 7 | "id": 34, 8 | "from_id": 111, 9 | "owner_id": 222, 10 | "date": 1594890511, 11 | "post_type": "post", 12 | "text": "", 13 | "copy_history": [ 14 | { 15 | "id": 3, 16 | "owner_id": -333, 17 | "from_id": -444, 18 | "date": 1594890485, 19 | "post_type": "post", 20 | "text": "test", 21 | "post_source": { 22 | "type": "vk" 23 | } 24 | } 25 | ], 26 | "can_archive": true, 27 | "is_archived": false, 28 | "comments": { 29 | "count": 0 30 | }, 31 | "is_favorite": false 32 | }, 33 | "group_id": 555, 34 | "event_id": "aaa" 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /src/test/java/api/longpoll/bots/methods/impl/board/DeleteCommentTest.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.board; 2 | 3 | import api.longpoll.bots.methods.VkBotsMethods; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class DeleteCommentTest { 7 | VkBotsMethods vk = new VkBotsMethods("access_token"); 8 | 9 | @Test 10 | void deleteCommentCreation() { 11 | DeleteComment deleteComment = vk.board.deleteComment() 12 | .setGroupId(1) 13 | .setTopicId(2) 14 | .setCommentId(3); 15 | 16 | // assertEquals("https://api.vk.com/method/board.deleteComment", deleteComment.getUri()); 17 | // assertEquals(IntegerResponseBody.class, deleteComment.getResponseClass()); 18 | // assertEquals("1", deleteComment.getParams().get("group_id")); 19 | // assertEquals("2", deleteComment.getParams().get("topic_id")); 20 | // assertEquals("3", deleteComment.getParams().get("comment_id")); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/wall/comments/WallReply.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.wall.comments; 2 | 3 | import api.longpoll.bots.model.objects.basic.WallComment; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes wall_reply_new, wall_reply_edit and wall_reply_restore event objects. 8 | */ 9 | public class WallReply extends WallComment { 10 | /** 11 | * Post owner ID. 12 | */ 13 | @SerializedName("post_owner_id") 14 | private Integer postOwnerId; 15 | 16 | public Integer getPostOwnerId() { 17 | return postOwnerId; 18 | } 19 | 20 | public void setPostOwnerId(Integer postOwnerId) { 21 | this.postOwnerId = postOwnerId; 22 | } 23 | 24 | 25 | @Override 26 | public String toString() { 27 | return "WallReplyEvent{" + 28 | "postOwnerId=" + postOwnerId + 29 | "} " + super.toString(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/api/longpoll/bots/methods/impl/board/RestoreCommentTest.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.board; 2 | 3 | import api.longpoll.bots.methods.VkBotsMethods; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class RestoreCommentTest { 7 | VkBotsMethods vk = new VkBotsMethods("access_token"); 8 | 9 | @Test 10 | void restoreCommentCreation() { 11 | RestoreComment restoreComment = vk.board.restoreComment() 12 | .setGroupId(1) 13 | .setTopicId(2) 14 | .setCommentId(3); 15 | 16 | // assertEquals("https://api.vk.com/method/board.restoreComment", restoreComment.getUri()); 17 | // assertEquals(IntegerResponseBody.class, restoreComment.getResponseClass()); 18 | // assertEquals("1", restoreComment.getParams().get("group_id")); 19 | // assertEquals("2", restoreComment.getParams().get("topic_id")); 20 | // assertEquals("3", restoreComment.getParams().get("comment_id")); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/Currency.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes currency. 7 | */ 8 | public class Currency { 9 | /** 10 | * Currency ID. 11 | */ 12 | @SerializedName("id") 13 | private Integer id; 14 | 15 | /** 16 | * Currency letter. 17 | */ 18 | @SerializedName("name") 19 | private String name; 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Currency{" + 40 | "id=" + id + 41 | ", name='" + name + '\'' + 42 | '}'; 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/Country.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes country objects. 7 | */ 8 | public class Country { 9 | /** 10 | * Country ID. 11 | */ 12 | @SerializedName("id") 13 | private Integer id; 14 | 15 | /** 16 | * Country name. 17 | */ 18 | @SerializedName("title") 19 | private String title; 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getTitle() { 30 | return title; 31 | } 32 | 33 | public void setTitle(String title) { 34 | this.title = title; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Country{" + 40 | "id=" + id + 41 | ", title='" + title + '\'' + 42 | '}'; 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_text_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2588", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1593092311, 9 | "from_id": 111, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 222, 13 | "text": "test", 14 | "conversation_message_id": 4392, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [], 19 | "is_hidden": false 20 | }, 21 | "client_info": { 22 | "button_actions": [ 23 | "text", 24 | "vkpay", 25 | "open_app", 26 | "location", 27 | "open_link" 28 | ], 29 | "keyboard": true, 30 | "inline_keyboard": true, 31 | "lang_id": 0 32 | } 33 | }, 34 | "group_id": 333, 35 | "event_id": "aaa" 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/utils/GetServerTime.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.utils; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements utils.getServerTime method. 9 | *

10 | * Returns the current time of the VK server. 11 | * 12 | * @see https://vk.com/dev/utils.getServerTime 13 | */ 14 | public class GetServerTime extends VkMethod { 15 | public GetServerTime(String accessToken) { 16 | super(VkMethods.get("utils.getServerTime"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | @Override 25 | public GetServerTime addParam(String key, Object value) { 26 | return (GetServerTime) super.addParam(key, value); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/WallMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.wall.CloseComments; 4 | import api.longpoll.bots.methods.impl.wall.CreateComment; 5 | import api.longpoll.bots.methods.impl.wall.OpenComments; 6 | 7 | import java.util.function.Supplier; 8 | 9 | /** 10 | * Provides Utils methods. 11 | */ 12 | public class WallMethods { 13 | /** 14 | * {@code access_token}. 15 | */ 16 | private final Supplier accessTokenSupplier; 17 | 18 | public WallMethods(Supplier accessTokenSupplier) { 19 | this.accessTokenSupplier = accessTokenSupplier; 20 | } 21 | 22 | public CloseComments closeComments() { 23 | return new CloseComments(accessTokenSupplier.get()); 24 | } 25 | 26 | public CreateComment createComment() { 27 | return new CreateComment(accessTokenSupplier.get()); 28 | } 29 | 30 | public OpenComments openComments() { 31 | return new OpenComments(accessTokenSupplier.get()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/parse/response/GroupsGroupsGetLongPollServerResponseParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response; 2 | 3 | import api.longpoll.bots.methods.impl.groups.GetLongPollServer; 4 | import com.google.gson.Gson; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | import static org.junit.jupiter.api.Assertions.assertNotNull; 9 | 10 | public class GroupsGroupsGetLongPollServerResponseParseTest { 11 | final Gson gson = new Gson(); 12 | 13 | @Test 14 | void getLongPollServerResponseSuccessParse() { 15 | GetLongPollServer.ResponseBody vkResponse = gson.fromJson(ParseUtil.readJson("json/response/get_long_poll_server_response_sample_5_110.json"), GetLongPollServer.ResponseBody.class); 16 | assertNotNull(vkResponse); 17 | 18 | GetLongPollServer.ResponseBody.Response response = vkResponse.getResponse(); 19 | assertNotNull(response); 20 | assertEquals("aaa", response.getKey()); 21 | assertEquals("bbb", response.getServer()); 22 | assertEquals(2587, response.getTs()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/parse/response/message/MessageTypingStateParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.message; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.messages.MessageTypingState; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class MessageTypingStateParseTest { 11 | @Test 12 | void messageTypingState() { 13 | Update event = ParseUtil.getFirstEvent("json/response/message_typing_state/message_typing_state_sample_5_111.json"); 14 | assertEquals(Update.Type.MESSAGE_TYPING_STATE, event.getType()); 15 | 16 | Update.Object object = event.getObject(); 17 | assertNotNull(object); 18 | assertTrue(object instanceof MessageTypingState); 19 | 20 | MessageTypingState messageTypingState = (MessageTypingState) object; 21 | assertEquals("typing", messageTypingState.getState()); 22 | assertEquals(789, messageTypingState.getFromId()); 23 | assertEquals(-456, messageTypingState.getToId()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/utils/VkMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.utils; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Properties; 6 | 7 | /** 8 | * Gets VK method URLs. 9 | */ 10 | public class VkMethods { 11 | /** 12 | * Path to VK methods list. 13 | */ 14 | private static final String VK_METHODS_PATH = "/vk/vk_methods.properties"; 15 | 16 | /** 17 | * {@link Properties} object. 18 | */ 19 | private static final Properties PROPERTIES = new Properties(); 20 | 21 | /** 22 | * Gets VK method URL by key. 23 | * 24 | * @param key method key. 25 | * @return VK method URL. 26 | */ 27 | public static String get(String key) { 28 | if (PROPERTIES.isEmpty()) { 29 | try (InputStream inputStream = VkMethods.class.getResourceAsStream(VK_METHODS_PATH)) { 30 | PROPERTIES.load(inputStream); 31 | } catch (IOException e) { 32 | throw new RuntimeException(e); 33 | } 34 | } 35 | return PROPERTIES.getProperty(key); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/parse/response/UpdatesParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response; 2 | 3 | import api.longpoll.bots.methods.impl.events.GetUpdates; 4 | import api.longpoll.bots.model.events.Update; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.util.List; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | import static org.junit.jupiter.api.Assertions.assertNotNull; 11 | import static org.junit.jupiter.api.Assertions.assertTrue; 12 | 13 | public class UpdatesParseTest { 14 | @Test 15 | void emptyUpdatesParse() { 16 | GetUpdates.ResponseBody responseBody = ParseUtil.getEventsResult("json/response/empty_updates_sample_5_110.json"); 17 | assertEquals(2587, responseBody.getTs()); 18 | 19 | List events = responseBody.getEvents(); 20 | assertNotNull(events); 21 | assertTrue(events.isEmpty()); 22 | } 23 | 24 | @Test 25 | void updatesFailed() { 26 | GetUpdates.ResponseBody responseBody = ParseUtil.getEventsResult("json/response/get_updates_failed_1_5_110.json"); 27 | assertEquals(2593, responseBody.getTs()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Yevhen Vasyliev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/messages/MessageAllow.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.messages; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes message_allow event object. 8 | */ 9 | public class MessageAllow implements Update.Object { 10 | /** 11 | * User ID. 12 | */ 13 | @SerializedName("user_id") 14 | private Integer userId; 15 | 16 | /** 17 | * Key parameter. 18 | */ 19 | @SerializedName("key") 20 | private String key; 21 | 22 | public Integer getUserId() { 23 | return userId; 24 | } 25 | 26 | public void setUserId(Integer userId) { 27 | this.userId = userId; 28 | } 29 | 30 | public String getKey() { 31 | return key; 32 | } 33 | 34 | public void setKey(String key) { 35 | this.key = key; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "MessageAllowEvent{" + 41 | "userId=" + userId + 42 | ", key=" + key + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/groups/EnableOnline.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.groups; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements groups.enableOnline method. 9 | *

10 | * Enables "online" status in the community. 11 | * 12 | * @see https://vk.com/dev/groups.enableOnline 13 | */ 14 | public class EnableOnline extends VkMethod { 15 | public EnableOnline(String accessToken) { 16 | super(VkMethods.get("groups.enableOnline"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public EnableOnline setGroupId(int groupId) { 25 | return addParam("group_id", groupId); 26 | } 27 | 28 | @Override 29 | public EnableOnline addParam(String key, Object value) { 30 | return (EnableOnline) super.addParam(key, value); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/groups/DisableOnline.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.groups; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements groups.disableOnline method. 9 | *

10 | * Disables "online" status in the community. 11 | * 12 | * @see https://vk.com/dev/groups.disableOnline 13 | */ 14 | public class DisableOnline extends VkMethod { 15 | public DisableOnline(String accessToken) { 16 | super(VkMethods.get("groups.disableOnline"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public DisableOnline setGroupId(int groupId) { 25 | return addParam("group_id", groupId); 26 | } 27 | 28 | @Override 29 | public DisableOnline addParam(String key, Object value) { 30 | return (DisableOnline) super.addParam(key, value); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/VkList.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Describes VK list. 9 | * 10 | * @see Lists 11 | */ 12 | public class VkList { 13 | /** 14 | * The total number of elements. 15 | */ 16 | @SerializedName("count") 17 | private Integer count; 18 | 19 | /** 20 | * List of element objects. 21 | */ 22 | @SerializedName("items") 23 | private List items; 24 | 25 | public Integer getCount() { 26 | return count; 27 | } 28 | 29 | public void setCount(Integer count) { 30 | this.count = count; 31 | } 32 | 33 | public List getItems() { 34 | return items; 35 | } 36 | 37 | public void setItems(List items) { 38 | this.items = items; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "VkList{" + 44 | "count=" + count + 45 | ", items=" + items + 46 | '}'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_start_button_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2961", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1604253831, 9 | "from_id": 111111111, 10 | "id": 459, 11 | "out": 0, 12 | "peer_id": 222222222, 13 | "text": "Начать", 14 | "conversation_message_id": 1, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [], 19 | "payload": "{\"command\":\"start\"}", 20 | "is_hidden": false 21 | }, 22 | "client_info": { 23 | "button_actions": [ 24 | "text", 25 | "vkpay", 26 | "open_app", 27 | "location", 28 | "open_link" 29 | ], 30 | "keyboard": true, 31 | "inline_keyboard": true, 32 | "carousel": false, 33 | "lang_id": 0 34 | } 35 | }, 36 | "group_id": 333333333, 37 | "event_id": "3a7298e4f23cf007a7d6709cc14323d7f2990349" 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/Unpin.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.unpin method. 9 | *

10 | * Unpins message. 11 | * 12 | * @see https://vk.com/dev/messages.unpin 13 | */ 14 | public class Unpin extends VkMethod { 15 | public Unpin(String accessToken) { 16 | super(VkMethods.get("messages.unpin"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public Unpin setPeerId(int peerId) { 25 | return addParam("peer_id", peerId); 26 | } 27 | 28 | public Unpin setGroupId(int groupId) { 29 | return addParam("group_id", groupId); 30 | } 31 | 32 | @Override 33 | public Unpin addParam(String key, Object value) { 34 | return (Unpin) super.addParam(key, value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/parse/response/board/BoardPostDeleteParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.board; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.boards.BoardPostDelete; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class BoardPostDeleteParseTest { 11 | @Test 12 | void boardReplyNew() { 13 | Update event = ParseUtil.getFirstEvent("json/response/board_post_delete/board_post_delete_sample_5_110.json"); 14 | assertEquals(Update.Type.BOARD_POST_DELETE, event.getType()); 15 | assertEquals(123, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | 21 | assertTrue(object instanceof BoardPostDelete); 22 | BoardPostDelete boardPostDeleteUpdate = (BoardPostDelete) object; 23 | assertEquals(-111, boardPostDeleteUpdate.getTopicOwnerId()); 24 | assertEquals(3, boardPostDeleteUpdate.getId()); 25 | assertEquals(333, boardPostDeleteUpdate.getTopicId()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/wall/OpenComments.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.wall; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements wall.openComments method. 9 | * 10 | * @see https://vk.com/dev/wall.openComments 11 | */ 12 | public class OpenComments extends VkMethod { 13 | public OpenComments(String accessToken) { 14 | super(VkMethods.get("wall.openComments"), accessToken); 15 | } 16 | 17 | @Override 18 | protected Class getResponseClass() { 19 | return IntegerResponseBody.class; 20 | } 21 | 22 | public OpenComments setOwnerId(int ownerId) { 23 | return addParam("owner_id", ownerId); 24 | } 25 | 26 | public OpenComments setPostId(int postId) { 27 | return addParam("post_id", postId); 28 | } 29 | 30 | @Override 31 | public OpenComments addParam(String key, Object value) { 32 | return (OpenComments) super.addParam(key, value); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/parse/response/likes/LikeAddParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.likes; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.likes.Like; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class LikeAddParseTest { 11 | @Test 12 | void likeAdd() { 13 | Update event = ParseUtil.getFirstEvent("json/response/like_add/like_add_sample_5_110.json"); 14 | assertEquals(Update.Type.LIKE_ADD, event.getType()); 15 | assertEquals(333, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | 21 | assertTrue(object instanceof Like); 22 | Like audio = (Like) object; 23 | assertEquals(111, audio.getLikerId()); 24 | assertEquals("post", audio.getObjectType()); 25 | assertEquals(-222, audio.getObjectOwnerId()); 26 | assertEquals(3, audio.getObjectId()); 27 | assertEquals(0, audio.getThreadReplyId()); 28 | assertEquals(0, audio.getPostId()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/wall/CloseComments.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.wall; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements wall.closeComments method. 9 | * 10 | * @see https://vk.com/dev/wall.closeComments 11 | */ 12 | public class CloseComments extends VkMethod { 13 | public CloseComments(String accessToken) { 14 | super(VkMethods.get("wall.closeComments"), accessToken); 15 | } 16 | 17 | @Override 18 | protected Class getResponseClass() { 19 | return IntegerResponseBody.class; 20 | } 21 | 22 | public CloseComments setOwnerId(int ownerId) { 23 | return addParam("owner_id", ownerId); 24 | } 25 | 26 | public CloseComments setPostId(int postId) { 27 | return addParam("post_id", postId); 28 | } 29 | 30 | @Override 31 | public CloseComments addParam(String key, Object value) { 32 | return (CloseComments) super.addParam(key, value); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/users/GroupJoin.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.users; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes group_join event objects. 8 | */ 9 | public class GroupJoin implements Update.Object { 10 | /** 11 | * User ID. 12 | */ 13 | @SerializedName("user_id") 14 | private Integer userId; 15 | 16 | /** 17 | * Shows how exactly the user has joined. 18 | */ 19 | @SerializedName("join_type") 20 | private String joinType; 21 | 22 | public Integer getUserId() { 23 | return userId; 24 | } 25 | 26 | public void setUserId(Integer userId) { 27 | this.userId = userId; 28 | } 29 | 30 | public String getJoinType() { 31 | return joinType; 32 | } 33 | 34 | public void setJoinType(String joinType) { 35 | this.joinType = joinType; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "GroupJoinEvent{" + 41 | "userId=" + userId + 42 | ", joinType='" + joinType + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/carousel/Carousel.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional.carousel; 2 | 3 | import api.longpoll.bots.model.objects.additional.Template; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | /** 10 | * Describes carousel template. 11 | */ 12 | public class Carousel extends Template { 13 | /** 14 | * A list of carousel elements. 15 | */ 16 | @SerializedName("elements") 17 | private List elements; 18 | 19 | public Carousel(Element... elements) { 20 | this(Arrays.asList(elements)); 21 | } 22 | 23 | public Carousel(List elements) { 24 | super("carousel"); 25 | this.elements = elements; 26 | } 27 | 28 | public List getElements() { 29 | return elements; 30 | } 31 | 32 | public void setElements(List elements) { 33 | this.elements = elements; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "Carousel{" + 39 | "elements=" + elements + 40 | "} " + super.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/EditChat.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.editChat method. 9 | *

10 | * Edits the title of a chat. 11 | * 12 | * @see https://vk.com/dev/messages.editChat 13 | */ 14 | public class EditChat extends VkMethod { 15 | public EditChat(String accessToken) { 16 | super(VkMethods.get("messages.editChat"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public EditChat setChatId(int chatId) { 25 | return addParam("chat_id", chatId); 26 | } 27 | 28 | public EditChat setTitle(String title) { 29 | return addParam("title", title); 30 | } 31 | 32 | @Override 33 | public EditChat addParam(String key, Object value) { 34 | return (EditChat) super.addParam(key, value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/Restore.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.restore method. 9 | *

10 | * Restores a deleted message. 11 | * 12 | * @see https://vk.com/dev/messages.restore 13 | */ 14 | public class Restore extends VkMethod { 15 | public Restore(String accessToken) { 16 | super(VkMethods.get("messages.restore"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public Restore setMessageId(int messageId) { 25 | return addParam("message_id", messageId); 26 | } 27 | 28 | public Restore setGroupId(int groupId) { 29 | return addParam("group_id", groupId); 30 | } 31 | 32 | @Override 33 | public Restore addParam(String key, Object value) { 34 | return (Restore) super.addParam(key, value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_bomb_sample_5_118.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "3494", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1623079373, 9 | "from_id": 123, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 2000000008, 13 | "text": "bomb", 14 | "conversation_message_id": 20, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [], 19 | "is_hidden": false, 20 | "expire_ttl": 15 21 | }, 22 | "client_info": { 23 | "button_actions": [ 24 | "text", 25 | "vkpay", 26 | "open_app", 27 | "location", 28 | "open_link", 29 | "callback", 30 | "intent_subscribe", 31 | "intent_unsubscribe" 32 | ], 33 | "keyboard": true, 34 | "inline_keyboard": true, 35 | "carousel": true, 36 | "lang_id": 0 37 | } 38 | }, 39 | "group_id": 321, 40 | "event_id": "5302d228b5bc407db1fc42d91f4376e6c31d4b1b" 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/groups/DeleteAddress.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.groups; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements groups.deleteAddress method. 9 | * 10 | * @see https://vk.com/dev/groups.deleteAddress 11 | */ 12 | public class DeleteAddress extends VkMethod { 13 | public DeleteAddress(String accessToken) { 14 | super(VkMethods.get("groups.deleteAddress"), accessToken); 15 | } 16 | 17 | @Override 18 | protected Class getResponseClass() { 19 | return IntegerResponseBody.class; 20 | } 21 | 22 | public DeleteAddress setGroupId(int groupId) { 23 | return addParam("group_id", groupId); 24 | } 25 | 26 | public DeleteAddress setAddressId(int addressId) { 27 | return addParam("address_id", addressId); 28 | } 29 | 30 | @Override 31 | public DeleteAddress addParam(String key, Object value) { 32 | return (DeleteAddress) super.addParam(key, value); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/DocsMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.docs.GetMessagesUploadServer; 4 | import api.longpoll.bots.methods.impl.docs.GetWallUploadServer; 5 | import api.longpoll.bots.methods.impl.docs.Save; 6 | import api.longpoll.bots.methods.impl.docs.Search; 7 | 8 | import java.util.function.Supplier; 9 | 10 | /** 11 | * Provides Docs methods. 12 | */ 13 | public class DocsMethods { 14 | /** 15 | * {@code access_token}. 16 | */ 17 | private final Supplier accessTokenSupplier; 18 | 19 | public DocsMethods(Supplier accessTokenSupplier) { 20 | this.accessTokenSupplier = accessTokenSupplier; 21 | } 22 | 23 | public GetMessagesUploadServer getMessagesUploadServer() { 24 | return new GetMessagesUploadServer(accessTokenSupplier.get()); 25 | } 26 | 27 | public GetWallUploadServer getWallUploadServer() { 28 | return new GetWallUploadServer(accessTokenSupplier.get()); 29 | } 30 | 31 | public Save save() { 32 | return new Save(accessTokenSupplier.get()); 33 | } 34 | 35 | public Search search() { 36 | return new Search(accessTokenSupplier.get()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/MarketMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.market.EditOrder; 4 | import api.longpoll.bots.methods.impl.market.GetGroupOrders; 5 | import api.longpoll.bots.methods.impl.market.GetOrderById; 6 | import api.longpoll.bots.methods.impl.market.GetOrderItems; 7 | 8 | import java.util.function.Supplier; 9 | 10 | /** 11 | * Provides Market methods. 12 | */ 13 | public class MarketMethods { 14 | /** 15 | * {@code access_token}. 16 | */ 17 | private final Supplier accessTokenSupplier; 18 | 19 | public MarketMethods(Supplier accessTokenSupplier) { 20 | this.accessTokenSupplier = accessTokenSupplier; 21 | } 22 | 23 | public EditOrder editOrder() { 24 | return new EditOrder(accessTokenSupplier.get()); 25 | } 26 | 27 | public GetGroupOrders getGroupOrders() { 28 | return new GetGroupOrders(accessTokenSupplier.get()); 29 | } 30 | 31 | public GetOrderById getOrderById() { 32 | return new GetOrderById(accessTokenSupplier.get()); 33 | } 34 | 35 | public GetOrderItems getOrderItems() { 36 | return new GetOrderItems(accessTokenSupplier.get()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/stories/HideReply.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.stories; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements stories.hideReply method. 9 | *

10 | * Hides the reply to the current user's story. 11 | * 12 | * @see https://vk.com/dev/stories.hideReply 13 | */ 14 | public class HideReply extends VkMethod { 15 | public HideReply(String accessToken) { 16 | super(VkMethods.get("stories.hideReply"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public HideReply setOwnerId(int ownerId) { 25 | return addParam("owner_id", ownerId); 26 | } 27 | 28 | public HideReply setStoryId(int storyId) { 29 | return addParam("story_id", storyId); 30 | } 31 | 32 | @Override 33 | public HideReply addParam(String key, Object value) { 34 | return (HideReply) super.addParam(key, value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/other/GroupChangePhoto.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.other; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.objects.media.Photo; 5 | import com.google.gson.annotations.SerializedName; 6 | 7 | /** 8 | * Describes group_change_photo event objects. 9 | */ 10 | public class GroupChangePhoto implements Update.Object { 11 | /** 12 | * ID of the user who made changes. 13 | */ 14 | @SerializedName("user_id") 15 | private Integer userId; 16 | 17 | /** 18 | * Photo object. 19 | */ 20 | @SerializedName("photo") 21 | private Photo photo; 22 | 23 | public Integer getUserId() { 24 | return userId; 25 | } 26 | 27 | public void setUserId(Integer userId) { 28 | this.userId = userId; 29 | } 30 | 31 | public Photo getPhoto() { 32 | return photo; 33 | } 34 | 35 | public void setPhoto(Photo photo) { 36 | this.photo = photo; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "GroupChangePhotoEvent{" + 42 | "userId=" + userId + 43 | ", photo=" + photo + 44 | '}'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/parse/response/wall/WallCommentDeleteParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.wall; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.wall.comments.WallReplyDelete; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class WallCommentDeleteParseTest { 11 | @Test 12 | void wallReplyDelete() { 13 | Update event = ParseUtil.getFirstEvent("json/response/wall_reply_delete/wall_reply_delete_sample_5_110.json"); 14 | assertEquals(Update.Type.WALL_REPLY_DELETE, event.getType()); 15 | assertEquals(333, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | assertTrue(object instanceof WallReplyDelete); 21 | 22 | WallReplyDelete wallReplyDeleteUpdate = (WallReplyDelete) object; 23 | assertEquals(-111, wallReplyDeleteUpdate.getOwnerId()); 24 | assertEquals(4, wallReplyDeleteUpdate.getId()); 25 | assertEquals(222, wallReplyDeleteUpdate.getDeleterId()); 26 | assertEquals(3, wallReplyDeleteUpdate.getPostId()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_geo_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2602", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1594229206, 9 | "from_id": 111, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 222, 13 | "text": "", 14 | "conversation_message_id": 4406, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [], 19 | "geo": { 20 | "type": "point", 21 | "coordinates": { 22 | "latitude": 23.431881, 23 | "longitude": 7.031246 24 | } 25 | }, 26 | "is_hidden": false 27 | }, 28 | "client_info": { 29 | "button_actions": [ 30 | "text", 31 | "vkpay", 32 | "open_app", 33 | "location", 34 | "open_link" 35 | ], 36 | "keyboard": true, 37 | "inline_keyboard": true, 38 | "carousel": false, 39 | "lang_id": 0 40 | } 41 | }, 42 | "group_id": 333, 43 | "event_id": "aaa" 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/docs/GetWallUploadServer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.docs; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.utils.VkMethods; 5 | 6 | /** 7 | * Implements docs.getWallUploadServer method. 8 | * 9 | * @see https://vk.com/dev/docs.getWallUploadServer 10 | */ 11 | public class GetWallUploadServer extends VkMethod { 12 | public GetWallUploadServer(String accessToken) { 13 | super(VkMethods.get("docs.getWallUploadServer"), accessToken); 14 | } 15 | 16 | @Override 17 | protected Class getResponseClass() { 18 | return ResponseBody.class; 19 | } 20 | 21 | public GetWallUploadServer setGroupId(int groupId) { 22 | return addParam("group_id", groupId); 23 | } 24 | 25 | @Override 26 | public GetWallUploadServer addParam(String key, Object value) { 27 | return (GetWallUploadServer) super.addParam(key, value); 28 | } 29 | 30 | /** 31 | * Response to docs.getWallUploadServer request. 32 | */ 33 | public static class ResponseBody extends GetMessagesUploadServer.ResponseBody { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/parse/response/video/VideoCommentDeleteParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.video; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.video.VideoCommentDelete; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class VideoCommentDeleteParseTest { 11 | @Test 12 | void videoCommentDelete() { 13 | Update event = ParseUtil.getFirstEvent("json/response/video_comment_delete/video_comment_delete_sample_5_110.json"); 14 | assertEquals(Update.Type.VIDEO_COMMENT_DELETE, event.getType()); 15 | assertEquals(444, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | assertTrue(object instanceof VideoCommentDelete); 21 | 22 | VideoCommentDelete videoCommentDeleteUpdate = (VideoCommentDelete) object; 23 | assertEquals(1, videoCommentDeleteUpdate.getId()); 24 | assertEquals(-111, videoCommentDeleteUpdate.getOwnerId()); 25 | assertEquals(222, videoCommentDeleteUpdate.getDeleterId()); 26 | assertEquals(333, videoCommentDeleteUpdate.getVideoId()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/http/PathRequestBody.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.http; 2 | 3 | import okhttp3.MediaType; 4 | import okhttp3.RequestBody; 5 | import okio.BufferedSink; 6 | import okio.Okio; 7 | import okio.Source; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.io.IOException; 12 | import java.net.HttpURLConnection; 13 | import java.nio.file.Path; 14 | 15 | /** 16 | * Wraps {@link Path} into {@link RequestBody}. 17 | */ 18 | public class PathRequestBody extends RequestBody { 19 | /** 20 | * File. 21 | */ 22 | private final Path path; 23 | 24 | /** 25 | * Content-Type. 26 | */ 27 | private final MediaType contentType; 28 | 29 | public PathRequestBody(Path path) { 30 | this.path = path; 31 | this.contentType = MediaType.get(HttpURLConnection.guessContentTypeFromName(path.getFileName().toString())); 32 | } 33 | 34 | @Nullable 35 | @Override 36 | public MediaType contentType() { 37 | return contentType; 38 | } 39 | 40 | @Override 41 | public void writeTo(@NotNull BufferedSink bufferedSink) throws IOException { 42 | try (Source source = Okio.source(path)) { 43 | bufferedSink.writeAll(source); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/parse/response/board/BoardReplyNewParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.board; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.boards.BoardPost; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class BoardReplyNewParseTest { 11 | @Test 12 | void boardReplyNew() { 13 | Update event = ParseUtil.getFirstEvent("json/response/board_post_new/board_post_new_sample_5_110.json"); 14 | assertEquals(Update.Type.BOARD_POST_NEW, event.getType()); 15 | assertEquals(444, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | 21 | assertTrue(object instanceof BoardPost); 22 | BoardPost boardPostUpdate = (BoardPost) object; 23 | assertEquals(2, boardPostUpdate.getId()); 24 | assertEquals(111, boardPostUpdate.getFromId()); 25 | assertEquals(1595841380, boardPostUpdate.getDate()); 26 | assertEquals("test", boardPostUpdate.getText()); 27 | assertEquals(-222, boardPostUpdate.getTopicOwnerId()); 28 | assertEquals(333, boardPostUpdate.getTopicId()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_reply_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2589", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1593093610, 9 | "from_id": 111, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 222, 13 | "text": "test", 14 | "conversation_message_id": 4393, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [], 19 | "is_hidden": false, 20 | "reply_message": { 21 | "date": 1593092313, 22 | "from_id": 333, 23 | "text": "test", 24 | "attachments": [], 25 | "conversation_message_id": 4392, 26 | "peer_id": 444, 27 | "id": 555 28 | } 29 | }, 30 | "client_info": { 31 | "button_actions": [ 32 | "text", 33 | "vkpay", 34 | "open_app", 35 | "location", 36 | "open_link" 37 | ], 38 | "keyboard": true, 39 | "inline_keyboard": true, 40 | "lang_id": 0 41 | } 42 | }, 43 | "group_id": 666, 44 | "event_id": "aaa" 45 | } 46 | ] 47 | } -------------------------------------------------------------------------------- /src/test/java/parse/response/board/BoardPostEditParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.board; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.boards.BoardPost; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class BoardPostEditParseTest { 11 | @Test 12 | void boardReplyNew() { 13 | Update event = ParseUtil.getFirstEvent("json/response/board_post_edit/board_post_edit_sample_5_110.json"); 14 | assertEquals(Update.Type.BOARD_POST_EDIT, event.getType()); 15 | assertEquals(333, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | 21 | assertTrue(object instanceof BoardPost); 22 | BoardPost boardPostUpdate = (BoardPost) object; 23 | assertEquals(2, boardPostUpdate.getId()); 24 | assertEquals(123, boardPostUpdate.getFromId()); 25 | assertEquals(1595841380, boardPostUpdate.getDate()); 26 | assertEquals("testtest", boardPostUpdate.getText()); 27 | assertEquals(-111, boardPostUpdate.getTopicOwnerId()); 28 | assertEquals(222, boardPostUpdate.getTopicId()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/stories/Save.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.stories; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.additional.Story; 5 | import api.longpoll.bots.model.objects.additional.VkList; 6 | import api.longpoll.bots.model.response.GenericResponseBody; 7 | import api.longpoll.bots.utils.VkMethods; 8 | 9 | /** 10 | * Implements stories.save method. 11 | * 12 | * @see https://vk.com/dev/stories.save 13 | */ 14 | public class Save extends VkMethod { 15 | public Save(String accessToken) { 16 | super(VkMethods.get("stories.save"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return ResponseBody.class; 22 | } 23 | 24 | public Save setUploadResults(String uploadResults) { 25 | return addParam("upload_results", uploadResults); 26 | } 27 | 28 | @Override 29 | public Save addParam(String key, Object value) { 30 | return (Save) super.addParam(key, value); 31 | } 32 | 33 | /** 34 | * Response to stories.get 35 | */ 36 | public static class ResponseBody extends GenericResponseBody> { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/boards/BoardPost.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.boards; 2 | 3 | import api.longpoll.bots.model.objects.basic.TopicComment; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes board_post_new, board_post_edit and board_post_restore event objects. 8 | */ 9 | public class BoardPost extends TopicComment { 10 | /** 11 | * Topic ID. 12 | */ 13 | @SerializedName("topic_id") 14 | private Integer topicId; 15 | 16 | /** 17 | * Topic owner ID. 18 | */ 19 | @SerializedName("topic_owner_id") 20 | private Integer topicOwnerId; 21 | 22 | public Integer getTopicId() { 23 | return topicId; 24 | } 25 | 26 | public void setTopicId(Integer topicId) { 27 | this.topicId = topicId; 28 | } 29 | 30 | public Integer getTopicOwnerId() { 31 | return topicOwnerId; 32 | } 33 | 34 | public void setTopicOwnerId(Integer topicOwnerId) { 35 | this.topicOwnerId = topicOwnerId; 36 | } 37 | 38 | 39 | @Override 40 | public String toString() { 41 | return "BoardPostEvent{" + 42 | "topicId=" + topicId + 43 | ", topicOwnerId=" + topicOwnerId + 44 | "} " + super.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_fwd_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2590", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1593094646, 9 | "from_id": 111, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 222, 13 | "text": "", 14 | "conversation_message_id": 4394, 15 | "fwd_messages": [ 16 | { 17 | "date": 1590523631, 18 | "from_id": 333, 19 | "text": "testFwd", 20 | "attachments": [], 21 | "conversation_message_id": 102248, 22 | "peer_id": 444, 23 | "id": 555 24 | } 25 | ], 26 | "important": false, 27 | "random_id": 0, 28 | "attachments": [], 29 | "is_hidden": false 30 | }, 31 | "client_info": { 32 | "button_actions": [ 33 | "text", 34 | "vkpay", 35 | "open_app", 36 | "location", 37 | "open_link" 38 | ], 39 | "keyboard": true, 40 | "inline_keyboard": true, 41 | "lang_id": 0 42 | } 43 | }, 44 | "group_id": 666, 45 | "event_id": "aaa" 46 | } 47 | ] 48 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/http/InputStreamRequestBody.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.http; 2 | 3 | import okhttp3.MediaType; 4 | import okhttp3.RequestBody; 5 | import okio.BufferedSink; 6 | import okio.Okio; 7 | import okio.Source; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.net.URLConnection; 14 | 15 | /** 16 | * Wraps {@link InputStream} into {@link RequestBody}. 17 | */ 18 | public class InputStreamRequestBody extends RequestBody { 19 | /** 20 | * Content-Type. 21 | */ 22 | private final MediaType contentType; 23 | 24 | /** 25 | * File. 26 | */ 27 | private final InputStream file; 28 | 29 | public InputStreamRequestBody(String filename, InputStream file) { 30 | this.contentType = MediaType.get(URLConnection.guessContentTypeFromName(filename)); 31 | this.file = file; 32 | } 33 | 34 | @Nullable 35 | @Override 36 | public MediaType contentType() { 37 | return contentType; 38 | } 39 | 40 | @Override 41 | public void writeTo(@NotNull BufferedSink bufferedSink) throws IOException { 42 | try (Source source = Okio.source(file)) { 43 | bufferedSink.writeAll(source); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/stories/HideAllReplies.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.stories; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements stories.hideAllReplies method. 9 | *

10 | * Hides all replies in the last 24 hours from the user to current user's stories. 11 | * 12 | * @see https://vk.com/dev/stories.hideAllReplies 13 | */ 14 | public class HideAllReplies extends VkMethod { 15 | public HideAllReplies(String accessToken) { 16 | super(VkMethods.get("stories.hideAllReplies"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public HideAllReplies setOwnerId(int ownerId) { 25 | return addParam("owner_id", ownerId); 26 | } 27 | 28 | public HideAllReplies setGroupId(int groupId) { 29 | return addParam("group_id", groupId); 30 | } 31 | 32 | @Override 33 | public HideAllReplies addParam(String key, Object value) { 34 | return (HideAllReplies) super.addParam(key, value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/photos/PhotoComment.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.photos; 2 | 3 | import api.longpoll.bots.model.objects.basic.WallComment; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes photo_comment_new, photo_comment_edit and photo_comment_restore event objects. 8 | */ 9 | public class PhotoComment extends WallComment { 10 | /** 11 | * Photo ID. 12 | */ 13 | @SerializedName("photo_id") 14 | private Integer photoId; 15 | 16 | /** 17 | * Photo owner ID. 18 | */ 19 | @SerializedName("photo_owner_id") 20 | private Integer photoOwnerId; 21 | 22 | public Integer getPhotoId() { 23 | return photoId; 24 | } 25 | 26 | public void setPhotoId(Integer photoId) { 27 | this.photoId = photoId; 28 | } 29 | 30 | public Integer getPhotoOwnerId() { 31 | return photoOwnerId; 32 | } 33 | 34 | public void setPhotoOwnerId(Integer photoOwnerId) { 35 | this.photoOwnerId = photoOwnerId; 36 | } 37 | 38 | 39 | @Override 40 | public String toString() { 41 | return "PhotoCommentEvent{" + 42 | "photoId=" + photoId + 43 | ", photoOwnerId=" + photoOwnerId + 44 | "} " + super.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/video/VideoComment.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.video; 2 | 3 | import api.longpoll.bots.model.objects.basic.WallComment; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes video_comment_new, video_comment_edit and video_comment_restore event objects. 8 | */ 9 | public class VideoComment extends WallComment { 10 | /** 11 | * Video ID. 12 | */ 13 | @SerializedName("video_id") 14 | private Integer videoId; 15 | 16 | /** 17 | * Video owner ID. 18 | */ 19 | @SerializedName("video_owner_id") 20 | private Integer videoOwnerId; 21 | 22 | public Integer getVideoId() { 23 | return videoId; 24 | } 25 | 26 | public void setVideoId(Integer videoId) { 27 | this.videoId = videoId; 28 | } 29 | 30 | public Integer getVideoOwnerId() { 31 | return videoOwnerId; 32 | } 33 | 34 | public void setVideoOwnerId(Integer videoOwnerId) { 35 | this.videoOwnerId = videoOwnerId; 36 | } 37 | 38 | 39 | @Override 40 | public String toString() { 41 | return "VideoCommentEvent{" + 42 | "videoId=" + videoId + 43 | ", videoOwnerId=" + videoOwnerId + 44 | "} " + super.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_payload_sample_5_118.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "3464", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1622383770, 9 | "from_id": 918650328, 10 | "id": 844, 11 | "out": 0, 12 | "peer_id": 918650328, 13 | "text": "Click me", 14 | "conversation_message_id": 820, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [], 19 | "payload": "{\"data\":\"clicked\",\"time\":1622383763657,\"values\":[11,22,33],\"status\":{\"active\":true}}", 20 | "is_hidden": false 21 | }, 22 | "client_info": { 23 | "button_actions": [ 24 | "text", 25 | "vkpay", 26 | "open_app", 27 | "location", 28 | "open_link", 29 | "callback", 30 | "intent_subscribe", 31 | "intent_unsubscribe" 32 | ], 33 | "keyboard": true, 34 | "inline_keyboard": true, 35 | "carousel": true, 36 | "lang_id": 0 37 | } 38 | }, 39 | "group_id": 886761559, 40 | "event_id": "1a44b4b4ee2612d41e2860bbfda03201081b125d" 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/users/GroupLeave.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.users; 2 | 3 | import api.longpoll.bots.adapters.deserializers.BoolIntDeserializer; 4 | import api.longpoll.bots.model.events.Update; 5 | import com.google.gson.annotations.JsonAdapter; 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | /** 9 | * Describes group_leave event objects. 10 | */ 11 | public class GroupLeave implements Update.Object { 12 | /** 13 | * User ID. 14 | */ 15 | @SerializedName("user_id") 16 | private Integer userId; 17 | 18 | /** 19 | * true, if a user has left on his own. 20 | */ 21 | @SerializedName("self") 22 | @JsonAdapter(BoolIntDeserializer.class) 23 | private Boolean self; 24 | 25 | public Integer getUserId() { 26 | return userId; 27 | } 28 | 29 | public void setUserId(Integer userId) { 30 | this.userId = userId; 31 | } 32 | 33 | public Boolean getSelf() { 34 | return self; 35 | } 36 | 37 | public void setSelf(Boolean self) { 38 | this.self = self; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "GroupLeaveEvent{" + 44 | "userId=" + userId + 45 | ", self=" + self + 46 | '}'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/parse/response/audio/AudioNewParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.audio; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.objects.media.Audio; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class AudioNewParseTest { 11 | @Test 12 | void audioNew() { 13 | Update event = ParseUtil.getFirstEvent("json/response/audio_new/audio_new_sample_5_110.json"); 14 | assertEquals(Update.Type.AUDIO_NEW, event.getType()); 15 | assertEquals(123, event.getGroupId()); 16 | assertEquals("abc", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | 21 | assertTrue(object instanceof Audio); 22 | Audio audio = (Audio) object; 23 | assertEquals("Rick Astley", audio.getArtist()); 24 | assertEquals(456239017, audio.getId()); 25 | assertEquals(-111, audio.getOwnerId()); 26 | assertEquals("Never Gonna Give You Up", audio.getTitle()); 27 | assertEquals(211, audio.getDuration()); 28 | String url = audio.getUrl(); 29 | assertNotNull(url); 30 | assertTrue(url.isEmpty()); 31 | assertEquals(1594822421, audio.getDate()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/market/MarketComment.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.market; 2 | 3 | import api.longpoll.bots.model.objects.basic.WallComment; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes market_comment_new, market_comment_edit and market_comment_restore event objects. 8 | */ 9 | public class MarketComment extends WallComment { 10 | /** 11 | * Market owner ID. 12 | */ 13 | @SerializedName("market_owner_id") 14 | private Integer marketOwnerId; 15 | 16 | /** 17 | * Market item ID. 18 | */ 19 | @SerializedName("item_id") 20 | private Integer itemId; 21 | 22 | public Integer getMarketOwnerId() { 23 | return marketOwnerId; 24 | } 25 | 26 | public void setMarketOwnerId(Integer marketOwnerId) { 27 | this.marketOwnerId = marketOwnerId; 28 | } 29 | 30 | public Integer getItemId() { 31 | return itemId; 32 | } 33 | 34 | public void setItemId(Integer itemId) { 35 | this.itemId = itemId; 36 | } 37 | 38 | 39 | @Override 40 | public String toString() { 41 | return "MarketCommentEvent{" + 42 | "marketOwnerId=" + marketOwnerId + 43 | ", itemId=" + itemId + 44 | "} " + super.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/parse/response/message/MessageReplyParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.message; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.objects.basic.Message; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class MessageReplyParseTest { 11 | @Test 12 | void messageEdit() { 13 | Update event = ParseUtil.getFirstEvent("json/response/message_reply/message_reply_sample_5_110.json"); 14 | assertEquals(Update.Type.MESSAGE_REPLY, event.getType()); 15 | assertEquals(555, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | assertTrue(object instanceof Message); 21 | 22 | Message message = (Message) object; 23 | assertEquals(1594282112, message.getDate()); 24 | assertEquals(111, message.getFromId()); 25 | assertEquals(222, message.getId()); 26 | assertEquals(333, message.getPeerId()); 27 | assertEquals("test", message.getText()); 28 | assertEquals(261, message.getConversationMessageId()); 29 | assertFalse(message.getImportant()); 30 | assertEquals(0, message.getRandomId()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/parse/response/photo/PhotoCommentDeleteParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.photo; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.photos.PhotoCommentDelete; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class PhotoCommentDeleteParseTest { 11 | @Test 12 | void messageEdit() { 13 | Update event = ParseUtil.getFirstEvent("json/response/photo_comment_delete/photo_comment_delete_sample_5_110.json"); 14 | assertEquals(Update.Type.PHOTO_COMMENT_DELETE, event.getType()); 15 | assertEquals(666, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | assertTrue(object instanceof PhotoCommentDelete); 21 | 22 | PhotoCommentDelete photoCommentDeleteUpdate = (PhotoCommentDelete) object; 23 | assertEquals(-111, photoCommentDeleteUpdate.getOwnerId()); 24 | assertEquals(333, photoCommentDeleteUpdate.getId()); 25 | assertEquals(222, photoCommentDeleteUpdate.getDeleterId()); 26 | assertEquals(444, photoCommentDeleteUpdate.getPhotoId()); 27 | assertEquals(555, photoCommentDeleteUpdate.getUserId()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/Image.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes Image objects. 7 | */ 8 | public class Image { 9 | /** 10 | * Image URL. 11 | */ 12 | @SerializedName("url") 13 | private String url; 14 | /** 15 | * Image width. 16 | */ 17 | @SerializedName("width") 18 | private Integer width; 19 | 20 | /** 21 | * Image height. 22 | */ 23 | @SerializedName("height") 24 | private Integer height; 25 | 26 | public String getUrl() { 27 | return url; 28 | } 29 | 30 | public void setUrl(String url) { 31 | this.url = url; 32 | } 33 | 34 | public Integer getWidth() { 35 | return width; 36 | } 37 | 38 | public void setWidth(Integer width) { 39 | this.width = width; 40 | } 41 | 42 | public Integer getHeight() { 43 | return height; 44 | } 45 | 46 | public void setHeight(Integer height) { 47 | this.height = height; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "Image{" + 53 | "url='" + url + '\'' + 54 | ", width=" + width + 55 | ", height=" + height + 56 | '}'; 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/groups/DeleteCallbackServer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.groups; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements groups.deleteCallbackServer method. 9 | *

10 | * Deletes Callback API server from the community. 11 | * 12 | * @see https://vk.com/dev/groups.deleteCallbackServer 13 | */ 14 | public class DeleteCallbackServer extends VkMethod { 15 | public DeleteCallbackServer(String accessToken) { 16 | super(VkMethods.get("groups.deleteCallbackServer"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public DeleteCallbackServer setGroupId(int groupId) { 25 | return addParam("group_id", groupId); 26 | } 27 | 28 | public DeleteCallbackServer setServerId(int serverId) { 29 | return addParam("server_id", serverId); 30 | } 31 | 32 | @Override 33 | public DeleteCallbackServer addParam(String key, Object value) { 34 | return (DeleteCallbackServer) super.addParam(key, value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/parse/response/likes/LikeRemoveParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.likes; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.likes.Like; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import java.util.List; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | public class LikeRemoveParseTest { 13 | @Test 14 | void likeRemove() { 15 | List events = ParseUtil.getEvents("json/response/like_remove/like_remove_sample_5_110.json"); 16 | assertEquals(1, events.size()); 17 | 18 | Update event = events.get(0); 19 | assertNotNull(event); 20 | assertEquals(Update.Type.LIKE_REMOVE, event.getType()); 21 | assertEquals(333, event.getGroupId()); 22 | assertEquals("aaa", event.getEventId()); 23 | 24 | Update.Object object = event.getObject(); 25 | assertNotNull(object); 26 | 27 | assertTrue(object instanceof Like); 28 | Like audio = (Like) object; 29 | assertEquals(111, audio.getLikerId()); 30 | assertEquals("post", audio.getObjectType()); 31 | assertEquals(-222, audio.getObjectOwnerId()); 32 | assertEquals(3, audio.getObjectId()); 33 | assertEquals(0, audio.getThreadReplyId()); 34 | assertEquals(0, audio.getPostId()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/parse/response/message/MessageEditParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.message; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.objects.basic.Message; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class MessageEditParseTest { 11 | @Test 12 | void messageEdit() { 13 | Update event = ParseUtil.getFirstEvent("json/response/message_edit/message_edit_sample_5_110.json"); 14 | assertEquals(Update.Type.MESSAGE_EDIT, event.getType()); 15 | assertEquals(444, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | 21 | assertTrue(object instanceof Message); 22 | Message message = (Message) object; 23 | assertNotNull(message); 24 | assertEquals(1594282377, message.getDate()); 25 | assertEquals(-111, message.getFromId()); 26 | assertEquals(276, message.getId()); 27 | assertEquals(222, message.getPeerId()); 28 | assertEquals("tests", message.getText()); 29 | assertEquals(261, message.getConversationMessageId()); 30 | assertFalse(message.getImportant()); 31 | assertEquals(0, message.getRandomId()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/adapters/deserializers/CoordinatesDeserializer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.adapters.deserializers; 2 | 3 | import api.longpoll.bots.model.objects.additional.Geo; 4 | import com.google.gson.JsonDeserializationContext; 5 | import com.google.gson.JsonDeserializer; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonParseException; 8 | import com.google.gson.JsonPrimitive; 9 | 10 | import java.lang.reflect.Type; 11 | 12 | /** 13 | * Deserializes {@link Geo.Coordinates}. 14 | */ 15 | public class CoordinatesDeserializer implements JsonDeserializer { 16 | @Override 17 | public Geo.Coordinates deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { 18 | if (jsonElement.isJsonPrimitive()) { 19 | JsonPrimitive jsonPrimitive = jsonElement.getAsJsonPrimitive(); 20 | if (jsonPrimitive.isString()) { 21 | String[] coordinatesStr = jsonPrimitive.getAsString().split("\\s+"); 22 | 23 | Geo.Coordinates coordinates = new Geo.Coordinates(); 24 | coordinates.setLatitude(Float.parseFloat(coordinatesStr[0])); 25 | coordinates.setLongitude(Float.parseFloat(coordinatesStr[1])); 26 | return coordinates; 27 | } 28 | } 29 | 30 | return context.deserialize(jsonElement, type); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/UtilsMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.utils.CheckLink; 4 | import api.longpoll.bots.methods.impl.utils.GetLinkStats; 5 | import api.longpoll.bots.methods.impl.utils.GetServerTime; 6 | import api.longpoll.bots.methods.impl.utils.GetShortLink; 7 | import api.longpoll.bots.methods.impl.utils.ResolveScreenName; 8 | 9 | import java.util.function.Supplier; 10 | 11 | /** 12 | * Provides Utils methods. 13 | */ 14 | public class UtilsMethods { 15 | /** 16 | * {@code access_token}. 17 | */ 18 | private final Supplier accessTokenSupplier; 19 | 20 | public UtilsMethods(Supplier accessTokenSupplier) { 21 | this.accessTokenSupplier = accessTokenSupplier; 22 | } 23 | 24 | public CheckLink checkLink() { 25 | return new CheckLink(accessTokenSupplier.get()); 26 | } 27 | 28 | public GetLinkStats getLinkStats() { 29 | return new GetLinkStats(accessTokenSupplier.get()); 30 | } 31 | 32 | public GetServerTime getServerTime() { 33 | return new GetServerTime(accessTokenSupplier.get()); 34 | } 35 | 36 | public GetShortLink getShortLink() { 37 | return new GetShortLink(accessTokenSupplier.get()); 38 | } 39 | 40 | public ResolveScreenName resolveScreenName() { 41 | return new ResolveScreenName(accessTokenSupplier.get()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/other/Execute.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.other; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.GenericResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | import com.google.gson.JsonElement; 7 | 8 | /** 9 | * Implements execute method. 10 | *

11 | * A universal method for calling a sequence of other methods while saving and filtering interim results. 12 | * 13 | * @see https://vk.com/dev/execute 14 | */ 15 | public class Execute extends VkMethod { 16 | public Execute(String accessToken) { 17 | super(VkMethods.get("execute"), accessToken); 18 | } 19 | 20 | @Override 21 | protected Class getResponseClass() { 22 | return ResponseBody.class; 23 | } 24 | 25 | public Execute setCode(String code) { 26 | return addParam("code", code); 27 | } 28 | 29 | public Execute setFuncV(int funcV) { 30 | return addParam("func_v", funcV); 31 | } 32 | 33 | @Override 34 | public Execute addParam(String key, Object value) { 35 | return (Execute) super.addParam(key, value); 36 | } 37 | 38 | /** 39 | * Response to execute request. 40 | */ 41 | public static class ResponseBody extends GenericResponseBody { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/messages/MessageNew.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.messages; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.objects.additional.ClientInfo; 5 | import api.longpoll.bots.model.objects.basic.Message; 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | /** 9 | * Describes message_new, message_reply and message_edit event objects. 10 | */ 11 | public class MessageNew implements Update.Object { 12 | /** 13 | * Message object. 14 | */ 15 | @SerializedName("message") 16 | private Message message; 17 | 18 | /** 19 | * Information about features available to the user. 20 | */ 21 | @SerializedName("client_info") 22 | private ClientInfo clientInfo; 23 | 24 | public Message getMessage() { 25 | return message; 26 | } 27 | 28 | public void setMessage(Message message) { 29 | this.message = message; 30 | } 31 | 32 | public ClientInfo getClientInfo() { 33 | return clientInfo; 34 | } 35 | 36 | public void setClientInfo(ClientInfo clientInfo) { 37 | this.clientInfo = clientInfo; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "MessageNewEvent{" + 43 | "message=" + message + 44 | ", clientInfo=" + clientInfo + 45 | '}'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/parse/response/photo/PhotoNewParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.photo; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.objects.additional.PhotoSize; 5 | import api.longpoll.bots.model.objects.media.Photo; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import java.util.List; 10 | 11 | import static org.junit.jupiter.api.Assertions.*; 12 | 13 | public class PhotoNewParseTest { 14 | @Test 15 | void messageEdit() { 16 | Update event = ParseUtil.getFirstEvent("json/response/photo_new/photo_new_sample_5_110.json"); 17 | assertEquals(Update.Type.PHOTO_NEW, event.getType()); 18 | assertEquals(444, event.getGroupId()); 19 | assertEquals("aaa", event.getEventId()); 20 | 21 | Update.Object object = event.getObject(); 22 | assertNotNull(object); 23 | assertTrue(object instanceof Photo); 24 | 25 | Photo photo = (Photo) object; 26 | assertEquals(111, photo.getAlbumId()); 27 | assertEquals(1594284077, photo.getDate()); 28 | assertEquals(222, photo.getId()); 29 | assertEquals(-333, photo.getOwnerId()); 30 | assertFalse(photo.hasText()); 31 | assertEquals(555, photo.getUserId()); 32 | 33 | List photoSizes = photo.getPhotoSizes(); 34 | assertNotNull(photo); 35 | assertFalse(photoSizes.isEmpty()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/Pin.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.additional.PinnedMessage; 5 | import api.longpoll.bots.model.response.GenericResponseBody; 6 | import api.longpoll.bots.utils.VkMethods; 7 | 8 | /** 9 | * Implements messages.pin method. 10 | *

11 | * Pin the message 12 | * 13 | * @see https://vk.com/dev/messages.pin 14 | */ 15 | public class Pin extends VkMethod { 16 | public Pin(String accessToken) { 17 | super(VkMethods.get("messages.pin"), accessToken); 18 | } 19 | 20 | @Override 21 | protected Class getResponseClass() { 22 | return ResponseBody.class; 23 | } 24 | 25 | public Pin setPeerId(int peerId) { 26 | return addParam("peer_id", peerId); 27 | } 28 | 29 | public Pin setConversationMessageId(int conversationMessageId) { 30 | return addParam("conversation_message_id", conversationMessageId); 31 | } 32 | 33 | @Override 34 | public Pin addParam(String key, Object value) { 35 | return (Pin) super.addParam(key, value); 36 | } 37 | 38 | /** 39 | * Response to messages.pin request. 40 | */ 41 | public static class ResponseBody extends GenericResponseBody { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/response/ExtendedVkList.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.response; 2 | 3 | import api.longpoll.bots.model.objects.additional.VkList; 4 | import api.longpoll.bots.model.objects.basic.Community; 5 | import api.longpoll.bots.model.objects.basic.User; 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Describes Vk list with "profiles" and "groups" additional fields. 12 | * 13 | * @param type of items. 14 | */ 15 | public class ExtendedVkList extends VkList { 16 | /** 17 | * List of users. 18 | */ 19 | @SerializedName("profiles") 20 | private List profiles; 21 | 22 | /** 23 | * List of communities. 24 | */ 25 | @SerializedName("groups") 26 | private List groups; 27 | 28 | public List getProfiles() { 29 | return profiles; 30 | } 31 | 32 | public void setProfiles(List profiles) { 33 | this.profiles = profiles; 34 | } 35 | 36 | public List getGroups() { 37 | return groups; 38 | } 39 | 40 | public void setGroups(List groups) { 41 | this.groups = groups; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "ExtendedVkList{" + 47 | "profiles=" + profiles + 48 | ", groups=" + groups + 49 | "} " + super.toString(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/adapters/deserializers/SendResponseBodyDeserializer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.adapters.deserializers; 2 | 3 | import api.longpoll.bots.methods.impl.messages.Send; 4 | import com.google.gson.JsonDeserializationContext; 5 | import com.google.gson.JsonDeserializer; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonParseException; 8 | import com.google.gson.reflect.TypeToken; 9 | 10 | import java.lang.reflect.Type; 11 | import java.util.List; 12 | 13 | /** 14 | * Deserializes JSON object to {@link Send.ResponseBody}. 15 | */ 16 | public class SendResponseBodyDeserializer implements JsonDeserializer { 17 | @Override 18 | public Send.ResponseBody deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { 19 | JsonElement jsonResponse = jsonElement.getAsJsonObject().get("response"); 20 | 21 | Send.ResponseBody responseBody = new Send.ResponseBody(); 22 | responseBody.setResponse(deserializeResponse(jsonResponse, context)); 23 | return responseBody; 24 | } 25 | 26 | private Object deserializeResponse(JsonElement jsonResponse, JsonDeserializationContext context) { 27 | return jsonResponse.isJsonPrimitive() 28 | ? jsonResponse.getAsInt() 29 | : context.deserialize(jsonResponse, TypeToken.getParameterized(List.class, Send.ResponseBody.Response.class).getType()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_graffiti_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2597", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1593168730, 9 | "from_id": 111, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 222, 13 | "text": "", 14 | "conversation_message_id": 4401, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [ 19 | { 20 | "type": "graffiti", 21 | "graffiti": { 22 | "id": 333, 23 | "owner_id": 444, 24 | "url": "https://vk.com/doc381980625_538172633?hash=491cc01048edeb58f8&dl=GA:1593168730:3aaaa5d7bddbfa19d9&api=1&no_preview=1", 25 | "width": 720, 26 | "height": 714, 27 | "access_key": "aaa" 28 | } 29 | } 30 | ], 31 | "is_hidden": false 32 | }, 33 | "client_info": { 34 | "button_actions": [ 35 | "text", 36 | "vkpay", 37 | "open_app", 38 | "location", 39 | "open_link" 40 | ], 41 | "keyboard": true, 42 | "inline_keyboard": true, 43 | "lang_id": 0 44 | } 45 | }, 46 | "group_id": 555, 47 | "event_id": "aaa" 48 | } 49 | ] 50 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/receiving-vk-api-exeption.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Receiving VK API Exeption 3 | about: Create a report to help us improve the library 4 | title: Receiving VK API Exeption 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | I'm executing this request (replace with URI from your logs): `https://api.vk.com/method/messages.send` 11 | 12 | with parameters (replace with params from your logs): `access_token=*************************************************************************************&random_id=1413328727&message=Sending you message&v=5.131` 13 | 14 | and I'm receiving (replace with response from your logs): 15 | ```json 16 | {"error":{"error_code":100,"error_msg":"One of the parameters specified was missing or invalid: you should specify peer_id, user_id, domain, chat_id or user_ids param","request_params":[{"key":"method","value":"messages.send"},{"key":"oauth","value":"1"},{"key":"v","value":"5.131"},{"key":"random_id","value":"1413460573"}]}} 17 | ``` 18 | 19 | Here is the code example (replace with your code example): 20 | ```java 21 | public void sendMessage() throws VkApiException { 22 | Send.ResponseBody responseBody = vk.messages.send() 23 | .setMessage("Sending you message") 24 | .execute(); 25 | 26 | System.out.println("Response: " + responseBody); 27 | } 28 | ``` 29 | 30 | I'm using `java-vk-bots-longpoll-api` version (replace with version you are using): `3.1.1` 31 | 32 | Could you please help me to understand what is wrong here? 33 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/SetActivity.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.setActivity method. 9 | *

10 | * Changes the status of a user as typing in a conversation. 11 | * 12 | * @see https://vk.com/dev/messages.setActivity 13 | */ 14 | public class SetActivity extends VkMethod { 15 | public SetActivity(String accessToken) { 16 | super(VkMethods.get("messages.setActivity"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public SetActivity setUserId(int userId) { 25 | return addParam("user_id", userId); 26 | } 27 | 28 | public SetActivity setType(String type) { 29 | return addParam("type", type); 30 | } 31 | 32 | public SetActivity setPeerId(int peerId) { 33 | return addParam("peer_id", peerId); 34 | } 35 | 36 | public SetActivity setGroupId(int groupId) { 37 | return addParam("group_id", groupId); 38 | } 39 | 40 | @Override 41 | public SetActivity addParam(String key, Object value) { 42 | return (SetActivity) super.addParam(key, value); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/Price.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes price. 7 | * 8 | * @see Price 9 | */ 10 | public class Price { 11 | /** 12 | * Integer price value multiplied by 100. 13 | */ 14 | @SerializedName("amount") 15 | private Integer amount; 16 | 17 | /** 18 | * Price currency. 19 | */ 20 | @SerializedName("currency") 21 | private Currency currency; 22 | 23 | /** 24 | * Localized price and currency. 25 | */ 26 | @SerializedName("text") 27 | private String text; 28 | 29 | public Integer getAmount() { 30 | return amount; 31 | } 32 | 33 | public void setAmount(Integer amount) { 34 | this.amount = amount; 35 | } 36 | 37 | public Currency getCurrency() { 38 | return currency; 39 | } 40 | 41 | public void setCurrency(Currency currency) { 42 | this.currency = currency; 43 | } 44 | 45 | public String getText() { 46 | return text; 47 | } 48 | 49 | public void setText(String text) { 50 | this.text = text; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Price{" + 56 | "amount=" + amount + 57 | ", currency=" + currency + 58 | ", text='" + text + '\'' + 59 | '}'; 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/adapters/deserializers/PayloadDeserializer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.adapters.deserializers; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonDeserializationContext; 5 | import com.google.gson.JsonDeserializer; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonParseException; 8 | import com.google.gson.JsonSyntaxException; 9 | 10 | import java.lang.reflect.Type; 11 | 12 | /** 13 | * Deserializes JSON object to payload. 14 | */ 15 | public class PayloadDeserializer implements JsonDeserializer { 16 | /** 17 | * {@link Gson} object. 18 | */ 19 | private static final Gson GSON = new Gson(); 20 | 21 | @Override 22 | public JsonElement deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { 23 | return jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString() 24 | ? parseString(jsonElement) 25 | : jsonElement; 26 | } 27 | 28 | /** 29 | * Parses string. 30 | * 31 | * @param jsonElement string value. 32 | * @return JSON if provided string is a valid JSON, same string otherwise. 33 | */ 34 | private JsonElement parseString(JsonElement jsonElement) { 35 | try { 36 | return GSON.fromJson(jsonElement.getAsString(), JsonElement.class); 37 | } catch (JsonSyntaxException e) { 38 | return jsonElement; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/RemoveChatUser.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.removeChatUser method. 9 | *

10 | * Allows the current user to leave a chat or, if the current user started the chat, allows the user to remove another user from the chat. 11 | * 12 | * @see https://vk.com/dev/messages.removeChatUser 13 | */ 14 | public class RemoveChatUser extends VkMethod { 15 | public RemoveChatUser(String accessToken) { 16 | super(VkMethods.get("messages.removeChatUser"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public RemoveChatUser setChatId(int chatId) { 25 | return addParam("chat_id", chatId); 26 | } 27 | 28 | public RemoveChatUser setUserId(int userId) { 29 | return addParam("user_id", userId); 30 | } 31 | 32 | public RemoveChatUser setMemberId(int memberId) { 33 | return addParam("member_id", memberId); 34 | } 35 | 36 | @Override 37 | public RemoveChatUser addParam(String key, Object value) { 38 | return (RemoveChatUser) super.addParam(key, value); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/MarkAsAnsweredConversation.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.markAsAnsweredConversation method. 9 | * 10 | * @see https://vk.com/dev/messages.markAsAnsweredConversation 11 | */ 12 | public class MarkAsAnsweredConversation extends VkMethod { 13 | public MarkAsAnsweredConversation(String accessToken) { 14 | super(VkMethods.get("messages.markAsAnsweredConversation"), accessToken); 15 | } 16 | 17 | @Override 18 | protected Class getResponseClass() { 19 | return IntegerResponseBody.class; 20 | } 21 | 22 | public MarkAsAnsweredConversation setPeerId(int peerId) { 23 | return addParam("peer_id", peerId); 24 | } 25 | 26 | public MarkAsAnsweredConversation setAnswered(boolean answered) { 27 | return addParam("answered", answered ? 1 : 0); 28 | } 29 | 30 | public MarkAsAnsweredConversation setGroupId(int groupId) { 31 | return addParam("group_id", groupId); 32 | } 33 | 34 | @Override 35 | public MarkAsAnsweredConversation addParam(String key, Object value) { 36 | return (MarkAsAnsweredConversation) super.addParam(key, value); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/buttons/VKPayButton.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional.buttons; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * A button to open VK Pay window 8 | */ 9 | public class VKPayButton extends Button { 10 | public VKPayButton(Action action) { 11 | super(action); 12 | } 13 | 14 | /** 15 | * Describes action for button type of VK Pay. 16 | */ 17 | public static class Action extends Button.Action { 18 | /** 19 | * A string containing VK Pay payment parameters and the id of the app in the aid parameter, separated by &. 20 | * Example: action=transfer-to-group&group_id=1&aid=10 21 | */ 22 | @SerializedName("hash") 23 | private String hash; 24 | 25 | public Action(String hash) { 26 | this(hash, null); 27 | } 28 | 29 | public Action(String hash, JsonElement payload) { 30 | super("vkpay", payload); 31 | this.hash = hash; 32 | } 33 | 34 | public String getHash() { 35 | return hash; 36 | } 37 | 38 | public void setHash(String hash) { 39 | this.hash = hash; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Action{" + 45 | "hash='" + hash + '\'' + 46 | "} " + super.toString(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/MarkAsImportantConversation.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.markAsImportantConversation method. 9 | * 10 | * @see https://vk.com/dev/messages.markAsImportantConversation 11 | */ 12 | public class MarkAsImportantConversation extends VkMethod { 13 | public MarkAsImportantConversation(String accessToken) { 14 | super(VkMethods.get("messages.markAsImportantConversation"), accessToken); 15 | } 16 | 17 | @Override 18 | protected Class getResponseClass() { 19 | return IntegerResponseBody.class; 20 | } 21 | 22 | public MarkAsImportantConversation setPeerId(int peerId) { 23 | return addParam("peer_id", peerId); 24 | } 25 | 26 | public MarkAsImportantConversation setAnswered(boolean answered) { 27 | return addParam("answered", answered ? 1 : 0); 28 | } 29 | 30 | public MarkAsImportantConversation setGroupId(int groupId) { 31 | return addParam("group_id", groupId); 32 | } 33 | 34 | @Override 35 | public MarkAsImportantConversation addParam(String key, Object value) { 36 | return (MarkAsImportantConversation) super.addParam(key, value); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/groups/SetSettings.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.groups; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements groups.setSettings method. 9 | * 10 | * @see https://vk.com/dev/groups.setSettings 11 | */ 12 | public class SetSettings extends VkMethod { 13 | 14 | public SetSettings(String accessToken) { 15 | super(VkMethods.get("groups.setSettings"), accessToken); 16 | } 17 | 18 | @Override 19 | protected Class getResponseClass() { 20 | return IntegerResponseBody.class; 21 | } 22 | 23 | public SetSettings setGroupId(int groupId) { 24 | return addParam("group_id", groupId); 25 | } 26 | 27 | public SetSettings setMessages(boolean messages) { 28 | return addParam("messages", messages ? 1 : 0); 29 | } 30 | 31 | public SetSettings setBotsCapabilities(boolean botsCapabilities) { 32 | return addParam("bots_capabilities", botsCapabilities ? 1 : 0); 33 | } 34 | 35 | public SetSettings setBotsAddToChat(boolean botsAddToChat) { 36 | return addParam("bots_add_to_chat", botsAddToChat ? 1 : 0); 37 | } 38 | 39 | @Override 40 | public SetSettings addParam(String key, Object value) { 41 | return (SetSettings) super.addParam(key, value); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/VkBotsMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import java.util.function.Supplier; 4 | 5 | /** 6 | * Provides all VK APIs available for Bots. 7 | */ 8 | public class VkBotsMethods { 9 | public final BoardMethods board; 10 | public final DocsMethods docs; 11 | public final GroupsMethods groups; 12 | public final MarketMethods market; 13 | public final MessagesMethods messages; 14 | public final OtherMethods other; 15 | public final PhotosMethods photos; 16 | public final StoriesMethods stories; 17 | public final UsersMethods users; 18 | public final UtilsMethods utils; 19 | public final WallMethods wall; 20 | 21 | public VkBotsMethods(String accessToken) { 22 | this(() -> accessToken); 23 | } 24 | 25 | public VkBotsMethods(Supplier accessTokenSupplier) { 26 | board = new BoardMethods(accessTokenSupplier); 27 | docs = new DocsMethods(accessTokenSupplier); 28 | groups = new GroupsMethods(accessTokenSupplier); 29 | market = new MarketMethods(accessTokenSupplier); 30 | messages = new MessagesMethods(accessTokenSupplier); 31 | other = new OtherMethods(accessTokenSupplier); 32 | photos = new PhotosMethods(accessTokenSupplier); 33 | stories = new StoriesMethods(accessTokenSupplier); 34 | users = new UsersMethods(accessTokenSupplier); 35 | utils = new UtilsMethods(accessTokenSupplier); 36 | wall = new WallMethods(accessTokenSupplier); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/stories/Delete.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.stories; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.ParamUtils; 6 | import api.longpoll.bots.utils.VkMethods; 7 | 8 | import java.util.Arrays; 9 | 10 | /** 11 | * Implements stories.delete method. 12 | *

13 | * Allows deleting a story. 14 | * 15 | * @see https://vk.com/dev/stories.delete 16 | */ 17 | public class Delete extends VkMethod { 18 | public Delete(String accessToken) { 19 | super(VkMethods.get("stories.delete"), accessToken); 20 | } 21 | 22 | @Override 23 | protected Class getResponseClass() { 24 | return IntegerResponseBody.class; 25 | } 26 | 27 | public Delete setOwnerId(int ownerId) { 28 | return addParam("owner_id", ownerId); 29 | } 30 | 31 | public Delete setStoryId(int storyId) { 32 | return addParam("story_id", storyId); 33 | } 34 | 35 | public Delete setStories(String... stories) { 36 | return setStories(Arrays.asList(stories)); 37 | } 38 | 39 | public Delete setStories(Iterable stories) { 40 | return addParam("stories", ParamUtils.csv(stories)); 41 | } 42 | 43 | @Override 44 | public Delete addParam(String key, Object value) { 45 | return (Delete) super.addParam(key, value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/docs/Search.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.docs; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.additional.VkList; 5 | import api.longpoll.bots.model.objects.media.Doc; 6 | import api.longpoll.bots.utils.VkMethods; 7 | 8 | /** 9 | * Implements docs.search method. 10 | * 11 | * @see https://vk.com/dev/docs.search 12 | */ 13 | public class Search extends VkMethod { 14 | 15 | public Search(String accessToken) { 16 | super(VkMethods.get("docs.search"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return ResponseBody.class; 22 | } 23 | 24 | public Search setQ(String q) { 25 | return addParam("q", q); 26 | } 27 | 28 | public Search setCount(int count) { 29 | return addParam("count", count); 30 | } 31 | 32 | public Search setOffset(int offset) { 33 | return addParam("offset", offset); 34 | } 35 | 36 | public Search setReturnTags(boolean returnTags) { 37 | return addParam("return_tags", returnTags ? 1 : 0); 38 | } 39 | 40 | @Override 41 | public Search addParam(String key, Object value) { 42 | return (Search) super.addParam(key, value); 43 | } 44 | 45 | /** 46 | * Response to docs.search request. 47 | */ 48 | public static class ResponseBody extends VkList { 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/users/UserUnblock.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.users; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes user_unblock event objects. 8 | */ 9 | public class UserUnblock implements Update.Object { 10 | /** 11 | * Administrator ID. 12 | */ 13 | @SerializedName("admin_id") 14 | private Integer adminId; 15 | 16 | /** 17 | * User ID. 18 | */ 19 | @SerializedName("user_id") 20 | private Integer userId; 21 | 22 | /** 23 | * Unblocking date. 24 | */ 25 | @SerializedName("by_end_date") 26 | private Integer byEndDate; 27 | 28 | public Integer getAdminId() { 29 | return adminId; 30 | } 31 | 32 | public void setAdminId(Integer adminId) { 33 | this.adminId = adminId; 34 | } 35 | 36 | public Integer getUserId() { 37 | return userId; 38 | } 39 | 40 | public void setUserId(Integer userId) { 41 | this.userId = userId; 42 | } 43 | 44 | public Integer getByEndDate() { 45 | return byEndDate; 46 | } 47 | 48 | public void setByEndDate(Integer byEndDate) { 49 | this.byEndDate = byEndDate; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "UserUnblockEvent{" + 55 | "adminId=" + adminId + 56 | ", userId=" + userId + 57 | ", byEndDate=" + byEndDate + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/docs/Save.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.docs; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.media.Attachment; 5 | import api.longpoll.bots.model.response.GenericResponseBody; 6 | import api.longpoll.bots.utils.VkMethods; 7 | 8 | /** 9 | * Implements docs.save method. 10 | * 11 | * @see https://vk.com/dev/docs.save 12 | */ 13 | public class Save extends VkMethod { 14 | 15 | public Save(String accessToken) { 16 | super(VkMethods.get("docs.save"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return ResponseBody.class; 22 | } 23 | 24 | public Save setFile(String file) { 25 | return addParam("file", file); 26 | } 27 | 28 | public Save setTitle(String title) { 29 | return addParam("title", title); 30 | } 31 | 32 | public Save setTags(String tags) { 33 | return addParam("tags", tags); 34 | } 35 | 36 | public Save setReturnTags(boolean returnTags) { 37 | return addParam("return_tags", returnTags ? 1 : 0); 38 | } 39 | 40 | @Override 41 | public Save addParam(String key, Object value) { 42 | return (Save) super.addParam(key, value); 43 | } 44 | 45 | /** 46 | * Response to docs.save request. 47 | */ 48 | public static class ResponseBody extends GenericResponseBody { 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/boards/BoardPostDelete.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.boards; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes board_post_delete event objects. 8 | */ 9 | public class BoardPostDelete implements Update.Object { 10 | /** 11 | * Topic owner ID. 12 | */ 13 | @SerializedName("topic_owner_id") 14 | private Integer topicOwnerId; 15 | 16 | /** 17 | * Comment ID. 18 | */ 19 | @SerializedName("id") 20 | private Integer id; 21 | 22 | /** 23 | * Topic ID. 24 | */ 25 | @SerializedName("topic_id") 26 | private Integer topicId; 27 | 28 | public Integer getTopicOwnerId() { 29 | return topicOwnerId; 30 | } 31 | 32 | public void setTopicOwnerId(Integer topicOwnerId) { 33 | this.topicOwnerId = topicOwnerId; 34 | } 35 | 36 | public Integer getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Integer id) { 41 | this.id = id; 42 | } 43 | 44 | public Integer getTopicId() { 45 | return topicId; 46 | } 47 | 48 | public void setTopicId(Integer topicId) { 49 | this.topicId = topicId; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "BoardPostDeleteEvent{" + 55 | "topicOwnerId=" + topicOwnerId + 56 | ", id=" + id + 57 | ", topicId=" + topicId + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/api/longpoll/bots/converters/response/messages/MessagesSendResultConverterTest.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.converters.response.messages; 2 | 3 | import api.longpoll.bots.methods.impl.messages.Send; 4 | import com.google.gson.Gson; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import java.util.List; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | import static org.junit.jupiter.api.Assertions.assertFalse; 12 | import static org.junit.jupiter.api.Assertions.assertNotNull; 13 | import static org.junit.jupiter.api.Assertions.assertTrue; 14 | 15 | class MessagesSendResultConverterTest { 16 | final Gson gson = new Gson(); 17 | 18 | @Test 19 | void responses() { 20 | Send.ResponseBody result = gson.fromJson(ParseUtil.readJson("json/response/messages_send/message_send_responses_sample_5_110.json"), Send.ResponseBody.class); 21 | assertNotNull(result); 22 | 23 | Object response = result.getResponse(); 24 | assertNotNull(response); 25 | assertTrue(response instanceof List); 26 | 27 | List list = (List) response; 28 | assertFalse(list.isEmpty()); 29 | 30 | Object o = list.get(0); 31 | assertNotNull(o); 32 | assertTrue(o instanceof Send.ResponseBody.Response); 33 | 34 | Send.ResponseBody.Response messagesSendResponse = (Send.ResponseBody.Response) o; 35 | assertEquals(111, messagesSendResponse.getPeerId()); 36 | assertEquals(287, messagesSendResponse.getMessageId()); 37 | } 38 | } -------------------------------------------------------------------------------- /src/test/java/parse/response/photo/PhotoCommentNewParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.photo; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.photos.PhotoComment; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class PhotoCommentNewParseTest { 12 | @Test 13 | void messageEdit() { 14 | Update event = ParseUtil.getFirstEvent("json/response/photo_comment_new/photo_comment_new_sample_5_110.json"); 15 | assertEquals(Update.Type.PHOTO_COMMENT_NEW, event.getType()); 16 | assertEquals(444, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof PhotoComment); 22 | 23 | PhotoComment photoCommentUpdate = (PhotoComment) object; 24 | assertEquals(3, photoCommentUpdate.getId()); 25 | assertEquals(111, photoCommentUpdate.getFromId()); 26 | assertEquals(1594285508, photoCommentUpdate.getDate()); 27 | assertEquals("t", photoCommentUpdate.getText()); 28 | assertEquals(-222, photoCommentUpdate.getPhotoOwnerId()); 29 | assertEquals(333, photoCommentUpdate.getPhotoId()); 30 | 31 | WallComment.Thread thread = photoCommentUpdate.getThread(); 32 | assertNotNull(thread); 33 | assertEquals(0, thread.getCount()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/parse/response/video/VideoCommentParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.video; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.video.VideoComment; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class VideoCommentParseTest { 12 | @Test 13 | void videoCommentEdit() { 14 | Update event = ParseUtil.getFirstEvent("json/response/video_comment_edit/video_comment_edit_sample_5_110.json"); 15 | assertEquals(Update.Type.VIDEO_COMMENT_EDIT, event.getType()); 16 | assertEquals(555, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof VideoComment); 22 | 23 | VideoComment videoCommentUpdate = (VideoComment) object; 24 | assertEquals(1, videoCommentUpdate.getId()); 25 | assertEquals(111, videoCommentUpdate.getFromId()); 26 | assertEquals(222, videoCommentUpdate.getDate()); 27 | assertEquals("check2", videoCommentUpdate.getText()); 28 | assertEquals(-333, videoCommentUpdate.getVideoOwnerId()); 29 | assertEquals(444, videoCommentUpdate.getVideoId()); 30 | 31 | WallComment.Thread thread = videoCommentUpdate.getThread(); 32 | assertNotNull(thread); 33 | assertEquals(0, thread.getCount()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/MarkAsRead.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements messages.markAsRead method. 9 | *

10 | * Marks messages as read. 11 | * 12 | * @see https://vk.com/dev/messages.markAsRead 13 | */ 14 | public class MarkAsRead extends VkMethod { 15 | public MarkAsRead(String accessToken) { 16 | super(VkMethods.get("messages.markAsRead"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | public MarkAsRead setPeerId(int peerId) { 25 | return addParam("peer_id", peerId); 26 | } 27 | 28 | public MarkAsRead setStartMessageId(int startMessageId) { 29 | return addParam("start_message_id", startMessageId); 30 | } 31 | 32 | public MarkAsRead setGroupId(int groupId) { 33 | return addParam("group_id", groupId); 34 | } 35 | 36 | public MarkAsRead setMarkConversationAsRead(boolean markConversationAsRead) { 37 | return addParam("mark_conversation_as_read", markConversationAsRead ? 1 : 0); 38 | } 39 | 40 | @Override 41 | public MarkAsRead addParam(String key, Object value) { 42 | return (MarkAsRead) super.addParam(key, value); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/messages/MessageTypingState.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.messages; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Describes message_typing_state event object. 8 | */ 9 | public class MessageTypingState implements Update.Object { 10 | /** 11 | * Typing status. 12 | */ 13 | @SerializedName("state") 14 | private String state; 15 | 16 | /** 17 | * User ID who is typing the text. 18 | */ 19 | @SerializedName("from_id") 20 | private Integer fromId; 21 | 22 | /** 23 | * Community ID to which the user writes a message. 24 | */ 25 | @SerializedName("to_id") 26 | private Integer toId; 27 | 28 | public String getState() { 29 | return state; 30 | } 31 | 32 | public void setState(String state) { 33 | this.state = state; 34 | } 35 | 36 | public Integer getFromId() { 37 | return fromId; 38 | } 39 | 40 | public void setFromId(Integer fromId) { 41 | this.fromId = fromId; 42 | } 43 | 44 | public Integer getToId() { 45 | return toId; 46 | } 47 | 48 | public void setToId(Integer toId) { 49 | this.toId = toId; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "MessageTypingStateEvent{" + 55 | "state='" + state + '\'' + 56 | ", fromId=" + fromId + 57 | ", toId=" + toId + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/parse/response/photo/PhotoCommentEditParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.photo; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.photos.PhotoComment; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class PhotoCommentEditParseTest { 12 | @Test 13 | void messageEdit() { 14 | Update event = ParseUtil.getFirstEvent("json/response/photo_comment_edit/photo_comment_edit_sample_5_110.json"); 15 | assertEquals(Update.Type.PHOTO_COMMENT_EDIT, event.getType()); 16 | assertEquals(555, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof PhotoComment); 22 | 23 | PhotoComment photoCommentUpdate = (PhotoComment) object; 24 | assertEquals(111, photoCommentUpdate.getId()); 25 | assertEquals(222, photoCommentUpdate.getFromId()); 26 | assertEquals(1594285508, photoCommentUpdate.getDate()); 27 | assertEquals("tt", photoCommentUpdate.getText()); 28 | assertEquals(-333, photoCommentUpdate.getPhotoOwnerId()); 29 | assertEquals(444, photoCommentUpdate.getPhotoId()); 30 | 31 | WallComment.Thread thread = photoCommentUpdate.getThread(); 32 | assertNotNull(thread); 33 | assertEquals(0, thread.getCount()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/parse/response/video/VideoCommentNewParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.video; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.video.VideoComment; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class VideoCommentNewParseTest { 12 | @Test 13 | void videoCommentNew() { 14 | Update event = ParseUtil.getFirstEvent("json/response/video_comment_new/video_comment_new_sample_5_110.json"); 15 | assertEquals(Update.Type.VIDEO_COMMENT_NEW, event.getType()); 16 | assertEquals(444, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof VideoComment); 22 | 23 | VideoComment videoCommentUpdate = (VideoComment) object; 24 | assertEquals(1, videoCommentUpdate.getId()); 25 | assertEquals(111, videoCommentUpdate.getFromId()); 26 | assertEquals(1594823317, videoCommentUpdate.getDate()); 27 | assertEquals("check", videoCommentUpdate.getText()); 28 | assertEquals(-222, videoCommentUpdate.getVideoOwnerId()); 29 | assertEquals(333, videoCommentUpdate.getVideoId()); 30 | 31 | WallComment.Thread thread = videoCommentUpdate.getThread(); 32 | assertNotNull(thread); 33 | assertEquals(0, thread.getCount()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/parse/response/photo/PhotoCommentRestoreParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.photo; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.photos.PhotoComment; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class PhotoCommentRestoreParseTest { 12 | @Test 13 | void messageEdit() { 14 | Update event = ParseUtil.getFirstEvent("json/response/photo_comment_restore/photo_comment_restore_sample_5_110.json"); 15 | assertEquals(Update.Type.PHOTO_COMMENT_RESTORE, event.getType()); 16 | assertEquals(444, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof PhotoComment); 22 | 23 | PhotoComment photoCommentUpdate = (PhotoComment) object; 24 | assertEquals(3, photoCommentUpdate.getId()); 25 | assertEquals(111, photoCommentUpdate.getFromId()); 26 | assertEquals(1594285508, photoCommentUpdate.getDate()); 27 | assertEquals("tt", photoCommentUpdate.getText()); 28 | assertEquals(-222, photoCommentUpdate.getPhotoOwnerId()); 29 | assertEquals(333, photoCommentUpdate.getPhotoId()); 30 | 31 | WallComment.Thread thread = photoCommentUpdate.getThread(); 32 | assertNotNull(thread); 33 | assertEquals(0, thread.getCount()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/parse/response/wall/WallCommentNewParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.wall; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.wall.comments.WallReply; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class WallCommentNewParseTest { 12 | @Test 13 | void wallReplyNew() { 14 | Update event = ParseUtil.getFirstEvent("json/response/wall_reply_new/wall_reply_new_sample_5_110.json"); 15 | assertEquals(Update.Type.WALL_REPLY_NEW, event.getType()); 16 | assertEquals(444, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof WallReply); 22 | 23 | WallReply wallReplyUpdate = (WallReply) object; 24 | assertEquals(4, wallReplyUpdate.getId()); 25 | assertEquals(111, wallReplyUpdate.getFromId()); 26 | assertEquals(3, wallReplyUpdate.getPostId()); 27 | assertEquals(-222, wallReplyUpdate.getOwnerId()); 28 | assertEquals(1594972082, wallReplyUpdate.getDate()); 29 | assertEquals(-333, wallReplyUpdate.getPostOwnerId()); 30 | assertEquals("test", wallReplyUpdate.getText()); 31 | 32 | WallComment.Thread thread = wallReplyUpdate.getThread(); 33 | assertNotNull(thread); 34 | assertEquals(0, thread.getCount()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/parse/response/other/GroupChangeSettingsParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.other; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.other.GroupChangeSettings; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import java.util.Map; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | public class GroupChangeSettingsParseTest { 13 | @Test 14 | void likeAdd() { 15 | Update event = ParseUtil.getFirstEvent("json/response/group_change_settings/group_change_settings_sample_5_110.json"); 16 | assertEquals(Update.Type.GROUP_CHANGE_SETTINGS, event.getType()); 17 | assertEquals(222, event.getGroupId()); 18 | assertEquals("aaa", event.getEventId()); 19 | 20 | Update.Object object = event.getObject(); 21 | assertNotNull(object); 22 | assertTrue(object instanceof GroupChangeSettings); 23 | 24 | GroupChangeSettings groupChangeSettingsUpdate = (GroupChangeSettings) object; 25 | assertEquals(111, groupChangeSettingsUpdate.getUserId()); 26 | 27 | Map changes = groupChangeSettingsUpdate.getChanges(); 28 | assertNotNull(changes); 29 | assertFalse(changes.isEmpty()); 30 | assertTrue(changes.containsKey("description")); 31 | 32 | GroupChangeSettings.Change change = changes.get("description"); 33 | assertNotNull(change); 34 | assertEquals("test", change.getOldValue()); 35 | assertEquals("test1", change.getNewValue()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/parse/response/video/VideoCommentRestoreParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.video; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.video.VideoComment; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class VideoCommentRestoreParseTest { 12 | @Test 13 | void videoCommentRestore() { 14 | Update event = ParseUtil.getFirstEvent("json/response/video_comment_restore/video_comment_restore_sample_5_110.json"); 15 | assertEquals(Update.Type.VIDEO_COMMENT_RESTORE, event.getType()); 16 | assertEquals(444, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof VideoComment); 22 | 23 | VideoComment videoCommentUpdate = (VideoComment) object; 24 | assertEquals(2, videoCommentUpdate.getId()); 25 | assertEquals(111, videoCommentUpdate.getFromId()); 26 | assertEquals(1594834849, videoCommentUpdate.getDate()); 27 | assertEquals("t", videoCommentUpdate.getText()); 28 | assertEquals(-222, videoCommentUpdate.getVideoOwnerId()); 29 | assertEquals(333, videoCommentUpdate.getVideoId()); 30 | 31 | WallComment.Thread thread = videoCommentUpdate.getThread(); 32 | assertNotNull(thread); 33 | assertEquals(0, thread.getCount()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/parse/response/wall/WallCommentEditParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.wall; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.wall.comments.WallReply; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class WallCommentEditParseTest { 12 | @Test 13 | void wallReplyEdit() { 14 | Update event = ParseUtil.getFirstEvent("json/response/wall_reply_edit/wall_reply_edit_sample_5_110.json"); 15 | assertEquals(Update.Type.WALL_REPLY_EDIT, event.getType()); 16 | assertEquals(444, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof WallReply); 22 | 23 | WallReply wallReplyUpdate = (WallReply) object; 24 | assertEquals(4, wallReplyUpdate.getId()); 25 | assertEquals(111, wallReplyUpdate.getFromId()); 26 | assertEquals(3, wallReplyUpdate.getPostId()); 27 | assertEquals(-222, wallReplyUpdate.getOwnerId()); 28 | assertEquals(1594972082, wallReplyUpdate.getDate()); 29 | assertEquals(-333, wallReplyUpdate.getPostOwnerId()); 30 | assertEquals("test1", wallReplyUpdate.getText()); 31 | 32 | WallComment.Thread thread = wallReplyUpdate.getThread(); 33 | assertNotNull(thread); 34 | assertEquals(0, thread.getCount()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/PhotosMethods.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods; 2 | 3 | import api.longpoll.bots.methods.impl.photos.GetChatUploadServer; 4 | import api.longpoll.bots.methods.impl.photos.GetMessagesUploadServer; 5 | import api.longpoll.bots.methods.impl.photos.GetOwnerCoverPhotoUploadServer; 6 | import api.longpoll.bots.methods.impl.photos.SaveMessagesPhoto; 7 | import api.longpoll.bots.methods.impl.photos.SaveOwnerCoverPhoto; 8 | 9 | import java.util.function.Supplier; 10 | 11 | /** 12 | * Provides Photos methods. 13 | */ 14 | public class PhotosMethods { 15 | /** 16 | * {@code access_token}. 17 | */ 18 | private final Supplier accessTokenSupplier; 19 | 20 | public PhotosMethods(Supplier accessTokenSupplier) { 21 | this.accessTokenSupplier = accessTokenSupplier; 22 | } 23 | 24 | public GetChatUploadServer getChatUploadServer() { 25 | return new GetChatUploadServer(accessTokenSupplier.get()); 26 | } 27 | 28 | public GetMessagesUploadServer getMessagesUploadServer() { 29 | return new GetMessagesUploadServer(accessTokenSupplier.get()); 30 | } 31 | 32 | public GetOwnerCoverPhotoUploadServer getOwnerCoverPhotoUploadServer() { 33 | return new GetOwnerCoverPhotoUploadServer(accessTokenSupplier.get()); 34 | } 35 | 36 | public SaveMessagesPhoto saveMessagesPhoto() { 37 | return new SaveMessagesPhoto(accessTokenSupplier.get()); 38 | } 39 | 40 | public SaveOwnerCoverPhoto saveOwnerCoverPhoto() { 41 | return new SaveOwnerCoverPhoto(accessTokenSupplier.get()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/CreateChat.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.ParamUtils; 6 | import api.longpoll.bots.utils.VkMethods; 7 | 8 | import java.util.Arrays; 9 | 10 | /** 11 | * Implements messages.createChat method. 12 | *

13 | * Creates a chat with several participants. 14 | * 15 | * @see https://vk.com/dev/messages.createChat 16 | */ 17 | public class CreateChat extends VkMethod { 18 | public CreateChat(String accessToken) { 19 | super(VkMethods.get("messages.createChat"), accessToken); 20 | } 21 | 22 | @Override 23 | protected Class getResponseClass() { 24 | return IntegerResponseBody.class; 25 | } 26 | 27 | public CreateChat setUserIds(Integer... userIds) { 28 | return setUserIds(Arrays.asList(userIds)); 29 | } 30 | 31 | public CreateChat setUserIds(Iterable userIds) { 32 | return addParam("user_ids", ParamUtils.csv(userIds)); 33 | } 34 | 35 | public CreateChat setTitle(String title) { 36 | return addParam("title", title); 37 | } 38 | 39 | public CreateChat setGroupId(int groupId) { 40 | return addParam("group_id", groupId); 41 | } 42 | 43 | @Override 44 | public CreateChat addParam(String key, Object value) { 45 | return (CreateChat) super.addParam(key, value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/parse/response/wall/WallCommentRestoreParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.wall; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.events.wall.comments.WallReply; 5 | import api.longpoll.bots.model.objects.basic.WallComment; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class WallCommentRestoreParseTest { 12 | @Test 13 | void wallReplyRestore() { 14 | Update event = ParseUtil.getFirstEvent("json/response/wall_reply_restore/wall_reply_restore_sample_5_110.json"); 15 | assertEquals(Update.Type.WALL_REPLY_RESTORE, event.getType()); 16 | assertEquals(444, event.getGroupId()); 17 | assertEquals("aaa", event.getEventId()); 18 | 19 | Update.Object object = event.getObject(); 20 | assertNotNull(object); 21 | assertTrue(object instanceof WallReply); 22 | 23 | WallReply wallReplyUpdate = (WallReply) object; 24 | assertEquals(4, wallReplyUpdate.getId()); 25 | assertEquals(111, wallReplyUpdate.getFromId()); 26 | assertEquals(3, wallReplyUpdate.getPostId()); 27 | assertEquals(-222, wallReplyUpdate.getOwnerId()); 28 | assertEquals(1594972082, wallReplyUpdate.getDate()); 29 | assertEquals(-333, wallReplyUpdate.getPostOwnerId()); 30 | assertEquals("test1", wallReplyUpdate.getText()); 31 | 32 | WallComment.Thread thread = wallReplyUpdate.getThread(); 33 | assertNotNull(thread); 34 | assertEquals(0, thread.getCount()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_doc_no_preview_sample_5_118.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "3105", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1613547783, 9 | "from_id": 123, 10 | "id": 578, 11 | "out": 0, 12 | "peer_id": 123, 13 | "text": "", 14 | "conversation_message_id": 554, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [ 19 | { 20 | "type": "doc", 21 | "doc": { 22 | "id": 456, 23 | "owner_id": 789, 24 | "title": "canvas.rar", 25 | "size": 2325, 26 | "ext": "rar", 27 | "date": 1559985418, 28 | "type": 2, 29 | "url": "https:\/\/vk.com\/doc1234", 30 | "access_key": "5678" 31 | } 32 | } 33 | ], 34 | "is_hidden": false 35 | }, 36 | "client_info": { 37 | "button_actions": [ 38 | "text", 39 | "vkpay", 40 | "open_app", 41 | "location", 42 | "open_link", 43 | "intent_subscribe", 44 | "intent_unsubscribe" 45 | ], 46 | "keyboard": true, 47 | "inline_keyboard": true, 48 | "carousel": false, 49 | "lang_id": 0 50 | } 51 | }, 52 | "group_id": 444, 53 | "event_id": "aaa" 54 | } 55 | ] 56 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/market/GetOrderById.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.market; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.basic.MarketOrder; 5 | import api.longpoll.bots.model.response.GenericResponseBody; 6 | import api.longpoll.bots.utils.VkMethods; 7 | 8 | /** 9 | * Implements market.getOrderById method. 10 | *

11 | * Returns order by id. 12 | * 13 | * @see https://vk.com/dev/market.getOrderById 14 | */ 15 | public class GetOrderById extends VkMethod { 16 | 17 | public GetOrderById(String accessToken) { 18 | super(VkMethods.get("market.getOrderById"), accessToken); 19 | } 20 | 21 | @Override 22 | protected Class getResponseClass() { 23 | return ResponseBody.class; 24 | } 25 | 26 | public GetOrderById setUserId(int userId) { 27 | return addParam("user_id", userId); 28 | } 29 | 30 | public GetOrderById setOrderId(int orderId) { 31 | return addParam("order_id", orderId); 32 | } 33 | 34 | public GetOrderById setExtended(boolean extended) { 35 | return addParam("extended", extended ? 1 : 0); 36 | } 37 | 38 | @Override 39 | public GetOrderById addParam(String key, Object value) { 40 | return (GetOrderById) super.addParam(key, value); 41 | } 42 | 43 | /** 44 | * Response to market.getOrderById request. 45 | */ 46 | public static class ResponseBody extends GenericResponseBody { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/messages/SendEventAnswer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.messages; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.additional.EventData; 5 | import api.longpoll.bots.model.response.IntegerResponseBody; 6 | import api.longpoll.bots.utils.VkMethods; 7 | 8 | /** 9 | * Sends an event with an action that will occur when the callback button is clicked. 10 | * 11 | * @see https://vk.com/dev/messages.sendMessageEventAnswer 12 | */ 13 | public class SendEventAnswer extends VkMethod { 14 | public SendEventAnswer(String accessToken) { 15 | super(VkMethods.get("messages.sendMessageEventAnswer"), accessToken); 16 | } 17 | 18 | @Override 19 | protected Class getResponseClass() { 20 | return IntegerResponseBody.class; 21 | } 22 | 23 | public SendEventAnswer setEventId(String eventId) { 24 | return addParam("event_id", eventId); 25 | } 26 | 27 | public SendEventAnswer setUserId(int userId) { 28 | return addParam("user_id", userId); 29 | } 30 | 31 | public SendEventAnswer setPeerId(int peerId) { 32 | return addParam("peer_id", peerId); 33 | } 34 | 35 | public SendEventAnswer setEventData(EventData eventData) { 36 | return addParam("event_data", eventData); 37 | } 38 | 39 | @Override 40 | public SendEventAnswer addParam(String key, Object value) { 41 | return (SendEventAnswer) super.addParam(key, value); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/parse/response/video/VideoNewParseTest.java: -------------------------------------------------------------------------------- 1 | package parse.response.video; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import api.longpoll.bots.model.objects.media.Video; 5 | import org.junit.jupiter.api.Test; 6 | import parse.response.ParseUtil; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class VideoNewParseTest { 11 | @Test 12 | void videoNew() { 13 | Update event = ParseUtil.getFirstEvent("json/response/video_new/video_new_sample_5_110.json"); 14 | assertEquals(Update.Type.VIDEO_NEW, event.getType()); 15 | assertEquals(333, event.getGroupId()); 16 | assertEquals("aaa", event.getEventId()); 17 | 18 | Update.Object object = event.getObject(); 19 | assertNotNull(object); 20 | assertTrue(object instanceof Video); 21 | 22 | Video video = (Video) object; 23 | assertTrue(video.getCanEdit()); 24 | assertTrue(video.getCanAdd()); 25 | assertEquals(0, video.getCommentsAmount()); 26 | assertEquals(1594821406, video.getDate()); 27 | assertFalse(video.getDescription().isEmpty()); 28 | assertEquals(314, video.getDuration()); 29 | assertEquals(111, video.getId()); 30 | assertEquals(-222, video.getOwnerId()); 31 | String title = video.getTitle(); 32 | assertNotNull(title); 33 | assertFalse(title.isEmpty()); 34 | assertFalse(video.getFavourite()); 35 | assertEquals("video", video.getType()); 36 | assertEquals(1, video.getViews()); 37 | assertEquals(0, video.getLocalViews()); 38 | assertEquals("YouTube", video.getPlatform()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/adapters/deserializers/IsMemberResponseBodyDeserializer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.adapters.deserializers; 2 | 3 | import api.longpoll.bots.methods.impl.groups.IsMember; 4 | import com.google.gson.JsonDeserializationContext; 5 | import com.google.gson.JsonDeserializer; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonParseException; 8 | import com.google.gson.reflect.TypeToken; 9 | 10 | import java.lang.reflect.Type; 11 | import java.util.List; 12 | 13 | /** 14 | * Deserializes JSON object to {@link IsMember.ResponseBody}. 15 | */ 16 | public class IsMemberResponseBodyDeserializer implements JsonDeserializer { 17 | @Override 18 | public IsMember.ResponseBody deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { 19 | JsonElement jsonResponse = jsonElement.getAsJsonObject().get("response"); 20 | 21 | IsMember.ResponseBody responseBody = new IsMember.ResponseBody(); 22 | responseBody.setResponse(deserializeResponse(jsonResponse, context)); 23 | return responseBody; 24 | } 25 | 26 | private Object deserializeResponse(JsonElement jsonResponse, JsonDeserializationContext context) { 27 | if (jsonResponse.isJsonPrimitive()) { 28 | return jsonResponse.getAsInt() == 1; 29 | } 30 | 31 | if (jsonResponse.isJsonObject()) { 32 | return context.deserialize(jsonResponse, IsMember.ResponseBody.Response.class); 33 | } 34 | 35 | return context.deserialize(jsonResponse, TypeToken.getParameterized(List.class, IsMember.ResponseBody.Response.class).getType()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/resource/json/response/video_new/video_new_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2617", 3 | "updates": [ 4 | { 5 | "type": "video_new", 6 | "object": { 7 | "can_edit": 1, 8 | "can_add": 1, 9 | "can_attach_link": 1, 10 | "comments": 0, 11 | "date": 1594821406, 12 | "description": "We've re-mast.", 13 | "duration": 314, 14 | "image": [ 15 | { 16 | "height": 96, 17 | "url": "https://sun9-49.userapi.com/voqT9K4xzblZ_r1WIshNyXz0KRSdIIJTcOkL0g/SrGx51lLpU0.jpg", 18 | "width": 130, 19 | "with_padding": 1 20 | }, 21 | { 22 | "height": 120, 23 | "url": "https://sun9-46.userapi.com/3PVKOgGViqbEBQsUPaWu7wdBBcHliGZdTjgdBg/eX00PsuxhzA.jpg", 24 | "width": 160, 25 | "with_padding": 1 26 | }, 27 | { 28 | "height": 240, 29 | "url": "https://sun9-20.userapi.com/VDYzOTpHre2ei7PWXIc-xlJCiOeHj_6nieA-tQ/F_-6fyYJOUg.jpg", 30 | "width": 320, 31 | "with_padding": 1 32 | }, 33 | { 34 | "height": 450, 35 | "url": "https://sun9-12.userapi.com/avVLbdHAhRxzVCn4i3-4dm0-UtJ2LIhD2jc4Ew/CBc1tAlG6cw.jpg", 36 | "width": 800, 37 | "with_padding": 1 38 | } 39 | ], 40 | "id": 111, 41 | "owner_id": -222, 42 | "title": "abc", 43 | "is_favorite": false, 44 | "type": "video", 45 | "views": 1, 46 | "local_views": 0, 47 | "platform": "YouTube" 48 | }, 49 | "group_id": 333, 50 | "event_id": "aaa" 51 | } 52 | ] 53 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/market/GetGroupOrders.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.market; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.additional.VkList; 5 | import api.longpoll.bots.model.objects.basic.MarketOrder; 6 | import api.longpoll.bots.model.response.GenericResponseBody; 7 | import api.longpoll.bots.utils.VkMethods; 8 | 9 | /** 10 | * Implements market.getGroupOrders method. 11 | *

12 | * Returns community's orders. 13 | * 14 | * @see https://vk.com/dev/market.getGroupOrders 15 | */ 16 | public class GetGroupOrders extends VkMethod { 17 | public GetGroupOrders(String accessToken) { 18 | super(VkMethods.get("market.getGroupOrders"), accessToken); 19 | } 20 | 21 | @Override 22 | protected Class getResponseClass() { 23 | return ResponseBody.class; 24 | } 25 | 26 | public GetGroupOrders setGroupId(int groupId) { 27 | return addParam("group_id", groupId); 28 | } 29 | 30 | public GetGroupOrders setOffset(int offset) { 31 | return addParam("offset", offset); 32 | } 33 | 34 | public GetGroupOrders setCount(int count) { 35 | return addParam("count", count); 36 | } 37 | 38 | @Override 39 | public GetGroupOrders addParam(String key, Object value) { 40 | return (GetGroupOrders) super.addParam(key, value); 41 | } 42 | 43 | /** 44 | * Response to market.getGroupOrders request. 45 | */ 46 | public static class ResponseBody extends GenericResponseBody> { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/groups/EditCallbackServer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.groups; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements groups.editCallbackServer method. 9 | *

10 | * Edits Callback API server in the community. 11 | * 12 | * @see https://vk.com/dev/groups.editCallbackServer 13 | */ 14 | public class EditCallbackServer extends VkMethod { 15 | public EditCallbackServer(String accessToken) { 16 | super(VkMethods.get("groups.editCallbackServer"), accessToken); 17 | } 18 | 19 | public EditCallbackServer setUrl(String url) { 20 | return addParam("url", url); 21 | } 22 | 23 | @Override 24 | protected Class getResponseClass() { 25 | return IntegerResponseBody.class; 26 | } 27 | 28 | public EditCallbackServer setGroupId(int groupId) { 29 | return addParam("group_id", groupId); 30 | } 31 | 32 | public EditCallbackServer setServerId(int serverId) { 33 | return addParam("server_id", serverId); 34 | } 35 | 36 | public EditCallbackServer setTitle(String title) { 37 | return addParam("title", title); 38 | } 39 | 40 | public EditCallbackServer setSecretKey(String secretKey) { 41 | return addParam("secret_key", secretKey); 42 | } 43 | 44 | @Override 45 | public EditCallbackServer addParam(String key, Object value) { 46 | return (EditCallbackServer) super.addParam(key, value); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/photos/GetChatUploadServer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.photos; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.utils.VkMethods; 5 | 6 | /** 7 | * Implements photos.getChatUploadServer method. 8 | *

9 | * Returns an upload link for chat cover pictures. 10 | * 11 | * @see https://vk.com/dev/photos.getChatUploadServer 12 | */ 13 | public class GetChatUploadServer extends VkMethod { 14 | public GetChatUploadServer(String accessToken) { 15 | super(VkMethods.get("photos.getChatUploadServer"), accessToken); 16 | } 17 | 18 | @Override 19 | protected Class getResponseClass() { 20 | return ResponseBody.class; 21 | } 22 | 23 | public GetChatUploadServer setChatId(int chatId) { 24 | return addParam("chat_id", chatId); 25 | } 26 | 27 | public GetChatUploadServer setCropX(int cropX) { 28 | return addParam("crop_x", cropX); 29 | } 30 | 31 | public GetChatUploadServer setCropY(int cropY) { 32 | return addParam("crop_y", cropY); 33 | } 34 | 35 | public GetChatUploadServer setCropWidth(int cropWidth) { 36 | return addParam("crop_width", cropWidth); 37 | } 38 | 39 | @Override 40 | public GetChatUploadServer addParam(String key, Object value) { 41 | return (GetChatUploadServer) super.addParam(key, value); 42 | } 43 | 44 | /** 45 | * Response to photos.getChatUploadServer request. 46 | */ 47 | public static class ResponseBody extends GetOwnerCoverPhotoUploadServer.ResponseBody { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_wall_reply_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2606", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1594235111, 9 | "from_id": 111, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 222, 13 | "text": "", 14 | "conversation_message_id": 4410, 15 | "fwd_messages": [], 16 | "ref": "single", 17 | "important": false, 18 | "random_id": 0, 19 | "attachments": [ 20 | { 21 | "type": "wall_reply", 22 | "wall_reply": { 23 | "id": 333, 24 | "from_id": 444, 25 | "post_id": 555, 26 | "owner_id": -666, 27 | "parents_stack": [ 28 | 777 29 | ], 30 | "date": 1594231450, 31 | "text": "abc", 32 | "likes": { 33 | "count": 1, 34 | "user_likes": 0, 35 | "can_like": 1 36 | }, 37 | "reply_to_user": 888, 38 | "reply_to_comment": 999 39 | } 40 | } 41 | ], 42 | "is_hidden": false 43 | }, 44 | "client_info": { 45 | "button_actions": [ 46 | "text", 47 | "vkpay", 48 | "open_app", 49 | "location", 50 | "open_link" 51 | ], 52 | "keyboard": true, 53 | "inline_keyboard": true, 54 | "carousel": false, 55 | "lang_id": 0 56 | } 57 | }, 58 | "group_id": 100, 59 | "event_id": "aaa" 60 | } 61 | ] 62 | } -------------------------------------------------------------------------------- /src/test/resource/json/response/message_new/message_new_audio_sample_5_110.json: -------------------------------------------------------------------------------- 1 | { 2 | "ts": "2594", 3 | "updates": [ 4 | { 5 | "type": "message_new", 6 | "object": { 7 | "message": { 8 | "date": 1593164510, 9 | "from_id": 111, 10 | "id": 0, 11 | "out": 0, 12 | "peer_id": 222, 13 | "text": "", 14 | "conversation_message_id": 4398, 15 | "fwd_messages": [], 16 | "important": false, 17 | "random_id": 0, 18 | "attachments": [ 19 | { 20 | "type": "audio", 21 | "audio": { 22 | "artist": "Linkin Park", 23 | "id": 333, 24 | "owner_id": 444, 25 | "title": "In the End", 26 | "duration": 219, 27 | "track_code": "8ac27ee1cgHOcmlmj29hKOoadzN5ij-Y_-E", 28 | "url": "", 29 | "date": 1490105766, 30 | "content_restricted": 2, 31 | "main_artists": [ 32 | { 33 | "name": "Linkin Park", 34 | "domain": "67550258036106963", 35 | "id": "67550258036106963" 36 | } 37 | ] 38 | } 39 | } 40 | ], 41 | "is_hidden": false 42 | }, 43 | "client_info": { 44 | "button_actions": [ 45 | "text", 46 | "vkpay", 47 | "open_app", 48 | "location", 49 | "open_link" 50 | ], 51 | "keyboard": true, 52 | "inline_keyboard": true, 53 | "lang_id": 0 54 | } 55 | }, 56 | "group_id": 555, 57 | "event_id": "aaa" 58 | } 59 | ] 60 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/Keyboard.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional; 2 | 3 | import api.longpoll.bots.model.objects.additional.buttons.Button; 4 | import com.google.gson.Gson; 5 | import com.google.gson.annotations.SerializedName; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Describes Keyboard object. 11 | */ 12 | public class Keyboard { 13 | /** 14 | * Hides the keyboard after the initial use. 15 | */ 16 | @SerializedName("one_time") 17 | private Boolean oneTime; 18 | 19 | /** 20 | * Shows the keyboard inside the message. 21 | */ 22 | @SerializedName("inline") 23 | private Boolean inline; 24 | 25 | /** 26 | * An array of button arrays. 27 | */ 28 | @SerializedName("buttons") 29 | private List> buttons; 30 | 31 | public Keyboard(List> buttons) { 32 | this.buttons = buttons; 33 | } 34 | 35 | public String toJson() { 36 | return new Gson().toJson(this); 37 | } 38 | 39 | public Boolean getOneTime() { 40 | return oneTime; 41 | } 42 | 43 | public Keyboard setOneTime(Boolean oneTime) { 44 | this.oneTime = oneTime; 45 | return this; 46 | } 47 | 48 | public Boolean getInline() { 49 | return inline; 50 | } 51 | 52 | public Keyboard setInline(Boolean inline) { 53 | this.inline = inline; 54 | return this; 55 | } 56 | 57 | public List> getButtons() { 58 | return buttons; 59 | } 60 | 61 | public Keyboard setButtons(List> buttons) { 62 | this.buttons = buttons; 63 | return this; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return toJson(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/upload/UploadDoc.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.upload; 2 | 3 | import api.longpoll.bots.model.objects.media.UploadTypes; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.io.File; 7 | import java.io.InputStream; 8 | import java.nio.file.Path; 9 | 10 | /** 11 | * Implements uploading document in VK API. 12 | */ 13 | public class UploadDoc extends UploadMethod { 14 | 15 | public UploadDoc(String uploadUrl, String filename, InputStream doc) { 16 | super(uploadUrl, UploadTypes.FILE, filename, doc); 17 | } 18 | 19 | public UploadDoc(String uploadUrl, String filename, byte[] doc) { 20 | super(uploadUrl, UploadTypes.FILE, filename, doc); 21 | } 22 | 23 | public UploadDoc(String uploadUrl, File doc) { 24 | super(uploadUrl, UploadTypes.FILE, doc); 25 | } 26 | 27 | public UploadDoc(String uploadUrl, Path doc) { 28 | super(uploadUrl, UploadTypes.FILE, doc); 29 | } 30 | 31 | @Override 32 | protected Class getResponseClass() { 33 | return ResponseBody.class; 34 | } 35 | 36 | /** 37 | * Response to document uploading. 38 | */ 39 | public static class ResponseBody { 40 | /** 41 | * Uploaded file. 42 | */ 43 | @SerializedName("file") 44 | private String file; 45 | 46 | public String getFile() { 47 | return file; 48 | } 49 | 50 | public void setFile(String file) { 51 | this.file = file; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Response{" + 57 | "file='" + file + '\'' + 58 | '}'; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/stories/Get.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.stories; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.objects.additional.StoriesFeedBlock; 5 | import api.longpoll.bots.model.objects.additional.VkList; 6 | import api.longpoll.bots.model.response.GenericResponseBody; 7 | import api.longpoll.bots.utils.ParamUtils; 8 | import api.longpoll.bots.utils.VkMethods; 9 | 10 | import java.util.Arrays; 11 | 12 | /** 13 | * Implements stories.get method. 14 | *

15 | * Returns stories available for current user. 16 | * 17 | * @see https://vk.com/dev/stories.get 18 | */ 19 | public class Get extends VkMethod { 20 | public Get(String accessToken) { 21 | super(VkMethods.get("stories.get"), accessToken); 22 | } 23 | 24 | @Override 25 | protected Class getResponseClass() { 26 | return ResponseBody.class; 27 | } 28 | 29 | public Get setOwnerId(int ownerId) { 30 | return addParam("owner_id", ownerId); 31 | } 32 | 33 | public Get setExtended(boolean extended) { 34 | return addParam("extended", extended ? 1 : 0); 35 | } 36 | 37 | public Get setFields(String... fields) { 38 | return setFields(Arrays.asList(fields)); 39 | } 40 | 41 | public Get setFields(Iterable fields) { 42 | return addParam("fields", ParamUtils.csv(fields)); 43 | } 44 | 45 | @Override 46 | public Get addParam(String key, Object value) { 47 | return (Get) super.addParam(key, value); 48 | } 49 | 50 | /** 51 | * Response to stories.get 52 | */ 53 | public static class ResponseBody extends GenericResponseBody> { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/board/DeleteComment.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.board; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements board.deleteComment method. 9 | *

10 | * Deletes a comment on a topic on a community's discussion board. 11 | * 12 | * @see https://vk.com/dev/board.deleteComment 13 | */ 14 | public class DeleteComment extends VkMethod { 15 | public DeleteComment(String accessToken) { 16 | super(VkMethods.get("board.deleteComment"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | /** 25 | * Sets Group ID. 26 | * 27 | * @param groupId Group ID. 28 | * @return this instance. 29 | */ 30 | public DeleteComment setGroupId(int groupId) { 31 | return addParam("group_id", groupId); 32 | } 33 | 34 | /** 35 | * Sets Topic ID. 36 | * 37 | * @param topicId Topic ID. 38 | * @return this instance. 39 | */ 40 | public DeleteComment setTopicId(int topicId) { 41 | return addParam("topic_id", topicId); 42 | } 43 | 44 | /** 45 | * Sets Comment ID. 46 | * 47 | * @param commentId Comment ID. 48 | * @return this instance. 49 | */ 50 | public DeleteComment setCommentId(int commentId) { 51 | return addParam("comment_id", commentId); 52 | } 53 | 54 | @Override 55 | public DeleteComment addParam(String key, Object value) { 56 | return (DeleteComment) super.addParam(key, value); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/additional/buttons/OpenLinkButton.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.additional.buttons; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * A button to open a link. 8 | */ 9 | public class OpenLinkButton extends Button { 10 | public OpenLinkButton(Action action) { 11 | super(action); 12 | } 13 | 14 | /** 15 | * Describes action for button type of Open link. 16 | */ 17 | public static class Action extends Button.Action { 18 | /** 19 | * A link to be opened. 20 | */ 21 | @SerializedName("link") 22 | private String link; 23 | 24 | /** 25 | * Button text. 26 | */ 27 | @SerializedName("label") 28 | private String label; 29 | 30 | public Action(String link, String label) { 31 | this(link, label, null); 32 | } 33 | 34 | public Action(String link, String label, JsonElement payload) { 35 | super("open_link", payload); 36 | this.link = link; 37 | this.label = label; 38 | } 39 | 40 | public String getLink() { 41 | return link; 42 | } 43 | 44 | public void setLink(String link) { 45 | this.link = link; 46 | } 47 | 48 | public String getLabel() { 49 | return label; 50 | } 51 | 52 | public void setLabel(String label) { 53 | this.label = label; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "Action{" + 59 | "link='" + link + '\'' + 60 | ", label='" + label + '\'' + 61 | "} " + super.toString(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/api/longpoll/bots/converters/events/messages/MessagesGetHistoryAttachmentsResultConverterTest.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.converters.events.messages; 2 | 3 | import api.longpoll.bots.methods.impl.messages.GetHistoryAttachments; 4 | import api.longpoll.bots.model.objects.media.Attachment; 5 | import com.google.gson.Gson; 6 | import org.junit.jupiter.api.Test; 7 | import parse.response.ParseUtil; 8 | 9 | import java.util.List; 10 | 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | import static org.junit.jupiter.api.Assertions.assertFalse; 13 | import static org.junit.jupiter.api.Assertions.assertNotNull; 14 | 15 | class MessagesGetHistoryAttachmentsResultConverterTest { 16 | Gson gson = new Gson(); 17 | 18 | @Test 19 | void messagesGetHistoryAttachments() { 20 | GetHistoryAttachments.ResponseBody result = gson.fromJson(ParseUtil.readJson("json/response/messages_get_history_attachments/message_get_history_attachments_photo_sample_5_118.json"), GetHistoryAttachments.ResponseBody.class); 21 | assertNotNull(result); 22 | 23 | GetHistoryAttachments.ResponseBody.Response response = result.getResponse(); 24 | assertNotNull(response); 25 | assertEquals("542/1", response.getNextFrom()); 26 | 27 | List items = response.getItems(); 28 | assertNotNull(items); 29 | assertFalse(items.isEmpty()); 30 | 31 | GetHistoryAttachments.ResponseBody.Response.Item item = items.get(0); 32 | assertNotNull(item); 33 | assertEquals(542, item.getMessageId()); 34 | 35 | Attachment attachment = item.getAttachment(); 36 | assertNotNull(attachment); 37 | assertEquals(Attachment.Type.PHOTO, attachment.getType()); 38 | assertNotNull(attachment.getPhoto()); 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/board/RestoreComment.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.board; 2 | 3 | import api.longpoll.bots.methods.impl.VkMethod; 4 | import api.longpoll.bots.model.response.IntegerResponseBody; 5 | import api.longpoll.bots.utils.VkMethods; 6 | 7 | /** 8 | * Implements board.deleteComment method. 9 | *

10 | * Restores a comment deleted from a topic on a community's discussion board. 11 | * 12 | * @see https://vk.com/dev/board.deleteComment 13 | */ 14 | public class RestoreComment extends VkMethod { 15 | public RestoreComment(String accessToken) { 16 | super(VkMethods.get("board.restoreComment"), accessToken); 17 | } 18 | 19 | @Override 20 | protected Class getResponseClass() { 21 | return IntegerResponseBody.class; 22 | } 23 | 24 | /** 25 | * Sets Group ID. 26 | * 27 | * @param groupId Group ID. 28 | * @return this instance. 29 | */ 30 | public RestoreComment setGroupId(int groupId) { 31 | return addParam("group_id", groupId); 32 | } 33 | 34 | /** 35 | * Sets Topic ID. 36 | * 37 | * @param topicId Topic ID. 38 | * @return this instance. 39 | */ 40 | public RestoreComment setTopicId(int topicId) { 41 | return addParam("topic_id", topicId); 42 | } 43 | 44 | /** 45 | * Sets Comment ID. 46 | * 47 | * @param commentId Comment ID. 48 | * @return this instance. 49 | */ 50 | public RestoreComment setCommentId(int commentId) { 51 | return addParam("comment_id", commentId); 52 | } 53 | 54 | @Override 55 | public RestoreComment addParam(String key, Object value) { 56 | return (RestoreComment) super.addParam(key, value); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/methods/impl/upload/UploadStory.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.methods.impl.upload; 2 | 3 | import api.longpoll.bots.model.objects.media.UploadTypes; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.io.File; 7 | import java.io.InputStream; 8 | import java.nio.file.Path; 9 | 10 | /** 11 | * Implements uploading story in VK API. 12 | */ 13 | public class UploadStory extends UploadMethod { 14 | public UploadStory(String uploadUrl, String filename, InputStream story) { 15 | super(uploadUrl, UploadTypes.VIDEO_FILE, filename, story); 16 | } 17 | 18 | public UploadStory(String uploadUrl, String filename, byte[] story) { 19 | super(uploadUrl, UploadTypes.VIDEO_FILE, filename, story); 20 | } 21 | 22 | public UploadStory(String uploadUrl, File story) { 23 | super(uploadUrl, UploadTypes.VIDEO_FILE, story); 24 | } 25 | 26 | public UploadStory(String uploadUrl, Path story) { 27 | super(uploadUrl, UploadTypes.VIDEO_FILE, story); 28 | } 29 | 30 | @Override 31 | protected Class getResponseClass() { 32 | return ResponseBody.class; 33 | } 34 | 35 | /** 36 | * Response to story uploading. 37 | */ 38 | public static class ResponseBody { 39 | @SerializedName("upload_result") 40 | private String uploadResult; 41 | 42 | public String getUploadResult() { 43 | return uploadResult; 44 | } 45 | 46 | public void setUploadResult(String uploadResult) { 47 | this.uploadResult = uploadResult; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "Response{" + 53 | "uploadResult='" + uploadResult + '\'' + 54 | '}'; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/events/poll/PollVoteNew.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.events.poll; 2 | 3 | import api.longpoll.bots.model.events.Update; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * A new vote in a public poll. 8 | */ 9 | public class PollVoteNew implements Update.Object { 10 | /** 11 | * Poll owner ID. 12 | */ 13 | @SerializedName("owner_id") 14 | private Integer ownerId; 15 | 16 | /** 17 | * Poll ID. 18 | */ 19 | @SerializedName("poll_id") 20 | private Integer pollId; 21 | 22 | /** 23 | * Poll option ID. 24 | */ 25 | @SerializedName("option_id") 26 | private Integer optionId; 27 | 28 | /** 29 | * User ID. 30 | */ 31 | @SerializedName("user_id") 32 | private Integer userId; 33 | 34 | public Integer getOwnerId() { 35 | return ownerId; 36 | } 37 | 38 | public void setOwnerId(Integer ownerId) { 39 | this.ownerId = ownerId; 40 | } 41 | 42 | public Integer getPollId() { 43 | return pollId; 44 | } 45 | 46 | public void setPollId(Integer pollId) { 47 | this.pollId = pollId; 48 | } 49 | 50 | public Integer getOptionId() { 51 | return optionId; 52 | } 53 | 54 | public void setOptionId(Integer optionId) { 55 | this.optionId = optionId; 56 | } 57 | 58 | public Integer getUserId() { 59 | return userId; 60 | } 61 | 62 | public void setUserId(Integer userId) { 63 | this.userId = userId; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "PollVoteNew{" + 69 | "ownerId=" + ownerId + 70 | ", pollId=" + pollId + 71 | ", optionId=" + optionId + 72 | ", userId=" + userId + 73 | '}'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/model/objects/media/Gift.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.model.objects.media; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes gift. 7 | * 8 | * @see Gift 9 | */ 10 | public class Gift { 11 | /** 12 | * Gift ID. 13 | */ 14 | @SerializedName("id") 15 | private Integer id; 16 | 17 | /** 18 | * URL of the image with size 256x256px. 19 | */ 20 | @SerializedName("thumb_256") 21 | private String thumb256; 22 | 23 | /** 24 | * URL of the image with size 96x96px. 25 | */ 26 | @SerializedName("thumb_96") 27 | private String thumb96; 28 | 29 | /** 30 | * URL of the image with size 48x48px. 31 | */ 32 | @SerializedName("thumb_48") 33 | private String thumb48; 34 | 35 | public Integer getId() { 36 | return id; 37 | } 38 | 39 | public void setId(Integer id) { 40 | this.id = id; 41 | } 42 | 43 | public String getThumb256() { 44 | return thumb256; 45 | } 46 | 47 | public void setThumb256(String thumb256) { 48 | this.thumb256 = thumb256; 49 | } 50 | 51 | public String getThumb96() { 52 | return thumb96; 53 | } 54 | 55 | public void setThumb96(String thumb96) { 56 | this.thumb96 = thumb96; 57 | } 58 | 59 | public String getThumb48() { 60 | return thumb48; 61 | } 62 | 63 | public void setThumb48(String thumb48) { 64 | this.thumb48 = thumb48; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "Gift{" + 70 | "id=" + id + 71 | ", thumb256='" + thumb256 + '\'' + 72 | ", thumb96='" + thumb96 + '\'' + 73 | ", thumb48='" + thumb48 + '\'' + 74 | '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/api/longpoll/bots/adapters/deserializers/GetMemberResponseBodyDeserializer.java: -------------------------------------------------------------------------------- 1 | package api.longpoll.bots.adapters.deserializers; 2 | 3 | import api.longpoll.bots.methods.impl.groups.GetMembers; 4 | import api.longpoll.bots.model.objects.additional.VkList; 5 | import com.google.gson.JsonArray; 6 | import com.google.gson.JsonDeserializationContext; 7 | import com.google.gson.JsonDeserializer; 8 | import com.google.gson.JsonElement; 9 | import com.google.gson.JsonObject; 10 | import com.google.gson.JsonParseException; 11 | import com.google.gson.reflect.TypeToken; 12 | 13 | import java.lang.reflect.Type; 14 | import java.util.List; 15 | 16 | /** 17 | * Deserializes JSON object to {@link GetMembers.ResponseBody}. 18 | */ 19 | public class GetMemberResponseBodyDeserializer implements JsonDeserializer { 20 | @Override 21 | public GetMembers.ResponseBody deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { 22 | JsonObject jsonResponse = jsonElement.getAsJsonObject().getAsJsonObject("response"); 23 | JsonArray jsonItems = jsonResponse.getAsJsonArray("items"); 24 | 25 | VkList vkList = new VkList<>(); 26 | vkList.setCount(jsonResponse.get("count").getAsInt()); 27 | vkList.setItems(context.deserialize(jsonItems, guessItemsType(jsonItems))); 28 | 29 | GetMembers.ResponseBody responseBody = new GetMembers.ResponseBody(); 30 | responseBody.setResponse(vkList); 31 | return responseBody; 32 | } 33 | 34 | private Type guessItemsType(JsonArray jsonItems) { 35 | return jsonItems.isEmpty() || jsonItems.get(0).isJsonPrimitive() 36 | ? TypeToken.getParameterized(List.class, Integer.class).getType() 37 | : TypeToken.getParameterized(List.class, GetMembers.ResponseBody.Item.class).getType(); 38 | } 39 | } 40 | --------------------------------------------------------------------------------