Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.snqlby:tgwebhook:1.5.0'
}
dependencies {
implementation("com.github.snqlby:tgwebhook:1.5.0")
}
<dependency>
<groupId>com.github.snqlby</groupId>
<artifactId>tgwebhook</artifactId>
<version>1.5.0</version>
</dependency>
libraryDependencies += "com.github.snqlby" % "tgwebhook" % "1.5.0"
:dependencies [[com.github.snqlby/tgwebhook "1.5.0"]]
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: