Compare commits

...

7 Commits

Author SHA1 Message Date
6a203863c7
Update Dockerfile 2022-06-17 03:31:53 +06:00
dcb3665adc
Update README.md 2022-06-17 03:30:32 +06:00
699b58f952
Update App.kt 2022-06-17 03:26:56 +06:00
ea4a906e9a
Create example.config.json 2022-06-17 03:25:46 +06:00
1bbd3b2ea1
Update App.kt 2022-06-17 03:24:35 +06:00
5f2924c21b
Create Config.kt 2022-06-17 03:19:47 +06:00
873e495daa
Update .gitignore 2022-06-17 02:20:00 +06:00
6 changed files with 24 additions and 7 deletions

3
.gitignore vendored
View File

@ -9,5 +9,6 @@ settings.xml
build/
out/
local.properties
local.*
local.*/
secret.gradle

View File

@ -2,6 +2,7 @@ FROM adoptopenjdk/openjdk11
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 ./local.config.json /telegram_bot/

View File

@ -9,9 +9,7 @@ it was described [here](https://github.com/InsanusMokrassar/TelegramBotAPI#ok-wh
## Default
Since you have used this repo as a template you can simply run command `./gradlew run --args="BOT_TOKEN"` (of course,
replace here `BOT_TOKEN` with your telegram bot token like `1234567890:ABCDEFGHIJKLM_OPqrstuvwxyz012345678`). As an
output you will get your bot information like:
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:
```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))

3
example.config.json Normal file
View File

@ -0,0 +1,3 @@
{
"token": "your bot token"
}

View File

@ -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.behaviour_builder.buildBehaviourWithLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
import java.io.File
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>) {
// 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
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
val scope = CoroutineScope(Dispatchers.Default)

View File

@ -0,0 +1,8 @@
package telegram_bot
import kotlinx.serialization.Serializable
@Serializable
data class Config(
val token: String
)