Multiple bots in one application #552
-
Hi! I want to ask how I can use multiple bots in one Laravel application. I understand how to make webhooks for them, how to use the right bot at the right time Telegraph::bot("TOKEN")->chat('CHAT_ID')->message('some message')->send(); (I hope I understand correctly). But you can't keep two bots in the same handler, right? In any case, they will respond to commands together, and to prevent this from happening, you will most likely need to add a bunch of checks. So the question is, is it possible to specify a handler for each of the bots? 'webhook_handler' => \App\Telegram\Handler::class, Is there a way to do something like this: 'webhook_handler' => [
'bot1' => FirstHandler::class,
'bot2' => SecondHandler::class
], I am waiting for your reply, thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi! in this case you should use the main handler to detect the bot and call the dedicated handle: class MainWebhookHandler extends WebhookHandler
{
public function handle(Request $request, TelegraphBot $bot): void
{
match($bot->id){
1 => app(Bot1WebhookHandler::class)->handle($request, $bot),
2 => app(Bot2WebhookHandler::class)->handle($request, $bot),
3 => app(Bot3WebhookHandler::class)->handle($request, $bot),
default => parent::handle($request, $bot),
}
}
} |
Beta Was this translation helpful? Give feedback.
Hi!
in this case you should use the main handler to detect the bot and call the dedicated handle: