امیرحسین
9 ماه پیش توسط امیرحسین مطرح شد
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;

ثبت پرسش جدید

به همدیگه کمک کنیم

به امیرحسین کمک کنید تا مشکل خودش را حل کند؛ این‌طور می‌توانیم با هم پیشرفت کنیم.

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام