2017-03-02 2 views
0

전보 봇용 사용자 정의 키보드를 만드는 데 문제가 있습니다. "funzioneCiao ($ chatId);":전보 봇 PHP 키보드가 작동하지 않습니다.

<? 
$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); 
} 
?> 

기능 :

간단하게, 그렇지 않은 작품 않습니다 나는 이유를 모르겠어요 ...

내 코드입니다 및 "inviaMessaggio ($ chatId, $ messaggio)"작동하지만 "TastieraMenuPrincipale ($ chatId)"및 "TastieraInLine ($ ChatId)"작동하지 않습니다.

나는 PHP에서 초보자가 그래서 어려운 많은 ...

가 감사를 해요.

+0

당신은 봇 토큰을 표시합니다. 오용 될 수 있습니다. 그 대신 임의의 문자를 사용할 수 있습니다. – ManzoorWani

+0

예를 들어 내 실제 Bot가 아닙니다. –

답변

0

난 그냥 ... 그것은 완벽하게 작동,

enter image description here

+0

음, 다시 시도했지만 저와는 작동하지 않습니다 ... 무료 봇넷을 사용하여 웹을 사용하고 있지만 작동하지 않습니다. 너 나 좀 도와 줄 수있어? –

+0

URL (https : //api.telegram ......)을 사용하여 테스트했으며 작동합니다. 따라서 가능한 문제는 두 가지입니다. "및 '문제가 발생하거나 내 freewebhosting이 수행 할 수 없습니다. –

+0

전체 코드를 게시 할 수 있습니까? – ManzoorWani

0

왜 대신 file_get_contents();의 CURL을 사용하지 않은이 코드를 테스트?!

다만 다음 새 업데이트를받은 후 호출 코드에이 기능을 쓰기 :

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가 활성화되어 있는지 확인하십시오!