Telegram basit bir bot denemesi yapmak istedim. Ama bu hatayı alıyorum nasıl yapacagımıda bılmıyorum acemiyim yardımcı olabilecek arkadaş varsa hayra girer valla. Teşekkürler şimdiden
// 20211019125118
// https://api.telegram.org/bot2091886316 :AAFo78BUnVvdGNEUOBZUROCs98p_AANMUD8/getWebhookInfo
{
"ok": true,
"result": {
"url": "https://ozelguzelgunler.com/telegram/",
"has_custom_certificate": false,
"pending_update_count": 7,
"last_error_date": 1634637032,
"last_error_message": "Wrong response from the webhook: 500 Internal Server Error",
"max_connections": 40,
"ip_address": "159.253.45.183"
}
}
Buda php kodum
class TelegramBot {
const API_URL = 'https://api.telegram.org/bot';
public $token;
public $chatId;
public function setToken($token)
{
$this->token = $token;
}
public function getData()
{
$data = json_decode(file_get_contents('php://input'));
$this->chatId = $data->message->chat->id;
return $data->message;
}
public function setWebhook($url)
{
return $this->request('setWebhook', [
'url' => $url
]);
}
public function sendMessage($message){
return $this->request('sendMessage', [
'chat_id' => $this->chatId,
'text' => $message
]);
}
public function request($method, $posts)
{
$ch = curl_init();
$url = self::API_URL . $this->token . '/' . $method;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($posts));
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
}
$telegram = new TelegramBot();
$telegram->setToken('2091886316:AAFo78BUnVvdGNEUOBZUROCs98p_AANMUD8');
//echo $telegram->setWebhook('https://ozelguzelgunler.com/telegram/');
$data = $telegram->getData();
if ($data->text == 'hello'){
$telegram->senMessage('sanada hello');
}
?>