Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.voiteco:viber-bot-java:'
}
dependencies {
implementation("com.github.voiteco:viber-bot-java:")
}
<dependency>
<groupId>com.github.voiteco</groupId>
<artifactId>viber-bot-java</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.voiteco" % "viber-bot-java" % ""
:dependencies [[com.github.voiteco/viber-bot-java ""]]
Use this library to develop a bot for Viber platform. The library is available on GitHub as well as maven central.
This library is released under the terms of the Apache 2.0 license. See License for more information.
This library is released on maven central.
compile group: 'com.viber', name: 'viber-bot', version: '1.0.7'
<dependency>
<groupId>com.viber</groupId>
<artifactId>viber-bot</artifactId>
<version>1.0.7</version>
</dependency>
All public APIs are documented with JavaDocs which can be found in the GitHub repository.
We've created two sample projects to help you get started. -- Spring-Boot Sample using spring-boot-starter-web package, -- and NanoHTTPd Sample with a tiny embeddable http server, called NanoHTTPd.
public void botExample() {
ViberBot bot = new ViberBot(new BotProfile("SampleBot", "http://viber.com/avatar.jpg"), "YOUR_AUTH_TOKEN_HERE");
bot.onMessageReceived((event, message, response) -> response.send(message));
// somewhere else in your web server of choice:
bot.incoming(Request.fromJsonString("..."));
}
You can chose to use any web server or framework you like. All you need to do is call the API with -
bot.incoming(Request.fromJsonString("...")); // or
bot.incoming(Request.fromInputStream(inputStream));
The Viber bot library is thread-safe and highly concurrent. You do not have to worry about synchronizing anything.
All calls to ViberBot#incoming()
go through a BlockingQueue
, and ordering is retained.
All I/O calls are directly executed on the same thread they were initially called on.
Yes. You can pass a system property to control the I/O thread pool:
com.viber.bot.executor.strategy=[DIRECT|THREAD]
(default is DIRECT)
com.viber.bot.executor.threads=N
(default is getRuntime().availableProcessors()
)
Well funny you ask. Yes we do. But a word of warning - messages sent to your router callback will also be emitted to the ViberBot#onMessageReceived
event.
public void botTextRouterExample() {
bot.onTextMessage("(hi|hello)", (event, message, response) -> response.send("Hi " + event.getSender().getName()));
}
Join the conversation on [Gitter] (https://gitter.im/viber/bot-java).