First bot¶
Examples info
A lot of examples with using of Telegram Bot API you can find in this github repository
The most simple bot¶
The most simple bot will just print information about itself. All source code you can find in this repository. Our interest here will be concentrated on the next example part:
suspend fun main(vararg args: String) {
val botToken = args.first()
val bot = telegramBot(botToken)
println(bot.getMe())
}
So, let’s get understanding, about what is going on:
suspend fun main(vararg args: String)
:suspend
required for making of requests inside of this function. For more info you can open official documentation for coroutins. In fact,suspend fun main
is the same thatfun main() = runBlocking {}
from examples
val botToken = args.first()
: here we are just getting the bot token from first arguments of command lineval bot = telegramBot(botToken)
: inside ofbot
will be RequestsExecutor object which will be used for all requests in any project with this libraryprintln(bot.getMe())
: here happens calling of getMe extension
As a result, we will see in the command line something like