Version 1.5 this is a transitional version, in version 2.0 the features of 1.0 (creation through function overrides) will be cut in favor of an emphasis on the annotation management system, and also the possibilities of multi-botUser multi-threaded work will be implemented
The operation of the multi-botUser bot has not been tested and is at the development stage, bugs and critical errors are possible
Publishing to Maven Central with version 2.0 release
Please give my repository a ⭐, it will help me know that someone is using it
Version 1.5.x early access
Maven
<dependency>
<groupId>io.github.vilshiro</groupId>
<artifactId>mcb</artifactId>
<version>1.5.4</version>
</dependency>Gradle
implementation group: 'io.github.vilshiro', name: 'mcb', version: '1.5.4'Create a class that is a descendant of the class Bot and override the necessary functions, the constructor accepts the bot token
Use the getBot() command to get a bot instance
MyBot.java
public class MyBot extends Bot {
public MyBot() {
super("your token");
}
@Override
protected void updateParse(Update update) {
// your logic
}
@Override
protected void messageParse(Message message) {
// parsing the messages
}
@Override
protected void callbackQueryParse(CallbackQuery query) {
// callback data...
}
}First, you must create a class that is a descendant of the Bot class and implement one of the constructors (recommended with a configuration class)
MyBot.java
public class MyBot extends Bot{
public MyBot(){
super(MyConfig.class);
}
}Next, in the specified MyConfig class, add the BotConfiguration annotation and specify the token
MyConfig.java
@BotConfiguration(botToken = "your token")
public class MyConfig {
}Additional BotConfiguration parameters:
| parameter | type | functionality |
|---|---|---|
| threadSeparation | boolean | each command will run in its own thread |
| startCommand | String | start command, usually /start |
| doubleDispatch | boolean | when disabled - updates come only to annotated functions, when enabled - to annotated functions and overridden ones |
| staticBuild | boolean | does not create an instance of the configuration class within itself, the value is ignored if the @BotConfiguration annotation is on a class that is a descendant of the Bot class, only static functions will be executed |
Create any function, add the annotation @Feedback, add any set of parameters available for this function
In the annotation, specify a string indicating the type of updates that it can process
@BotConfiguration(botToken = "your token")
public class MyConfig {
@Feedback("update")
public void onUpdate() {
// parse your update here
}
@Feedback("message")
private static void message(Bot bot) {
// also parse messages here
}
@Feedback("start")
private void runBot(Message message, Bot bot) {
// code here
}
}Parameter sets for update processing functions Constants.java
| type | parameter set(classes) |
|---|---|
| update | com.pengrad.telegrambot.model.Update, org.fbs.mcb.form.Bot |
| start | com.pengrad.telegrambot.model.Update, com.pengrad.telegrambot.model.Message, org.fbs.mcb.form.Bot |
| message | com.pengrad.telegrambot.model.Update, com.pengrad.telegrambot.model.Message, org.fbs.mcb.form.Bot |
| entities | com.pengrad.telegrambot.model.Update, com.pengrad.telegrambot.model.Message, com.pengrad.telegrambot.model.MessageEntity[], org.fbs.mcb.form.Bot |
| callback_query | com.pengrad.telegrambot.model.Update, com.pengrad.telegrambot.model.CallbackQuery, org.fbs.mcb.form.Bot |
| inline_query | com.pengrad.telegrambot.model.Update, com.pengrad.telegrambot.model.InlineQuery, org.fbs.mcb.form.Bot |
| command | com.pengrad.telegrambot.model.Update, com.pengrad.telegrambot.model.Message, com.pengrad.telegrambot.model.MessageEntity[], org.fbs.mcb.form.Bot |
Create any function, add the annotation @Command, inside specify a line pointing to the command that is bound to this function
@BotConfiguration(botToken = "your token")
public class MyConfig {
@Command("/help")
private void help(Bot bot) {
// realize algorithm here
}
@Command("/exit")
public static void save(Message message){
// saving logic...
}
}Command functions have the same parameter sets as @Feedback("entities"), but without MessageEntities array
public class Main{
public static void main(String[] args) {
new MyBot();
}
}- If the bot token is specified via the constructor, but a configuration containing the token is also added, the bot will have the token specified via the constructor
- Add a buffer of processed methods for faster response to updates
- Implementation of multi-botUser functionality
- Possibility of implementing third-party Telegram Bot API
- Increase the autonomy of each element
- IDE Intellij Idea
- Base bot realization pengrad telegram bot api
- Tests junit
