elbekD / kt-telegram-bot

Telegram Bot Library for Kotlin language
MIT License
103 stars 19 forks source link

Chains processing by all bots. Cannot assign chain with same command to multiple bots. #60

Open Krokodilushka opened 1 year ago

Krokodilushka commented 1 year ago

Thank you for the library. I faced a problem with chains. For example, I cannot run multiple bots with chain command '/create_order'. Method onCommand works fine for all bots, but it is not for chains.

val token1 = "<TOKEN1>"
val token2 = "<TOKEN2>"
val bot1 = Bot.createPolling(token1)
val bot2 = Bot.createPolling(token2)

// Both bots process this chain. We can see that every bot have its message id sequence
// One bot can start chain and another bot can finish this chain
bot1.chain("/test") {
    println("step1 messageId ${it.messageId}")
}.then {
    println("step2 messageId ${it.messageId}")
}.build()

// This chain processing by both bots
bot1.chain("/order") {
    println("bot 1 processing this order")
}.then {
    println("bot 1 processing this order")
}.build()
// This chain not processing by any bot
bot2.chain("/order") {
    println("bot 2 processing this order")
}.then {
    println("bot 2 processing this order")
}.build()

bot1.start()
bot2.start()

I think this problem because ChainController is object. I fixed it for me. Probably, it might be added to the original code. There are need your review, some comments in code and probably something else. My branch: https://github.com/Krokodilushka/kt-telegram-bot/tree/chain-controller Example: https://github.com/Krokodilushka/kt-telegram-bot/blob/chain-controller/examples/src/main/kotlin/LongPollingExample.kt I did not collaborate on github yet. Write me if it required my actions.