Skip to content
Comfortable and simple library for creating bots for VK
Branch: master
Clone or download
Latest commit d0cc956 Apr 25, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Added voice bot example Aug 25, 2017

VK Bot Java SDK

Convenient and simple library that helps quickly and easily create a bot for

Using this library one can interact with VK API for making bots - and there is more. Functionality is nicely suitable either for communities and personal profiles.

Latest version: vk-bot-java-sdk

Language: English | Russian



Implementation of accepting messages of only specified types:

Group group = new Group(151083290, "access_token");
group.onSimpleTextMessage(message ->
     new Message()
         .text("Что-то скучновато буковки читать. Картинку кинь лучше.")

group.onPhotoMessage(message ->
    new Message()
         .text("Уже лучше. Но я тоже так могу. Что дальше?")

group.onVoiceMessage(message ->
    new Message()
         .text("Не охота мне голосовые твои слушать.")

Ver. 0.1.4-alpha

This version is only available for downloading here – it will be added to central repo once it gets rid of “alpha” suffix, fixed and complete.

  • Fixed small things not affecting performance and quality overall, but making the work easier and the code more legible.
  • Added chatworking – now you can develop a bot that processes chat messages:
  user.onMessage(message -> {
        if (message.isMessageFromChat()) {

            // Get chat id
            int chatIdLong = message.getChatIdLong(); // 2000000011
            int chatId = message.chatId();            // 11
            int sender = message.authorId();          // 62802565

            // Handle message, it's from chat
            new Message()
                        .text("Hello, chat!")

        } else {

           // Handle message that not from chat
           new Message()
                        .text("Sorry, I will work only in chats.")
  user.onChatMessage(message -> {
      // Handle message, it's from chat
  • processing chat events:
  // Handle title changing
  user.onChatTitleChanged((oldTitle, newTitle, who, chat) -> {
      String s = "User with id " + who + " changed title in chat " + chat + " from «" + oldTitle + "» to «" + newTitle + "»";

      new Message()

      // User with id 62802565 changed title in chat 2000000011 from «Test 0» to «Test 1»
  // also you can handle chat join, chat leave, chat creating, etc

All methods return full chat ID, but you can switch it. For the sake of convenience, this value (2000000000) is added as a constant com.petersamokhin.bots.sdk.objects.Chat.CHAT_PREFIX.

Ver. 0.1.3 (25.08.2017) functionality

  • Processing direct messages of communities and personal profiles - only access_token is necessary.
  • Ability to specify needed type of messages, e.g. voice messages, plain-text messages, messages with stickers etc.
  • Also command processing added:
// Simple example
group.onCommand("/start", message -> 
    // do something with message

// Defining aliases
group.onCommand(new String[]{"/start", "/bot", "hello"}, message ->
    // do something with message
  • If you attach image, document, cover etc. via a link, the file is not downloaded but transferred directly into VK as a byte array. Due to it, message processing is stably fast.
  • Reacting to a user typing. The status User is typing... will be shown for 10 seconds unless you send a message:
// React to user typing
group.onTyping(userId -> {
    System.out.println("Пользователь" + userId + " начал печатать");
// Let's type too
  • Attaching photo/document etc. via link/from local storage/from VK storage:
// Like this

// Or this

// Or even this
  • Uploading community cover with one line:
// Into the same community, if you specified group_id and access_token on initialization


  • Firstly, you need to create a community if you are intending to use bot on behalf of it
  • Then you need to retrieve access_token
    • It is very well explained there]


The library is in a central maven repo. All you need to do is add a few lines into your build file.

If you are using Maven

Add following lines to pom.xml:


If you are using Gradle

Add following lines to dependencies section in your build.gradle:

compile group: 'com.petersamokhin', name: 'vk-bot-java-sdk', version: '0.1.3'

If you are using something else

Please, refer to guidelines for other build systems by Maven:

If you ARE NOT using any build system

  • Download distributive (all dependencies are included): library (3.2 MB) | md5
  • Now, all you need to do is add it to classpath:
    • Using shell:
    javac -cp "/root/vk-bot-java-sdk-0.1.3-jar-with-dependencies.jar" Bot.jar 
    • If you use IntelliJ IDEA go to Project Structure... | Libraries, click + and add downloaded .jar to lib list: Cover

Done. The library is usable in your project now.

Extended description

Please, refer to the documentation

You can’t perform that action at this time.