mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template.git
synced 2025-10-13 03:10:29 +00:00
Compare commits
108 Commits
0.32.0
...
50442ddcb8
Author | SHA1 | Date | |
---|---|---|---|
50442ddcb8 | |||
2f981eb68b | |||
c26832f7a9 | |||
819c2fdb0d | |||
ebab694ac3 | |||
d82b62a069 | |||
098fed3b81 | |||
bc3662da25 | |||
2da218c805 | |||
c5638743af | |||
faa77ef5ac | |||
607bd00a3c | |||
0c5bbd5bb1 | |||
3ee9f9c46b | |||
f7ff501e58 | |||
353c28657d | |||
dfe0b475b4 | |||
ff63fad928 | |||
9538d320cf | |||
8d9be29f6e | |||
99a4ea2b12 | |||
0c66784ab7 | |||
df25274079 | |||
6cd6489cb2 | |||
5c6ad721d2 | |||
2acf32ec62 | |||
|
d0905c6d17 | ||
b243a19cdf | |||
ec944a3e68 | |||
4becd4fe60 | |||
acd13ea731 | |||
00363fd506 | |||
59b948bece | |||
8a857d3109 | |||
6ffe47d645 | |||
6088f79cc6 | |||
4747b48df4 | |||
f0aebfa800 | |||
04467a2416 | |||
a2e97be75a | |||
6a203863c7 | |||
dcb3665adc | |||
699b58f952 | |||
ea4a906e9a | |||
1bbd3b2ea1 | |||
5f2924c21b | |||
873e495daa | |||
7c2115739a | |||
50d5718ba0 | |||
12d345b067 | |||
a443205237 | |||
2afd9bb156 | |||
f41f756107 | |||
9b3a01a50b | |||
d5379b02e7 | |||
bf31c92bf1 | |||
ee93a83ed5 | |||
285afbe942 | |||
1e3cfeebcc | |||
e6b75e5000 | |||
4a71d78aba | |||
6e7210326a | |||
25583c6947 | |||
c7a5631184 | |||
9f1ae5bd17 | |||
1f2bd0b14a | |||
18ff841e9a | |||
a103cfb0f3 | |||
cbaf7277b0 | |||
ede5d944d5 | |||
0b08886be1 | |||
0487b44a3e | |||
ed12f41336 | |||
171a4a5060 | |||
0477319f12 | |||
fcc0b49576 | |||
e86d07d25d | |||
2c1f4e8202 | |||
14ce90d323 | |||
fbbc7d8cc0 | |||
c543f7ff6c | |||
77b61dff04 | |||
be4cefb875 | |||
97731ea814 | |||
6db81e1cb4 | |||
5428b048b8 | |||
86d535a1dc | |||
cf91388eef | |||
72e1e2feab | |||
dc1c783df3 | |||
df5c32a194 | |||
3181e7c985 | |||
0d9965f953 | |||
e2626f4163 | |||
f46b976f52 | |||
cfe4a79b19 | |||
31b5a18354 | |||
439d51cdfe | |||
84677466f2 | |||
28e5b337f2 | |||
25b264d8ed | |||
558c047d26 | |||
a82aad5985 | |||
424ab09c3d | |||
89e03ab1ed | |||
834ea36959 | |||
89164058af | |||
80b28bd7a9 |
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -8,9 +8,9 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up JDK 1.8
|
- name: Set up JDK 11
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
java-version: 11
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -9,5 +9,6 @@ settings.xml
|
|||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
|
|
||||||
local.properties
|
local.*
|
||||||
|
local.*/
|
||||||
secret.gradle
|
secret.gradle
|
||||||
|
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
FROM adoptopenjdk/openjdk11
|
||||||
|
|
||||||
|
USER 1000
|
||||||
|
|
||||||
|
ENTRYPOINT ["/telegram_bot/bin/telegram_bot", "/telegram_bot/local.config.json"]
|
||||||
|
|
||||||
|
ADD ./build/distributions/telegram_bot.tar /
|
||||||
|
ADD ./local.config.json /telegram_bot/
|
19
Makefile
Normal file
19
Makefile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!make
|
||||||
|
|
||||||
|
.ONESHELL:
|
||||||
|
.PHONY:
|
||||||
|
|
||||||
|
clean:
|
||||||
|
./gradlew clean
|
||||||
|
|
||||||
|
build:
|
||||||
|
./gradlew build
|
||||||
|
|
||||||
|
start:
|
||||||
|
./gradlew run
|
||||||
|
|
||||||
|
startCompose:
|
||||||
|
docker-compose build && docker-compose up
|
||||||
|
|
||||||
|
buildAndStartCompose:
|
||||||
|
make clean build startCompose
|
11
README.md
11
README.md
@@ -9,14 +9,19 @@ 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))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
|
In this template there is template-like [docker-compose](docker-compose.yml) and [docker](Dockerfile) files. Besides,
|
||||||
|
there is [Makefile](Makefile) and you may use something like `make buildAndStartCompose` to start your bot.
|
||||||
|
|
||||||
|
It is important to replace `"TOKEN"` in [Dockerfile](Dockerfile) or remove and add some config as a volume.
|
||||||
|
|
||||||
## What next?
|
## What next?
|
||||||
|
|
||||||
There are several ways to continue:
|
There are several ways to continue:
|
||||||
|
23
build.gradle
23
build.gradle
@@ -1,31 +1,36 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath libs.kotlin.gradle.plugin
|
||||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
classpath libs.kotlin.serialization.plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version"
|
alias libs.plugins.kotlin.jvm
|
||||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
alias libs.plugins.kotlin.serialization
|
||||||
id 'application'
|
id 'application'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation libs.kotlin
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$tgbotapi_version"
|
implementation libs.tgbotapi
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClassName = 'telegram_bot.AppKt'
|
mainClassName = 'AppKt'
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
|
6
docker-compose.yml
Normal file
6
docker-compose.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
version: "3.4"
|
||||||
|
|
||||||
|
services:
|
||||||
|
server:
|
||||||
|
build: .
|
||||||
|
restart: unless-stopped
|
3
example.config.json
Normal file
3
example.config.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"token": "your bot token"
|
||||||
|
}
|
@@ -3,6 +3,3 @@ kotlin.code.style=official
|
|||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
kotlin.js.generate.externals=true
|
kotlin.js.generate.externals=true
|
||||||
kotlin.incremental=true
|
kotlin.incremental=true
|
||||||
|
|
||||||
kotlin_version=1.4.21
|
|
||||||
tgbotapi_version=0.32.0
|
|
||||||
|
19
gradle/libs.versions.toml
Normal file
19
gradle/libs.versions.toml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
[versions]
|
||||||
|
|
||||||
|
kotlin = "1.8.20"
|
||||||
|
tgbotapi = "7.0.2"
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
|
||||||
|
kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
|
||||||
|
tgbotapi = { module = "dev.inmo:tgbotapi", version.ref = "tgbotapi" }
|
||||||
|
|
||||||
|
# Libs for classpath
|
||||||
|
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||||
|
kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
|
||||||
|
|
||||||
|
[plugins]
|
||||||
|
|
||||||
|
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||||
|
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
||||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@@ -1 +1,3 @@
|
|||||||
rootProject.name = 'telegram_bot'
|
rootProject.name = 'telegram_bot'
|
||||||
|
|
||||||
|
enableFeaturePreview("VERSION_CATALOGS")
|
||||||
|
@@ -1,33 +1,39 @@
|
|||||||
package telegram_bot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
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.buildBehaviour
|
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 configuration
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
|
|
||||||
// here should be main logic of your bot
|
// here should be main logic of your bot
|
||||||
bot.buildBehaviour(scope) {
|
bot.buildBehaviourWithLongPolling(scope) {
|
||||||
// in this lambda you will be able to call methods without "bot." prefix
|
// in this lambda you will be able to call methods without "bot." prefix
|
||||||
val me = getMe()
|
val me = getMe()
|
||||||
|
|
||||||
// this method will create point to react on each /start command
|
// this method will create point to react on each /start command
|
||||||
onCommand("/start", requireOnlyCommandInMessage = true) {
|
onCommand("start", requireOnlyCommandInMessage = true) {
|
||||||
// simply reply :)
|
// simply reply :)
|
||||||
reply(it, "Hello, I am ${me.firstName}")
|
reply(it, "Hello, I am ${me.firstName}")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
scope.coroutineContext.job.join()
|
// That will be called on the end of bot initiation. After that println will be started long polling and bot will
|
||||||
|
// react on your commands
|
||||||
|
println(me)
|
||||||
|
}.join()
|
||||||
}
|
}
|
6
src/main/kotlin/Config.kt
Normal file
6
src/main/kotlin/Config.kt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Config(
|
||||||
|
val token: String
|
||||||
|
)
|
Reference in New Issue
Block a user