mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template.git
synced 2024-12-05 00:10:12 +00:00
Compare commits
7 Commits
7c2115739a
...
6a203863c7
Author | SHA1 | Date | |
---|---|---|---|
6a203863c7 | |||
dcb3665adc | |||
699b58f952 | |||
ea4a906e9a | |||
1bbd3b2ea1 | |||
5f2924c21b | |||
873e495daa |
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,5 +9,6 @@ settings.xml
|
|||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
|
|
||||||
local.properties
|
local.*
|
||||||
|
local.*/
|
||||||
secret.gradle
|
secret.gradle
|
||||||
|
@ -2,6 +2,7 @@ FROM adoptopenjdk/openjdk11
|
|||||||
|
|
||||||
USER 1000
|
USER 1000
|
||||||
|
|
||||||
ENTRYPOINT ["/telegram_bot/bin/telegram_bot", "TOKEN"]
|
ENTRYPOINT ["/telegram_bot/bin/telegram_bot", "/telegram_bot/local.config.json"]
|
||||||
|
|
||||||
ADD ./build/distributions/telegram_bot.tar /
|
ADD ./build/distributions/telegram_bot.tar /
|
||||||
|
ADD ./local.config.json /telegram_bot/
|
||||||
|
@ -9,9 +9,7 @@ it was described [here](https://github.com/InsanusMokrassar/TelegramBotAPI#ok-wh
|
|||||||
|
|
||||||
## Default
|
## Default
|
||||||
|
|
||||||
Since you have used this repo as a template you can simply run command `./gradlew run --args="BOT_TOKEN"` (of course,
|
Since you have used this repo as a template you can copy file `example.config.json` as `local.config.json`, put there your bot token and simply run command `./gradlew run --args="local.config.json"`. As an output you will get your bot information like:
|
||||||
replace here `BOT_TOKEN` with your telegram bot token like `1234567890:ABCDEFGHIJKLM_OPqrstuvwxyz012345678`). As an
|
|
||||||
output you will get your bot information like:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ExtendedBot(id=ChatId(chatId=1234567890), username=Username(username=@username_of_your_bot), firstName=Name of bot, lastName=, canJoinGroups=(some boolean), canReadAllGroupMessages=(some boolean), supportsInlineQueries=(some boolean))
|
ExtendedBot(id=ChatId(chatId=1234567890), username=Username(username=@username_of_your_bot), firstName=Name of bot, lastName=, canJoinGroups=(some boolean), canReadAllGroupMessages=(some boolean), supportsInlineQueries=(some boolean))
|
||||||
|
3
example.config.json
Normal file
3
example.config.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"token": "your bot token"
|
||||||
|
}
|
@ -5,14 +5,20 @@ import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import java.io.File
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method by default expects one argument in [args] field: telegram bot token
|
* This method by default expects one argument in [args] field: telegram bot condiguration
|
||||||
*/
|
*/
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
|
// create json to decode config
|
||||||
|
val json = Json { ignoreUnknownKeys = true }
|
||||||
|
// decode config
|
||||||
|
val config: Config = json.decodeFromString(Config.serializer(), File(args.first()).readText())
|
||||||
// that is your bot
|
// that is your bot
|
||||||
val bot = telegramBot(args.first())
|
val bot = telegramBot(config.token)
|
||||||
|
|
||||||
// that is kotlin coroutine scope which will be used in requests and parallel works under the hood
|
// that is kotlin coroutine scope which will be used in requests and parallel works under the hood
|
||||||
val scope = CoroutineScope(Dispatchers.Default)
|
val scope = CoroutineScope(Dispatchers.Default)
|
||||||
|
8
src/main/kotlin/telegram_bot/Config.kt
Normal file
8
src/main/kotlin/telegram_bot/Config.kt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package telegram_bot
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Config(
|
||||||
|
val token: String
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user