-
Good afternoon, help to process the keyboard public function toTelegram($notifiable)
{
$chatId = $this->chatId;
$message = $this->message;
$bot = new TelegramNotification();
$pageUrl = env('APP_URL') . '/my-account/tasks'; // URL страницы для просмотра
$keyboard = [
[
new InlineKeyboardButton([
'text' => 'Відмовитися',
'callback_data' => 'taskReject'
]),
new InlineKeyboardButton([
'text' => 'Прийняти',
'callback_data' => 'taskAccept'
]),
],
[
new InlineKeyboardButton([
'text' => 'Переглянути на сайті',
'url' => $pageUrl
]),
],
];
$replyMarkup = new InlineKeyboardMarkup([
'inline_keyboard' => $keyboard,
]);
try {
$response = $bot->sendMessage([
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'HTML',
'reply_markup' => $replyMarkup,
'exceptions' => true,
]);
return $response;
} catch (TeleBotException $e) {
if ($e->getCode() == 403 && strpos($e->getMessage(), 'bot was blocked by the user') !== false) {
// Действия при блокировке бота пользователем
Log::error('Бот заблокирован пользователем.');
}
}
} Handler file <?php
namespace App\Telegram\Handlers\Admar;
use Illuminate\Support\Facades\Log;
use WeStacks\TeleBot\Handlers\CallbackHandler;
class TaskAdmarBotHandler extends CallbackHandler
{
protected string $match = '/^(taskReject|taskAccept)$/';
public function handle()
{
$data = $this->update->callback_query->data;
if ($data === 'taskReject') {
$this->handleTaskReject();
} elseif ($data === 'taskAccept') {
$this->handleTaskAccept();
}
$this->answerCallbackQuery();
}
private function handleTaskReject()
{
Log::info('handleTaskReject');
}
private function handleTaskAccept()
{
Log::info('handleTaskAccept');
}
} When I click on the button I get this error Bot: 'admar'; Update: 2222; Type: 'callback_query'
WeStacks\TeleBot\Exceptions\TeleBotException
Bad Request: query is too old and response timeout expired or query ID is invalid
at D:\OpenServer\domains\admar\vendor\westacks\telebot\src\Exceptions\TeleBotException.php:21
17▕ $parameters = ResponseParameters::create($result['parameters'] ?? null);
18▕ $text .= '; Parameters: '.$parameters;
19▕ }
20▕
➜ 21▕ return new static($text, $result['error_code']);
22▕ }
23▕ }
24▕
1 D:\OpenServer\domains\admar\vendor\westacks\telebot\src\Contracts\TelegramMethod.php:97
WeStacks\TeleBot\Exceptions\TeleBotException::requestError()
2 D:\OpenServer\domains\admar\vendor\guzzlehttp\promises\src\Promise.php:209
WeStacks\TeleBot\Contracts\TelegramMethod::WeStacks\TeleBot\Contracts\{closure}() If you delete the keyboard processing file, then everything works great |
Beta Was this translation helpful? Give feedback.
Answered by
punyflash
Jun 13, 2023
Replies: 1 comment
-
Hi! It seems everything fine with your code. As error says, you have old $this->exceptions(false)->answerCallbackQuery(); In that case, even if Telegram has expired callback query, the exception will not be thrown. Or you can catch the exception manually: try {
$this->answerCallbackQuery();
} catch (\Throwable $e) {
// process
} Or even using Laravel's helper: rescue(fn () => $this->answerCallbackQuery()); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
punyflash
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! It seems everything fine with your code. As error says, you have old
callback_query
update which was expired on telegram end. You can just do:In that case, even if Telegram has expired callback query, the exception will not be thrown. Or you can catch the exception manually:
Or even using Laravel's helper: