34 lines
1.1 KiB
Kotlin
Raw Normal View History

2020-11-08 18:54:22 +06:00
package telegram_bot
2020-12-08 15:31:26 +06:00
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
2020-11-08 18:54:22 +06:00
import dev.inmo.tgbotapi.extensions.api.bot.getMe
2021-01-29 16:51:08 +06:00
import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
import kotlinx.coroutines.*
2020-11-08 18:54:22 +06:00
/**
* This method by default expects one argument in [args] field: telegram bot token
*/
suspend fun main(args: Array<String>) {
2021-01-29 16:51:08 +06:00
// that is your bot
2020-11-08 18:54:22 +06:00
val bot = telegramBot(args.first())
2021-01-29 16:51:08 +06:00
// that is kotlin coroutine scope which will be used in requests and parallel works under the hood
val scope = CoroutineScope(Dispatchers.Default)
// here should be main logic of your bot
bot.buildBehaviour(scope) {
// in this lambda you will be able to call methods without "bot." prefix
val me = getMe()
// this method will create point to react on each /start command
onCommand("/start", requireOnlyCommandInMessage = true) {
// simply reply :)
reply(it, "Hello, I am ${me.firstName}")
}
}
scope.coroutineContext.job.join()
2020-11-08 18:54:22 +06:00
}