The idea is to have some buttons to do something, I got the following code, and something is wrong with the method (sendMessage) or callback_data because I received a undefined index error in all the rows where is the $message, if I use a url instead of a call back data works fine
I use a webhook
<?php
$botToken = "TOKEN";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
$response ="testing";
$keyboard = [
'inline_keyboard' => [
[
['text' => 'This is a test', 'callback_data' => 'testcompleted']
]
]
];
$parameters =
array(
'chat_id' => $chatId,
'text' => $response,
'reply_markup' => json_encode($keyboard)
);
send($parameters);
function send($data)
{
$url = "https://api.telegram.org/botTOKEN/sendMessage";
if (!$curld = curl_init()) {
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $data);
curl_setopt($curld, CURLOPT_URL, $url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close($curld);
return $output;
}
?>