Closed behnamazimi closed 7 years ago
dear @behnamazimi If you find some point about this problem please notice me here.
$update = $telegram->getWebhookUpdates();
// check if update contains callback_query
if ( isset($update['callback_query']) ){
// extract what is required
$chat_id = $callback_query['message']['chat']['id'];// to be used for sendMessage
$user_id = $callback_query['from']['id'];
$callbackdata = $callback_query['data'];
$message_id = $callback_query['message']['message_id'];
$text = $callback_query['message']['text'];
// then send the message you want
$res = $telegram->sendMessage([
'chat_id' => $chat_id,
'text' => 'Your message'
]);
}
I guess you are using commandsHandler. Well, I manage with the next, i put commands on callback_data of inline keyboard :joy:
$commands = [ /**/ ];
$update = Telegram::commandsHandler(true);
if ($update->isType('callback_query')) {
$query = $update->getCallbackQuery();
$data = $query->getData();
$start = strpos($data, ' ');
$command = ($start !== false) ? substr($data, 1, $start - 1) : substr($data, 1);
if (in_array($command, $commands)) {
$update->put('message', collect([
'text' => substr($data, $start + 1),
'from' => $query->getMessage()->getFrom(),
'chat' => $query->getMessage()->getChat()
]));
Telegram::triggerCommand($command, $update);
}
}
I am using V3 :stuck_out_tongue_closed_eyes: Maybe helps you
Here's a solution if using V3.x dev with laravel-starter.
Thanks to all the others for posting their solutions BTW. Highly appreciate helping each other here :)
I wanna send a message when a inline button attached, but I don't know How to catch
CallbackQuery
object via Webhook. Maybe a simple example be enough!