mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-09-15 13:19:21 +00:00
complete sample with native
This commit is contained in:
@@ -20,6 +20,8 @@ kotlin {
|
||||
browser()
|
||||
binaries.executable()
|
||||
}
|
||||
linuxX64()
|
||||
mingwX64()
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
|
@@ -15,11 +15,7 @@ suspend fun activateResenderBot(
|
||||
token: String,
|
||||
print: (Any) -> Unit
|
||||
) {
|
||||
val bot = telegramBot(token)
|
||||
|
||||
print(bot.getMe())
|
||||
|
||||
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
||||
telegramBotWithBehaviourAndLongPolling(token, scope = CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
||||
onContentMessage(
|
||||
subcontextUpdatesFilter = MessageFilterByChat,
|
||||
) {
|
||||
@@ -43,5 +39,6 @@ suspend fun activateResenderBot(
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
println(it)
|
||||
}
|
||||
}.join()
|
||||
print(bot.getMe())
|
||||
}.second.join()
|
||||
}
|
||||
|
46
ResenderBot/native_launcher/build.gradle
Normal file
46
ResenderBot/native_launcher/build.gradle
Normal file
@@ -0,0 +1,46 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
}
|
||||
|
||||
|
||||
kotlin {
|
||||
def hostOs = System.getProperty("os.name")
|
||||
def isMingwX64 = hostOs.startsWith("Windows")
|
||||
def nativeTarget
|
||||
if (hostOs == "Linux") nativeTarget = linuxX64("native") { binaries { executable() } }
|
||||
else if (isMingwX64) nativeTarget = mingwX64("native") { binaries { executable() } }
|
||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
api project(":ResenderBot:ResenderBotLib")
|
||||
}
|
||||
}
|
||||
|
||||
nativeMain {
|
||||
dependencies {
|
||||
def engine
|
||||
|
||||
if (hostOs == "Linux") engine = "curl"
|
||||
else if (isMingwX64) engine = "winhttp"
|
||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
||||
|
||||
api "io.ktor:ktor-client-$engine:$ktor_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
fun main(vararg args: String) {
|
||||
runBlocking {
|
||||
activateResenderBot(args.first()) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user