Answer the question
In order to leave comments, you need to log in
Request handler from N telegram bots?
Good afternoon! Let's say I have N records in the database with keys to telegram bots. Of course, webhooks are delivered to different URLs, but they have one handler.
I have a method in which I create a connection, and then I go through them in a loop, but from whichever bot I send a message, only the first one responds. Tell me what exactly am I doing wrong?
public function hendle()
{
$bots = [];
$bots[] = new Api('здесь первый ключ');
$bots[] = new Api('здесь второй ключ');
$instance = [];
foreach ($bots as $key => $bot)
{
if ($bot->getWebhookUpdates())
{
$request = $bot->getWebhookUpdates();
if(isset($request['message']))
{
$instance['message'] = $request['message'];
$instance['bot'] = $bot;
$instance['me'] = $request->getMe();
}
}
}
$chat_id = $instance['message']['chat']['id'];
return $instance['bot']->sendMessage([
'chat_id' => $chat_id,
'text' => "Hello World",
]);
}
Answer the question
In order to leave comments, you need to log in
In your question and example - collapse. You write that webhooks are installed. But in this case, you do not need to request any updates - they themselves arrive at the url specified in the webhook. And in the same place you get the id of the bot and all the necessary data on the sender / recipient
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question