Skip to content
/ TBot Public

Comfortable and powerful framework for Telegram API bot

License

Notifications You must be signed in to change notification settings

JarKz/TBot

Repository files navigation

About TBot

If you had to work with Spring Framework, you know firsthand that it framework is comfortable and powerful. But it's very very big for using Telegram API. And this project TBot will overcome these problems!

He will has any datatypes, handlers with custom rules and multithreading!

Documentation

The TBot Framework is very simple and not means usage for complex cases. If you want to have a more logic and clear framework or library, please use another. This framework was created for only purpose - be similar ot Spring Framework by ideas and usages.

To drive into the framework, go to Getting Started.

To have more understanding, how the framerork works, there four main categories:

You free to go to any group and read it. It will be helpful and more explaning about works in the framework.

Getting Started

The package is available only in GitHub packages. I don't have any reasons to use in Maven registry. So, please, read the documentation about using GitHub packages:

In the main class (i.e. Main.java), write:

import jarkz.tbot.TBotApplication;

public class Main {
    public static void main(String.. args) {
        // Launches a TBot application with a single thread count.
        TBotApplication.launch(Main.class);
    }
}

If you will try run application, in will fall into exception, because you didn't set BOT_TOKEN as environment variable. I did it for security instead of manual setting bot token. So, please, create your bot in Telegram using Bot Father.

Next, need to create handler, which will print all given events, so create the other class in the same package:

import jarkz.tbot.types.Update;
import jarkz.tbot.core.Rule;

public class EventPrinter {

    @Rule(mentionedClass = EventPrinter.class, methodName = "anyUpdates")
    public void printEvent(Update event) {
        System.out.println(event);
    }

    public boolean anyUpdates(Update event) {
        return true;
    }
}

And, that's all! As you can see, the method printEvent is handler, which will be called if the rule as the method anyUpdates is passes. Sadly that I need to have more information about calling method for the @Rule annotation because of the Java syntax restriction, so the @Rule annotation must to have information about class where find needed method as mentionedClass and the method name.

Also the rule method have restrictions: must return boolean type and acquire only Update type. In this example, the rule method will pass all events, because it always returns true value. If you want to have custom behavior, use the Update and here I warn you that any data type is data structs and it doesn't have any defense mechanism from null-check.

Using BOT_TOKEN as environment variable, you can run the application. Any messages, that you will send to bot, will printed in terminal output.

License

MIT

About

Comfortable and powerful framework for Telegram API bot

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages