Answer the question
In order to leave comments, you need to log in
How to process callback from bot's telegrams by condition?
Hello smart people. I ask you to help.
The logic of the bot is such that a request is sent from Bitrix24 to the bot script (I used this library ), the bot receives data from Bitrix24 via GET.
Then sends in parallel with the data, the buttons to the group - in this form . Logically, when the user presses the button, the text in the order stage field should change.
Here at this moment I came to a standstill, the question is: how to process the incoming callback by condition. For example, when I now click on the button, the code is completely processed, and the messages fall into the group.
How to make it so that when the user clicks on the button, the text changes and the message does not fall (and so that they fall only if there is a request from Bitrix24). Approximately according to the logic I understand, but there is not enough knowledge (and there is not enough time). Can you help with the code...
<?php
//Подключаем библиотеку
include('vendor/autoload.php');
use Telegram\Bot\Api;
//Указываем токен телеграм бота
$telegram = new Api('******');
$result = $telegram->getWebhookUpdates();
$result = json_decode($result, True);
//получаем данные с callback_query
$callback_data = $result['callback_query']['data'];
$callback_id = $result['callback_query']['message']['chat']['id'];
$callback_message_id = $result['callback_query']['message']['message_id'];
//собираем инлайн кнопки в объект
$text = 'Отправлен в группу';
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "Готовится",
"callback_data" => "Готовится"
],
[
"text" => "Отправлен",
"callback_data" => "Отправлен"
],
[
"text" => "Отменен",
"callback_data" => "Отменен"
]
]
]
]);
$telegram->sendMessage([
'chat_id' => -*****,
'text' => 'Стадия заказа: '.$text,
'reply_markup' => $keyboard
]);
if ($callback_data = true){
$telegram->editMessageText([
'chat_id' => -*******,
'message_id' => $callback_message_id,
'text' => 'Стадия заказа: '.$callback_data,
'reply_markup' => $keyboard
]);}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question