All Projects → yvasyliev → java-vk-bots-long-poll-api

yvasyliev / java-vk-bots-long-poll-api

Licence: MIT license
A Java library to create VK bots using Bots Long Poll API

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to java-vk-bots-long-poll-api

vbio
Python модуль для написания скриптов, использующих Bots API для социальной сети Вконтакте (vk.com)
Stars: ✭ 10 (-66.67%)
Mutual labels:  vk-bot, vk-api, vkapi, vkbot
vk-api
VK SDK | VKontakte wrapper for standalone apps
Stars: ✭ 30 (+0%)
Mutual labels:  vk-bot, vk-api, vkapi, vk-sdk
VK API
VK API Wrapper - in progress
Stars: ✭ 16 (-46.67%)
Mutual labels:  vk-bot, vk-api, long-polling, vk-sdk
py-vkontakte
A Python wrapper around the vk.com
Stars: ✭ 17 (-43.33%)
Mutual labels:  vk-api, vkapi
vkbottle
Сustomizable asynchronous VK API framework
Stars: ✭ 371 (+1136.67%)
Mutual labels:  vk-api, vkapi
vk-callback-bot
Бот для сообществ VK на основе CallBack. Взаимодействие с клавиатурой, загрузка файлов.
Stars: ✭ 21 (-30%)
Mutual labels:  vk-api, vk-sdk
easyvk
This app helps you create an apps with vk api easy!
Stars: ✭ 97 (+223.33%)
Mutual labels:  vk-api, longpoll
kasthack.osp
Генератор сырых дампов пользователей VK.
Stars: ✭ 15 (-50%)
Mutual labels:  vk-api, vkapi
VkNet.AudioBypass
Обход закрытия методов audio и messages для VkNet
Stars: ✭ 48 (+60%)
Mutual labels:  vk-api, vk-sdk
longpoll-doc
Документация для (почти) последней версии User LongPoll API
Stars: ✭ 56 (+86.67%)
Mutual labels:  vk-api, longpoll
node-vk-bot
Create and control VK bots easily.
Stars: ✭ 35 (+16.67%)
Mutual labels:  vk-bot, vk-api
kaishnik-bot
telegram & vk bot for students of KNRTU-KAI to make their daily routine more pleasant
Stars: ✭ 13 (-56.67%)
Mutual labels:  vk-bot
Vkwave
Asynchronous framework for building high-performance & easy to scale projects interacting with VK's API.
Stars: ✭ 135 (+350%)
Mutual labels:  vk-api
Sketal
Бот для ВКонтакте. Беседы / группы / развлечения.
Stars: ✭ 119 (+296.67%)
Mutual labels:  vk-api
Vk To Telegram Bot
Bot for auto-reposting posts from VK to Telegram channel
Stars: ✭ 103 (+243.33%)
Mutual labels:  vk-api
Whom I Know
Looks for common users of vk.com [DEPRECATED]
Stars: ✭ 69 (+130%)
Mutual labels:  vk-api
Vkrss
Generates RSS feed of opened/closed vk.com wall or global searched opened posts. Features: post filtering (include/exclude by regexp and/or by owner type), ads skipping, automatic title generation, hash-tags extraction as RSS categories, initial author extraction, HTML formatting
Stars: ✭ 59 (+96.67%)
Mutual labels:  vk-api
Vk api
Модуль для создания скриптов для ВКонтакте | vk.com API wrapper
Stars: ✭ 1,070 (+3466.67%)
Mutual labels:  vk-api
VideoforVk
Video for Vk (or VT) is client for Vk video API.
Stars: ✭ 27 (-10%)
Mutual labels:  vk-api
Swiftyvk
Easy and powerful way to interact with VK API for iOS and macOS
Stars: ✭ 247 (+723.33%)
Mutual labels:  vk-api

Maven Central Build status MIT License Total alerts Language grade: Java PRs Welcome javadoc

Java VK Bots Long Poll API

A Java library to create VK bots using Bots Long Poll API.

Description

An easy-to-use and lightweight Java library that implements Bots Long Poll API. Uses API version: 5.131.

Note

This library keeps on improving. Feel free to create issues or pull requests.

Third-party dependencies

This library uses the next third-party dependencies:

  • Gson
  • SLF4J

Requirements

  1. Java 8 or higher
  2. Maven or other build tool

Quickstart

  1. Create VK Community.
  2. Go to Manage - API usage - Access tokens and create access_token.
  3. Add the library to your Maven project:
<dependency>
  <groupId>com.github.yvasyliev</groupId>
  <artifactId>java-vk-bots-longpoll-api</artifactId>
  <version>3.5.3</version>
</dependency>
  1. Extend LongPollBot class and override necessary methods:
