Skip to content
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

Java Bot SDK

Dialog Java Bot SDK.

Documentation

API Reference

Example

Community chat

How to use the SDK with maven/gradle?

  1. Add repository

Gradle:

repositories {
    maven { url "http://dialog.bintray.com/maven" }
}
  1. Add BOT dependency
dependencies {
    compile 'im.dlg:bot-sdk:1.3'
}
  1. Create bot and subscribe on updates
public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException {

        BotConfig botConfig = BotConfig.Builder.aBotConfig()
                .withHost("your-server-host")
                .withPort(443)
                .withToken("your-bot-token")
                .build();

        Bot bot = Bot.start(botConfig).get();

        bot.messaging().onMessage(message ->
                bot.users().get(message.getSender()).thenAccept(userOpt -> userOpt.ifPresent(user -> {
                            System.out.println("Got a message: " + message.getText() + " from user: " + user.getName());
                        })
                ).thenCompose(aVoid -> {
                            return bot.messaging().sendText(message.getPeer(), "pong");
                        }
                ).exceptionally(ex -> {
                    ex.printStackTrace();
                    return null;
                }).thenAccept(uuid ->
                        System.out.println("Sent a message with UUID: " + uuid)));

        bot.await();
    }
}
You can’t perform that action at this time.