This library contains an implementation to process Webhook requests for rubenlagus/TelegramBots.
It provides simple ways to process incoming requests. Code reduction is achieved through the use of annotations to configure accepted requests.
@AcceptTypes({UpdateType.MESSAGE})
@Component
public class StartHandler {
@CommandMethod(value = "/start", locality = Locality.PRIVATE)
public BotApiMethod onStartCommand(AbsSender bot, Message message, List<String> args) {
return new SendMessage()
.setText("Hello world")
.setChatId(message.getChatId());
}
}
JitPack: see here
GuardBot: https://github.com/snqlby/guardbot
If you are using Spring for your application, try the following way:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
final Map<String, Object> handlers = context.getBeansWithAnnotation(AcceptTypes.class);
handlers.values().forEach(handler -> {
Handlers.addHandler(handler);
});
}
}
/*
Your code with
1. TelegramWebhookBot bot implementation
2. var resolver = new RequestResolver(bot);
*/
public BotApiMethod<?> yourMethodName(Update update) {
return resolver.handleRequest(update);
}
Supported annotations:
- @InlineMethod
- @CallbackMethod(data, game_short_name, locality, origin)
- @ChannelPostMethod
- @JoinMethod(room, reason)
- @LeaveMethod(room, reason)
- @EditedChannelPostMethod
- @MessageMethod(locality,flag)
- @EditedMessageMethod
- @CommandMethod(command, locality)
- @PreCheckoutMethod
- @ShippingMethod