visciang / telegram

Telegram library for the Elixir language
MIT License
204 stars 27 forks source link

bad child specification, more than one child specification has the id #153

Closed SimuraEpona closed 1 year ago

SimuraEpona commented 1 year ago

Hi,

thanks for creating this fantastic library.

currently, I'm having this problem.

first, I have two Bots BotA and BotB,

then, I add Poller to the Supervisor like this

    bot_config = [
      token: token,
      max_bot_concurrency: 1_000
    ]

    children = [
      {Telegram.Poller,
       bots: [
         {BotA, bot_config},
         {BotB, bot_config}
       ]}
    ]
Supervisor.init(children, strategy: :one_for_all)

after I start up my server, the error occurs.

** (Mix) Could not start application triforce: Triforce.Application.start(:normal, []) returned an error: shutdown: failed to start child: Triforce.Telegram.BotSupervisor
    ** (EXIT) shutdown: failed to start child: Telegram.Poller
        ** (EXIT) bad child specification, more than one child specification has the id: :"Elixir.Telegram.Poller.Task.xxxxxxx".
If using maps as child specifications, make sure the :id keys are unique.
If using a module or {module, arg} as child, use Supervisor.child_spec/2 to change the :id, for example:

    children = [
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_1),
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_2)
    ]

am I using Poller the wrong way?

visciang commented 1 year ago

Hi @SimuraEpona,

If you use multiple bots (in your example BotA and BotB) every bot should have it's own unique bot token - the bot identity in the telegram bot world.

bot_A_config = [token: token_A, max_bot_concurrency: 1_000]
bot_B_config = [token: token_B, max_bot_concurrency: 1_000]

children = [
  {Telegram.Poller,
   bots: [
     {BotA, bot_A_config},
     {BotB, bot_B_config}
   ]}
]
SimuraEpona commented 1 year ago

@visciang Thanks, I'll try it.