
Set of libraries for interacting with the Telegram Bot API, featuring examples for commands, handling updates, and building complex behaviors with long polling. Offers extensive documentation and community support.
| Docs |
|
|---|---|
| Useful repos |
|
| Misc |
|
| Platforms |
|
| Experimental Platforms |
|
Hello! This is a set of libraries for working with Telegram Bot API.
There are several things you need to do to launch examples below:
mavenCentral() to your project repositories
implementation "dev.inmo:tgbotapi:$tgbotapi_version"
tgbotapi_version with exact version (see last one in the table above) or put variable with this name in projectMore including instructions available here. Other configuration examples:
suspend fun main() {
val bot = telegramBot(TOKEN)
bot.buildBehaviourWithLongPolling {
println(getMe())
onCommand("start") {
reply(it, "Hi:)")
}
}.join()
}In this example you will see information about this bot at the moment of starting and answer with Hi:) every time it
gets message /start
suspend fun main() {
val bot = telegramBot(TOKEN)
val flowsUpdatesFilter = FlowsUpdatesFilter()
bot.buildBehaviour(flowUpdatesFilter = flowsUpdatesFilter) {
println(getMe())
onCommand("start") {
reply(it, "Hi:)")
}
retrieveAccumulatedUpdates(this).join()
}
}The main difference with the previous example is that bot will get only last updates (accumulated before bot launch and maybe some updates it got after launch)
suspend fun main() {
val bot = telegramBot(TOKEN)
bot.buildBehaviourWithLongPolling {
println(getMe())
val nameReplyMarkup = ReplyKeyboardMarkup(
matrix {
row {
+SimpleKeyboardButton("nope")
}
}
)
onCommand("start") {
val photo = waitPhoto(
SendTextMessage(it.chat.id, "Send me your photo please")
).first()
val name = waitText(
SendTextMessage(
it.chat.id,
"Send me your name or choose \"nope\"",
replyMarkup = nameReplyMarkup
)
).first().text.takeIf { it != "nope" }
sendPhoto(
it.chat,
photo.mediaCollection,
entities = buildEntities {
if (name != null) regular(name) // may be collapsed up to name ?.let(::regular)
}
)
}
}.join()
}You may find examples in this project. Besides, you are always welcome in our docs and chat.
Under the hood, default bots realizations will try to use links (PathedFile#filePath) as files each time you are trying to download file from telegram in any way - via saving to file, use stream or download as byte array. To let bot correctly download files from bot api server, you must:
101 UID/GID in linux for user and group as owners. So, your bot must run under user included in 101 group
(like systemd-journal) or be 101 UID user (like systemd-resolve)| Docs |
|
|---|---|
| Useful repos |
|
| Misc |
|
| Platforms |
|
| Experimental Platforms |
|
Hello! This is a set of libraries for working with Telegram Bot API.
There are several things you need to do to launch examples below:
mavenCentral() to your project repositories
implementation "dev.inmo:tgbotapi:$tgbotapi_version"
tgbotapi_version with exact version (see last one in the table above) or put variable with this name in projectMore including instructions available here. Other configuration examples:
suspend fun main() {
val bot = telegramBot(TOKEN)
bot.buildBehaviourWithLongPolling {
println(getMe())
onCommand("start") {
reply(it, "Hi:)")
}
}.join()
}In this example you will see information about this bot at the moment of starting and answer with Hi:) every time it
gets message /start
suspend fun main() {
val bot = telegramBot(TOKEN)
val flowsUpdatesFilter = FlowsUpdatesFilter()
bot.buildBehaviour(flowUpdatesFilter = flowsUpdatesFilter) {
println(getMe())
onCommand("start") {
reply(it, "Hi:)")
}
retrieveAccumulatedUpdates(this).join()
}
}The main difference with the previous example is that bot will get only last updates (accumulated before bot launch and maybe some updates it got after launch)
suspend fun main() {
val bot = telegramBot(TOKEN)
bot.buildBehaviourWithLongPolling {
println(getMe())
val nameReplyMarkup = ReplyKeyboardMarkup(
matrix {
row {
+SimpleKeyboardButton("nope")
}
}
)
onCommand("start") {
val photo = waitPhoto(
SendTextMessage(it.chat.id, "Send me your photo please")
).first()
val name = waitText(
SendTextMessage(
it.chat.id,
"Send me your name or choose \"nope\"",
replyMarkup = nameReplyMarkup
)
).first().text.takeIf { it != "nope" }
sendPhoto(
it.chat,
photo.mediaCollection,
entities = buildEntities {
if (name != null) regular(name) // may be collapsed up to name ?.let(::regular)
}
)
}
}.join()
}You may find examples in this project. Besides, you are always welcome in our docs and chat.
Under the hood, default bots realizations will try to use links (PathedFile#filePath) as files each time you are trying to download file from telegram in any way - via saving to file, use stream or download as byte array. To let bot correctly download files from bot api server, you must:
101 UID/GID in linux for user and group as owners. So, your bot must run under user included in 101 group
(like systemd-journal) or be 101 UID user (like systemd-resolve)