Rizzen / java-bot-sdk

Dialog Java Bot SDK

Home Page:https://docs.dlg.im/bots/java-bot.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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();
    }
}

About

Dialog Java Bot SDK

https://docs.dlg.im/bots/java-bot.html

License:Apache License 2.0


Languages

Language:Java 100.0%