2

我是 Kevin,这些天我遇到了函数editMessageText和 editReplyMarkup 的问题。这是我的代码,我不知道问题出在哪里。

这是我的代码:

<?php

$botToken = "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$website = "https://api.telegram.org/bot".$botToken;

$FilejSon = file_get_contents("php://input"); 
$FilejSon = json_decode($FilejSon, TRUE); 

$FirstName = $FilejSon["message"]["chat"]["first_name"];
$UserChatId = $FilejSon["message"]["chat"]["id"];
$Message = $FilejSon["message"]["text"];
$MessageID = $FilejSon["message"]["message_id"];

$CallBackID = $FilejSon["callback_query"]["from"]["id"];
$CallBackData = $FilejSon["callback_query"]["data"];
$what = ["callback_query"]["message"]["inline_message_id"];


$document = "http://media.giphy.com/media/109Ku3hdapZJle/giphy.gif"; //It's just a funny image

                //Emoji
    $phone = json_decode('"\uD83D\uDCF2"');
    $list = json_decode('"\uD83D\uDCCB"');
    $money = json_decode('"\uD83D\uDCB0"');
    $postbox = json_decode('"\uD83D\uDCEE"');
    $sos = json_decode('"\uD83C\uDD98"');
    $link = json_decode('"\uD83D\uDD17"');

    $jSonCodeKeyboard = '&reply_markup={"inline_keyboard":[[{"text":"1","url":"https://core.telegram.org/bots/api"}],[{"text":"2","url":"https://www.google.it"}],[{"text":"4","switch_inline_query_current_chat":"try"}],[{"text":"5","url":"https://www.google.it"},{"text":"'.$link.'%20Link%20'.$link.'","url":"http://botkevin.altervista.org/Bot/Nuovo_documento_di_testo.txt"}],[{"text":"6","callback_data":"Press"}]]}';
    $jSonCodeKeyboard1 = '&reply_markup={"inline_keyboard":[[{"text":"Indietro","callback_data":"Ok"}]]}';

switch ($Message){
    case '/start':
        $msg = "Hello $GLOBALS[FirstName] $GLOBALS[MessageID] $GLOBALS[UserChatId] $GLOBALS[what].\n";
        sendMessage($UserChatId, $msg, $jSonCodeKeyboard);
        break;

    case '/prova':
        sendFile($UserChatId, $document);
        break;

    case '/prova1':
        $msg = "worked $GLOBALS[MessageID]";
        sendMessage($UserChatId, $msg, $jSonCodeKeyboard1);    
        break;

    default:
        if (callback($FilejSon)){
            if ($CallBackData == "Press"){
                sendMessage($CallBackID, "gg", $jSonCodeKeyboard1);
            }
            else if($CallBackData == "Ok")
            {
                $msg = "Edited";
                Edit($CallBackID, $MessageID, $msg);
                Edit1($CallBackID, $MessageID, $jSonCodeKeyboard1);
            }
        }

        $msg = "Unrecognized command.";
        sendMessage($UserChatId, $msg);
        break;
} 

function sendMessage($chat_id, $text, $LayoutKey){
    if($LayoutKey==""){
    $url = $GLOBALS[website]."/sendMessage?chat_id=".$chat_id."&text=".urlencode($text);
    file_get_contents($url);
    }
    else{
    $url = $GLOBALS[website]."/sendMessage?chat_id=".$chat_id."&text=".urlencode($text).$LayoutKey;
    file_get_contents($url);
    }
}

function sendFile($chat_id, $file){
    $url = $GLOBALS[website]."/sendDocument?chat_id=".$chat_id."&document=".$file;  //Gif,Pdf e Zip
    file_get_contents($url);
}

function Edit($chat_id, $msgID, $text){
    $url = $GLOBALS[website]."/editMessageText?chat_id=".$chat_id."&message_id=".$msgID."&text=".urlencode($text);
    file_get_contents($url);
}

function Edit1($chat_id, $msgID, $LayoutKey){
    $url = $GLOBALS[website]."/editMessageReplyMarkup?chat_id=".$chat_id."&message_id=".$msgID.$jSonCodeKeyboard1;
    file_get_contents($url);
}

function callback($getUpdate){
    return $getUpdate["callback_query"];
}?>

我到处搜索解决方案,但要么使用另一种编程语言,要么使用库等等,我不太擅长 php,所以我想要一个基本的东西,比如我的代码。

当我通过执行“/ start”单击发送机器人的第一条消息的内联键盘时,我想这样做,单击一个按钮可以修改消息和内联键盘,而不会发送其他消息阻塞聊天。

(已经检查过 https://core.telegram.org/bots/api

4

0 回答 0