apimorphism / telegramium

Telegramium or F[ Tg ] - pure functional Telegram Bot API implementation for Scala.
MIT License
82 stars 9 forks source link

Question: Multi sub-module bot entrypoint #142

Closed benkio closed 3 years ago

benkio commented 3 years ago

Hi, I write this issue to ask if there's a way to run multiple bots using a single entrypoint:

I have a multi sub-module project organized in this way:

project/
|----main
|----bot1
|----bot2
|----commonLib

Telegramium is used into the commonLib that's shared between all the sub module bots and then the main module should run all the bots in a single entrypoint. Each sub-module also has its own main and if I run sbt bot1/run & sbt bot2/run they work without problems, but if I try sbt main/run I got this error:

[error] telegramium.bots.high.FailedRequest: method=getUpdates code=409 description=Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
[error]     at telegramium.bots.high.BotApi.$anonfun$handleResponse$1(BotApi.scala:80)
[error]     at ifM @ org.http4s.client.PoolManager.createConnection(PoolManager.scala:126)
[error]     at uncancelable @ org.http4s.client.ConnectionManager$.pool(ConnectionManager.scala:83)
[error]     at map @ telegramium.bots.high.BotApi.$anonfun$handleResponse$1(BotApi.scala:71)
[error]     at uncancelable @ org.http4s.client.ConnectionManager$.pool(ConnectionManager.scala:83)
[error]     at uncancelable @ org.http4s.client.ConnectionManager$.pool(ConnectionManager.scala:83)
[error]     at flatMap @ org.http4s.client.PoolManager.releaseRecyclable(PoolManager.scala:225)
[error]     at uncancelable @ org.http4s.client.ConnectionManager$.pool(ConnectionManager.scala:83)
[error]     at withPermit @ org.http4s.client.PoolManager.shutdown(PoolManager.scala:370)
[error]     at uncancelable @ org.http4s.client.ConnectionManager$.pool(ConnectionManager.scala:83)
[error]     at withPermit @ org.http4s.client.PoolManager.shutdown(PoolManager.scala:370)
[error] [scala-execution-context-global-26] ERROR telegramium.bots.high.BotApi - Telegram Bot API request failed: code=409 description="Conflict: terminated by other getUpdates request; make sure that only one bot instance is running" method=getUpdates, JSON: 
[error] {
[error]   "offset" : 0,
[error]   "timeout" : 10,
[error]   "allowed_updates" : [
[error]   ],
[error]   "method" : "getUpdates"
[error] }

What should I do in order to run all the bot at once into the main? I expect I need to change some configuration and pass a custom one to each bot in order to avoid clashes/collisions in the connection, or something like that :pray:

johnspade commented 3 years ago

It looks like you launch multiple bots with the same token. Can you check that?

benkio commented 3 years ago

I'll check ASAP, but each bot has it's own resource folder. I'll put a println and let you know.

benkio commented 3 years ago

I checked and they actually were picking up the same bot.token file. Customizing the name of the file solved the issue. Closing :pray: