Dialog Java Bot SDK.
How to use the SDK with maven/gradle?
- Add repository
Gradle:
repositories {
maven { url "http://dialog.bintray.com/maven" }
}
- Add BOT dependency
dependencies {
compile 'im.dlg:bot-sdk:1.3'
}
- 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();
}
}