Reputation: 61
I've started to create a bot telegram with webhooks. My first question: I must put a url of web site with HTTPS? My site isn't a HTTPS but HTTP only. Telegram required only HTTPS?
Second question: When I enable a webhook I put this: "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); }
?>
Upvotes: 2
Views: 913
Reputation: 5038
Yes, Telegram currently only supports HTTPS.
You need a valid SSL certificate for webhooks to work.
https://core.telegram.org/bots/faq#i-39m-having-problems-with-webhooks
You can grab the data you receive with $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
Upvotes: 1