Bots 电报机器人PHP键盘不';t工作

Bots 电报机器人PHP键盘不';t工作,bots,telegram,telegram-bot,Bots,Telegram,Telegram Bot,我在为我的电报机器人创建自定义键盘时遇到问题 简单地说,它不起作用,我不知道原因 这是我的代码: <? $botToken = "*****"; $website = "https://api.telegram.org/bot".$botToken; $update = file_get_contents('php://input'); $update = json_decode($update, TRUE); $chatId = $update["message"]["chat"][

我在为我的电报机器人创建自定义键盘时遇到问题

简单地说,它不起作用,我不知道原因

这是我的代码:

<?
$botToken = "*****";
$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"];
$telegramusername = $update["message"]["from"]["username"];
$message_id = $update["message"]["message_id"];
$message_name = $update["message"]["chat"]["first_name"];


switch($message)
{
case "ciao":
funzioneCiao($chatId);
break;
case "youtube":
TastieraInline($chatId);
break;
default:
TastieraMenuPrincipale($chatId);
break;
}

function inviaMessaggio($chatId, $messaggio)
{
    $url = "$GLOBALS[website]/sendMessage?chat_id=$chatId&parse_mode=HTML&text=".urlencode($messaggio);
    file_get_contents($url);
}

function funzioneCiao($chatId)
{
    $messaggio = "ciao";
inviaMessaggio($chatId, $messaggio);
}



function TastieraMenuPrincipale($chatId)
{
    $messaggio = "ciaaaao";
    $tastiera = '&reply_markup={"keyboard":[["Menu Principale"],["Developer"]]}';
    $url = "$GLOBALS[website]"."/sendMessage?chat_id=".$chatId."&parse_mode=HTML&text=".$messaggio.$tastiera;
    file_get_contents($url);

}

function TastieraInline($chatId)
{
    $message = "Iscriviti subito";
    $tastiera = '&reply_markup={"inline_keyboard":[[{"text":"SEGUIMI!","url":"http://www.youtube.com"}]]}';
    $url = $GLOBALS[website].'/sendMessage?chat_id='.$chatId.'&parse_mod=HTML&text='.$message.$tastiera;
    file_get_contents($url);
}
?>

功能:“funzioneCiao($chatId);”和“inviaMessaggio($chatId,$messaggio)”起作用,但是, “TastieraMenuPrincipale($chatId)”和“TastieraInLine($chatId)”不起作用

我是PHP的初学者,所以我有很多困难


谢谢。

我刚刚测试了代码,它工作得非常好


为什么不使用CURL而不是
file\u get\u contents()

只需将此函数写入代码,然后在获得新更新后调用它:

function makeHTTPRequest($method, $types = []){
    $url = 'https://api.telegram.org/bot'.$botToken.'/'.$method;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($types));
    $res = curl_exec($ch);
    if (curl_error($ch)){
        var_dump(curl_error($ch));
    } else {
        return json_decode($res);
    }
} 

确保在托管服务器上激活了CURL

你射击显示你的机器人令牌。它可能被滥用。你可以用任意随机字母来代替它。这是一个例子,它不是我真正的机器人;)嗯,我又试了一次,但它对我不起作用。。。。我正在使用一个免费的托管网站来使用我的机器人,但不起作用。。。你能帮我吗?我使用url()进行了测试,效果很好。因此,可能的问题有两个:“和”给出问题或我的免费网络主机无法做到这一点这是完整的代码…现在唯一不起作用的是API密钥,因为我删除了机器人…你能在pvt中与我联系吗?alessandrosiveri@gmail.comThen您应该使用@BotFather创建另一个bot,然后再次测试代码