Petersamokhin bots sdk java

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Comfortable and simple library for creating bots for VK

License

Ama-alt/vk-bot-java-sdk

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Convenient and simple library that helps quickly and easily create a bot for VK.com https://vk.com/vkbotsdk

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.

Language: English | Russian

Example

Implementation of accepting messages of only specified types:

Group group = new Group(151083290, "access_token"); group.onSimpleTextMessage(message -> new Message() .from(group) .to(message.authorId()) .text("Что-то скучновато буковки читать. Картинку кинь лучше.") .send() ); group.onPhotoMessage(message -> new Message() .from(group) .to(message.authorId()) .text("Уже лучше. Но я тоже так могу. Что дальше?") .photo("/Users/PeterSamokhin/Desktop/topoviy_mem.png") .send() ); group.onVoiceMessage(message -> new Message() .from(group) .to(message.authorId()) .text("Не охота мне голосовые твои слушать.") .doc("https://vk.com/doc62802565_447117479") .send() );

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() .from(user) .to(chatIdLong) .text("Hello, chat!") .send(); > else < // Handle message that not from chat new Message() .from(user) .to(message.authorId()) .text("Sorry, I will work only in chats.") .send(); > >); user.onChatMessage(message -> < // Handle message, it's from chat >);
// 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() .from(user) .to(chat) .text(s) .send(); // 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("Пользователь https://vk.com/id" + userId + " начал печатать"); >); // Let's type too group.enableTyping(true);
// Like this message.doc("doc62802565_447117479").send(); // Or this message.doc("/Users/PeterSamokhin/Desktop/cp.zip").send(); // Or even this message.doc("https://www.petersamokhin.com/files/test.txt").send();
// Into the same community, if you specified group_id and access_token on initialization group.uploadCover("https://www.petersamokhin.com/files/vk-bot-java-sdk/cover.png");
  • Firstly, you need to create a community if you are intending to use bot on behalf of it
    • You can do it there
    • 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.

    Add following lines to pom.xml:

    dependency> groupId>com.petersamokhingroupId> artifactId>vk-bot-java-sdkartifactId> version>0.1.3version> dependency>

    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

    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" Bot.jar
      • If you use IntelliJ IDEA go to Project Structure. | Libraries, click + and add downloaded .jar to lib list.

      Done. The library is usable in your project now.

      Источник

      Saved searches

      Use saved searches to filter your results more quickly

      You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

      Comfortable and simple library for creating bots for VK

      License

      Pets-Crew/vk-bot-java-sdk

      This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

      Name already in use

      A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

      Sign In Required

      Please sign in to use Codespaces.

      Launching GitHub Desktop

      If nothing happens, download GitHub Desktop and try again.

      Launching GitHub Desktop

      If nothing happens, download GitHub Desktop and try again.

      Launching Xcode

      If nothing happens, download Xcode and try again.

      Launching Visual Studio Code

      Your codespace will open once ready.

      There was a problem preparing your codespace, please try again.

      Latest commit

      Git stats

      Files

      Failed to load latest commit information.

      README.md

      Convenient and simple library that helps quickly and easily create a bot for VK.com https://vk.com/vkbotsdk

      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.

      Language: English | Russian

      Example

      Implementation of accepting messages of only specified types:

      Group group = new Group(151083290, "access_token"); group.onSimpleTextMessage(message -> new Message() .from(group) .to(message.authorId()) .text("Что-то скучновато буковки читать. Картинку кинь лучше.") .send() ); group.onPhotoMessage(message -> new Message() .from(group) .to(message.authorId()) .text("Уже лучше. Но я тоже так могу. Что дальше?") .photo("/Users/PeterSamokhin/Desktop/topoviy_mem.png") .send() ); group.onVoiceMessage(message -> new Message() .from(group) .to(message.authorId()) .text("Не охота мне голосовые твои слушать.") .doc("https://vk.com/doc62802565_447117479") .send() );

      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() .from(user) .to(chatIdLong) .text("Hello, chat!") .send(); > else < // Handle message that not from chat new Message() .from(user) .to(message.authorId()) .text("Sorry, I will work only in chats.") .send(); > >); user.onChatMessage(message -> < // Handle message, it's from chat >);
      // 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() .from(user) .to(chat) .text(s) .send(); // 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("Пользователь https://vk.com/id" + userId + " начал печатать"); >); // Let's type too group.enableTyping(true);
      // Like this message.doc("doc62802565_447117479").send(); // Or this message.doc("/Users/PeterSamokhin/Desktop/cp.zip").send(); // Or even this message.doc("https://www.petersamokhin.com/files/test.txt").send();
      // Into the same community, if you specified group_id and access_token on initialization group.uploadCover("https://www.petersamokhin.com/files/vk-bot-java-sdk/cover.png");
Оцените статью