public class HelloBot extends LongPollBot {
    @Override
    public void onMessageNew(MessageNew messageNew) {
        try {
            Message message = messageNew.getMessage();
            if (message.hasText()) {
                String response = "Hello! Received your message: " + message.getText();
                vk.messages.send()
                        .setPeerId(message.getPeerId())
                        .setMessage(response)
                        .execute();
            }
        } catch (VkApiException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getAccessToken() {
        return "your_access_token";
    }

    public static void main(String[] args) throws VkApiException {
        new HelloBot().startPolling();
    }
}

How to send photos or documents?

Easy:

@Override
public void onMessageNew(MessageNew messageNew) {
    try {
        Message message = messageNew.getMessage();
        vk.messages.send()
            .setPeerId(message.getPeerId())
            .setMessage("Sending some files to you...")
            .addPhoto(new File("your_photo.png")) // to send photo as photo
            .addDoc(new File("your_photo.png")) // to send photo as document
            .execute();
    } catch (VkApiException e) {
        e.printStackTrace();
    }
}

More Examples

Find more examples of bot usage here.

Async execution

Each API method can be executed asynchronously:

CompletableFuture<Send.ResponseBody> future = vk.messages.send()
        .setPeerId(peerId)
        .setMessage("Sending message asynchronously...")
        .executeAsync();

Bot events

LongPollBot can handle the next events:

VK event Handler method
app_payload public void onAppPayload(AppPayload appPayload)
audio_new public void onAudioNew(Audio audio)
board_post_delete public void onBoardPostDelete(BoardPostDelete boardPostDelete)
board_post_edit public void onBoardPostEdit(BoardPost boardPost)
board_post_new public void onBoardPostNew(BoardPost boardPost)
board_post_restore public void onBoardPostRestore(BoardPost boardPost)
group_change_photo public void onGroupChangePhoto(GroupChangePhoto groupChangePhoto)
group_change_settings public void onGroupChangeSettings(GroupChangeSettings groupChangeSettings)
group_join public void onGroupJoin(GroupJoin groupJoin)
group_leave public void onGroupLeave(GroupLeave groupLeave)
like_add public void onLikeAdd(Like like)
like_remove public void onLikeRemove(Like like)
market_comment_delete public void onMarketCommentDelete(MarketCommentDelete marketCommentDelete)
market_comment_edit public void onMarketCommentEdit(MarketComment marketComment)
market_comment_new public void onMarketCommentNew(MarketComment marketComment)
market_comment_restore public void onMarketCommentRestore(MarketComment marketComment)
market_order_edit public void onMarketOrderEdit(MarketOrder marketOrder)
market_order_new public void onMarketOrderNew(MarketOrder marketOrder)
message_allow public void onMessageAllow(MessageAllow messageAllow)
message_deny public void onMessageDeny(MessageDeny messageDeny)
message_edit public void onMessageEdit(Message message)
message_event public void onMessageEvent(MessageEvent messageEvent)
message_new public void onMessageNew(MessageNew messageNew)
message_reply public void onMessageReply(Message message)
message_typing_state public void onMessageTypingState(MessageTypingState messageTypingState)
photo_comment_delete public void onPhotoCommentDelete(PhotoCommentDelete photoCommentDelete)
photo_comment_edit public void onPhotoCommentEdit(PhotoComment photoComment)
photo_comment_new public void onPhotoCommentNew(PhotoComment photoComment)
photo_comment_restore public void onPhotoCommentRestore(PhotoComment photoComment)
photo_comment_new public void onPhotoNew(Photo photo)
poll_vote_new public void onPollVoteNew(PollVoteNew pollVoteNew)
user_block public void onUserBlock(UserBlock userBlock)
user_unblock public void onUserUnblock(UserUnblock userUnblock)
video_comment_delete public void onVideoCommentDelete(VideoCommentDelete videoCommentDelete)
video_comment_edit public void onVideoCommentEdit(VideoComment videoComment)
video_comment_new public void onVideoCommentNew(VideoComment videoComment)
video_comment_restore public void onVideoCommentRestore(VideoComment videoComment)
video_new public void onVideoNew(Video video)
vkpay_transaction public void onVkpayTransaction(VkpayTransaction vkpayTransaction)
wall_post_new public void onWallPostNew(WallPost wallPost)
wall_reply_delete public void onWallReplyDelete(WallReplyDelete wallReplyDelete)
wall_reply_edit public void onWallReplyEdit(WallReply wallReply)
wall_reply_new public void onWallReplyNew(WallReply wallReply)
wall_reply_restore public void onWallReplyRestore(WallReply wallReply)
wall_repost public void onWallRepost(WallPost wallPost)

Logging

This library uses SLF4J API to log all events. You can add any SLF4J binding to your project to register events the way you want.

It is highly recommended enabling DEBUG log level to see sent and received data.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].