【发布时间】:2019-08-03 10:51:49
【问题描述】:
这个想法是有一些按钮来做某事,我得到了以下代码,方法 (sendMessage) 或 callback_data 有问题,因为我在 $message 所在的所有行中都收到未定义的索引错误,如果我使用 url 而不是回调数据工作正常
我使用网络钩子
<?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;
}
?>
【问题讨论】:
-
你能显示你得到的完整错误吗?
-
$message 所在的所有行中的未定义索引错误
标签: php button bots telegram php-telegram-bot