Coder Social home page Coder Social logo

viber-bot-java's Introduction

⚠️ Deprecated ⚠️

This library is deprecated. No new development will be taking place. We recommend that you use either NodeJS, Python or REST API.

Viber Java Bot API

Use this library to develop a bot for Viber platform. The library is available on GitHub as well as maven central.

License

This library is released under the terms of the Apache 2.0 license. See License for more information.

Library Prerequisites

  1. Java >= 8
  2. An Active Viber account on a platform which supports Public Accounts/ bots (iOS/Android). This account will automatically be set as the account administrator during the account creation process.
  3. Active Public Account/ bot.
  4. Account authentication token - unique account identifier used to validate your account in all API requests. Once your account is created your authentication token will appear in the account’s “edit info” screen (for admins only). Each request posted to Viber by the account will need to contain the token.
  5. Webhook - Please use a server endpoint URL that supports HTTPS. If you deploy on your own custom server, you'll need a trusted (ca.pem) certificate, not self-signed. Read our blog post on how to test your bot locally.

Installation

This library is released on maven central.

Gradle

compile group: 'com.viber', name: 'viber-bot', version: '1.0.11'

Maven

<dependency>
    <groupId>com.viber</groupId>
    <artifactId>viber-bot</artifactId>
    <version>1.0.11</version>
</dependency>

Documentation

JavaDocs

All public APIs are documented with JavaDocs which can be found in the GitHub repository.

Sample projects

We've created two sample projects to help you get started:

A simple overview

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

Should I be concerned with synchronizing my web server threads? Is this library thread-safe?

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.

Can I make I/O calls asynchronous and still retain thread-safety for my bot?

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

  • Note: This will not change the way you use the library. You still don't have to synchronize anything.

Do you supply a basic router for text messages?

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

Community

Join the conversation on Gitter.

viber-bot-java's People

Contributors

itamarm avatar idanh avatar voiteco avatar lpandzic avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.