2016-01-17 72 views
2

我已经开始用webhooks创建一个机器人电报。 我的第一个问题:我必须把网站的网址与HTTPS?我的网站不是HTTPS,而只是HTTP。电报只需要HTTPS?Webhook电报机器人php不运行

第二个问题:当我启用webhook时,我把这个:“php:// input”。

php ini_set('error_reporting', E_ALL); 

$botToken ="*********************"; 

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

$update=file_get_contents("php://input");//before: $website."/getupdates" 

$updateArray=json_decode($update, TRUE); 

$chatID=$updateArray["message"]["chat"]["id"]; $message=$updateArray["message"]["text"]; 

switch($message) { case "/saluto":   sendMessage($chatID, "Ciao, sono il bot di Vincenzo e Francesco");   >break;  case "/comiato":  sendMessage($chatID, "Ciao è stato bello parlare con te");  break;  case default:  sendMessage($chatID, "Non ho capito!");   break; } 

function sendMessage($chatID, $message) {  $url=GLOBALS[$website]./"sendMessagechat_id=".$chatID."&text=".urlencode($messag>e); file_get_contents($url); } 

?> 

回答

1
  1. 是的,电报目前仅支持HTTPS。

    您需要一个有效的SSL证书才能使webhook工作。
    https://core.telegram.org/bots/faq#i-39m-having-problems-with-webhooks

  2. 你可以抓住你收到$HTTP_RAW_POST_DATA

    $data = json_decode($HTTP_RAW_POST_DATA, true); 
    $message = $data["message"];   // Message-Array 
    $chatID = $message["chat"]["id"];  // Chat ID 
    $message_text = $message["text"];  // Message Text 
    
数据