mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template.git
synced 2025-12-31 10:29:13 +00:00
Compare commits
49 Commits
0.32.0
...
e6b75e5000
| Author | SHA1 | Date | |
|---|---|---|---|
| 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
|
||||||
|
|||||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
FROM adoptopenjdk/openjdk11
|
||||||
|
|
||||||
|
USER 1000
|
||||||
|
|
||||||
|
VOLUME /config.json
|
||||||
|
|
||||||
|
ENTRYPOINT ["/telegram_bot/bin/telegram_bot", "TOKEN"]
|
||||||
|
|
||||||
|
ADD ./build/distributions/telegram_bot.tar /
|
||||||
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
|
||||||
@@ -17,6 +17,13 @@ output you will get your bot information like:
|
|||||||
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:
|
||||||
|
|||||||
20
build.gradle
20
build.gradle
@@ -1,31 +1,35 @@
|
|||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = 'telegram_bot.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,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.6.10"
|
||||||
|
tgbotapi = "0.38.12"
|
||||||
|
|
||||||
|
[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.4.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")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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 kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
@@ -18,16 +18,18 @@ suspend fun main(args: Array<String>) {
|
|||||||
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 prinln will be started long polling and bot will
|
||||||
|
// react on your commands
|
||||||
|
println(me)
|
||||||
|
}.join()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user