Get started
To use the library, all you need to do is add a dependency, build a config, specify token and username and create the bot and its context.
Ready-to-use solution for use with Spring.
build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.dehuckakpyt.telegrambot:telegram-bot-core:0.11.4")
implementation("io.github.dehuckakpyt.telegrambot:telegram-bot-spring:0.11.4")
}
com/example/myproject/config/BotConfig.kt
@EnableTelegramBot
@Configuration
class BotConfig {
@Bean //optional bean
fun telegramBotConfig(): TelegramBotConfig = TelegramBotConfig().apply {
//configure..
}
}
resources/application.properties
telegram-bot.token=${TELEGRAM_BOT_TOKEN}
telegram-bot.username=${TELEGRAM_BOT_USERNAME}
com/example/myproject/handler/StartHandler.kt
@HandlerComponent
class StartHandler : BotHandler({
command("/start") {
sendMessage("Hello, my name is ${bot.username} :-)")
}
})
Ready-to-use solution for use with Ktor+Koin.
build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.dehuckakpyt.telegrambot:telegram-bot-core:0.11.4")
implementation("io.github.dehuckakpyt.telegrambot:telegram-bot-ktor:0.11.4")
}
com/example/myproject/KtorApp.kt
fun Application.module() {
install(Koin) {
modules(defaultModule)
}
install(TelegramBot)
}
resources/application.conf
telegram-bot {
token = ${TELEGRAM_BOT_TOKEN}
username = ${TELEGRAM_BOT_USERNAME}
}
com/example/myproject/handler/StartHandler.kt
@Factory
class StartHandler : BotHandler({
command("/start") {
sendMessage("Hello, my name is ${bot.username} :-)")
}
})
Can be used for integrate with any frameworks manually.
build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.dehuckakpyt.telegrambot:telegram-bot-core:0.11.4")
}
com/example/myproject/KtorApp.kt
fun main(args: Array<String>): Unit {
val config = TelegramBotConfig().apply {
token = "<bot token required>"
username = "<bot username required>"
receiving {
handling {
startCommand()
}
}
}
val context = TelegramBotFactory.createTelegramBotContext(config)
val bot = context.telegramBot
val updateReceiver = context.updateReceiver
// start and stop for example only, use this methods with starting and stopping your application
updateReceiver.start()
readlnOrNull()
updateReceiver.stop()
}
com/example/myproject/handler/StartHandler.kt
fun BotHandling.startCommand() {
command("/start") {
sendMessage("Hello, my name is ${bot.username} :-)")
}
}
Containing modules
Common
io.github.dehuckakpyt.telegrambot:telegram-bot-core:0.11.4
io.github.dehuckakpyt.telegrambot:telegram-bot-spring:0.11.4
io.github.dehuckakpyt.telegrambot:telegram-bot-ktor:0.11.4
Testing
Link to Testing.
io.github.dehuckakpyt.telegrambot:telegram-bot-test:0.11.4
Database integration
Link to Spring JPA, to Exposed.
io.github.dehuckakpyt.telegrambot:telegram-bot-source-jpa:0.11.4
io.github.dehuckakpyt.telegrambot:telegram-bot-source-spring2-jpa:0.11.4
io.github.dehuckakpyt.telegrambot:telegram-bot-source-exposed:0.11.4
FreeMarker integration
Link to Templating.
io.github.dehuckakpyt.telegrambot:telegram-bot-templater-freemarker:0.11.4
Last modified: 27 July 2024