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.seik:kotlin-telegram-bot:4.6.0'
}
dependencies {
implementation("com.github.seik:kotlin-telegram-bot:4.6.0")
}
<dependency>
<groupId>com.github.seik</groupId>
<artifactId>kotlin-telegram-bot</artifactId>
<version>4.6.0</version>
</dependency>
libraryDependencies += "com.github.seik" % "kotlin-telegram-bot" % "4.6.0"
:dependencies [[com.github.seik/kotlin-telegram-bot "4.6.0"]]
A wrapper for the Telegram Bot API written in Kotlin.
Creating a bot instance is really simple:
fun main(args: Array<String>) {
val bot = bot {
token = "YOUR_API_KEY"
}
}
Now lets poll telegram API and route all text updates:
fun main(args: Array<String>) {
val bot = bot {
token = "YOUR_API_KEY"
dispatch {
text { bot, update ->
val text = update.message?.text ?: "Hello, World!"
bot.sendMessage(chatId = update.message!!.chat.id, text = text)
}
}
}
bot.startPolling()
}
Want to route commands?:
fun main(args: Array<String>) {
val bot = bot {
token = "YOUR_API_KEY"
dispatch {
command("start") { bot, update->
val result = bot.sendMessage(chatId = update.message!!.chat.id, text = "Hi there!")
result.fold({
// do something here with the response
},{
// do something with the error
})
}
}
}
bot.startPolling()
}
Take a look at the examples folder.
There are several samples:
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:x.y.z'
}
./gradlew ktlintFormat
./gradlew check
to see if tests and ktlint pass.Kotlin Telegram Bot is under the Apache 2.0 license. See the LICENSE for more information.