امیرحسین
3 سال پیش توسط امیرحسین مطرح شد
0 پاسخ

مشکل اجرای ربات تلگرام با کد php

سلام
من یه کد php رو برای ربات تلگرامم روی سرور با ست وب هوک اجرا کردم اینو نمایش داد:

{"ok":true,"result":true  

ولی توی ربات وقتی استارت میزنم هیچ اتفاقی نمیفته
کد رباتم هم اینه:

<?php

// Set your bot token here  
$botToken = ':--UM9h8';

// Get updates from Telegram API  
$update = filegetcontents('php://input');  
$update = jsondecode($update, true);

// Get user information  
$chatId = $update\['message'\]\['chat'\]\['id'\];  
$userId = $update\['message'\]\['from'\]\['id'\];  
$username = $update\['message'\]\['from'\]\['username'\];

// Send a message with the username and user ID  
$response = "Username: @$username\\nUser ID: $userId";

// Prepare the API request  
$apiUrl = "<https://api.telegram.org/bot$botToken/sendMessage>";  
$data = \[  
'chatid' =&gt; $chatId,  
'text' =&gt; $response,  
\];

// Send the message via Telegram API  
$options = \[  
'http' =&gt; \[  
'method' =&gt; 'POST',  
'header' =&gt; 'Content-Type: application/x-www-form-urlencoded',  
'content' =&gt; httpbuildquery($data),  
\],  
\];  
$context = streamcontextcreate($options);  
$result = filegetcontents($apiUrl, false, $context);

// Check if the message was sent successfully  
if ($result === false) {  
// Handle the error  
echo "Failed to send message.";  
} else {  
// Message sent successfully  
echo "Message sent.";  
}  
?&gt;