JBots

A java framework for creating Telegram Bots

License

License

Categories

Categories

Java Languages
GroupId

GroupId

me.shib.java.lib
ArtifactId

ArtifactId

jbots
Last Version

Last Version

0.8.1
Release Date

Release Date

Type

Type

jar
Description

Description

JBots
A java framework for creating Telegram Bots
Project URL

Project URL

https://github.com/shibme/jbots
Source Code Management

Source Code Management

https://github.com/shibme/jbots

Download jbots

How to add to project

<!-- https://jarcasting.com/artifacts/me.shib.java.lib/jbots/ -->
<dependency>
    <groupId>me.shib.java.lib</groupId>
    <artifactId>jbots</artifactId>
    <version>0.8.1</version>
</dependency>
// https://jarcasting.com/artifacts/me.shib.java.lib/jbots/
implementation 'me.shib.java.lib:jbots:0.8.1'
// https://jarcasting.com/artifacts/me.shib.java.lib/jbots/
implementation ("me.shib.java.lib:jbots:0.8.1")
'me.shib.java.lib:jbots:jar:0.8.1'
<dependency org="me.shib.java.lib" name="jbots" rev="0.8.1">
  <artifact name="jbots" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.shib.java.lib', module='jbots', version='0.8.1')
)
libraryDependencies += "me.shib.java.lib" % "jbots" % "0.8.1"
[me.shib.java.lib/jbots "0.8.1"]

Dependencies

compile (2)

Group / Artifact Type Version
me.shib.java.lib : jbotstats jar 0.2.2
org.reflections : reflections jar 0.9.11

Project Modules

There are no modules declared in this project.

JBots

Build Status Dependency Status Download Percentage of issues still open

A java framework for creating Telegram Bots

Maven Dependency for Consumers

Add to your pom.xml

<dependency>
	<groupId>me.shib.java.lib</groupId>
	<artifactId>jbots</artifactId>
	<version>0.8.1</version>
</dependency>

Also, you'll have to add the main class as me.shib.java.lib.jbots.JBotLauncher when you use maven assembly plugin to create a runnable binary JAR.

Example

Extend me.shib.java.lib.jbots.JBot abstract model class and create a new Model for your bot

public final class SampleJBot extends JBot {
    public SampleJBot(JBotConfig config) {
        super(config);
    }

    @Override
    public MessageHandler onMessage(Message message) {
        return new MessageHandler(message) {
            @Override
            public boolean onCommandFromAdmin(String command, String argument) {
                try {
                    bot().sendMessage(new ChatId(message.getChat().getId()), "Got a command \"" + command + "\" with the following argument from admin:\n" + argument);
                    return true;
                } catch (IOException e) {
                    return true;
                }
            }

            @Override
            public boolean onCommandFromUser(String command, String argument) {
                try {
                    bot().sendMessage(new ChatId(message.getChat().getId()), "Got a command \"" + command + "\" with the following argument from user:\n" + argument);
                    return true;
                } catch (IOException e) {
                    return true;
                }
            }

            @Override
            public boolean onMessageFromAdmin() {
                try {
                    bot().sendMessage(new ChatId(message.getChat().getId()), "Got a message from admin!");
                    return true;
                } catch (IOException e) {
                    return true;
                }
            }

            @Override
            public boolean onMessageFromUser() {
                try {
                    bot().sendMessage(new ChatId(message.getChat().getId()), "Got a message from user!");
                    return true;
                } catch (IOException e) {
                    return true;
                }
            }
        };
    }

    @Override
    public void onInlineQuery(InlineQuery query) {
        System.out.println(query);
    }

    @Override
    public void onChosenInlineResult(ChosenInlineResult chosenInlineResult) {
        System.out.println(chosenInlineResult);
    }

    @Override
    public void onCallbackQuery(CallbackQuery callbackQuery) {
        System.out.println(callbackQuery);
    }
}
Sample Config class

Create a class extending me.shib.java.lib.jbots.JBotConfig and override the methods that might be necessary

public final class SampleConfig extends JBotConfig {

    private static final String botApiToken = "xxxxxxxxxxxxxxxxxxx";
    private static final Class<? extends JBot> botModelClass = XYZ.class;
    private static final int threadCount = 4;
    private static final int reportInterval = 43200;
    private static final int minimumAllowedRating = 5;
    private static final boolean handleMissedChats = true;
    private static final boolean defaultWorker = true;
    private static final long[] admins = {1111111111, 2222222222};

    @Override
    public int threadCount() {
        return threadCount;
    }

    @Override
    public int reportInterval() {
        return reportInterval;
    }

    @Override
    public int minimumAllowedRating() {
        return minimumAllowedRating;
    }

    @Override
    public boolean handleMissedChats() {
        return handleMissedChats;
    }

    @Override
    public boolean defaultWorker() {
        return defaultWorker;
    }

    @Override
    protected long[] admins() {
        return admins;
    }

    @Override
    public String botApiToken() {
        return botApiToken;
    }

    @Override
    public Class<? extends JBot> botModelClass() {
        return botModelClass;
    }
}

Versions

Version
0.8.1
0.8.0
0.7
0.6
0.5.4
0.5.3
0.5.2
0.5.1
0.5
0.4.2
0.4.1
0.4
0.3.1
0.3