Skip to content

Instantly share code, notes, and snippets.

@omergulen
Created July 19, 2019 10:36
Show Gist options
  • Select an option

  • Save omergulen/987a09446759e29040846183300be3fa to your computer and use it in GitHub Desktop.

Select an option

Save omergulen/987a09446759e29040846183300be3fa to your computer and use it in GitHub Desktop.
Get post request and it's body with Telegram message on PHP Server.
<?php
$_POST = (array) json_decode(file_get_contents('php://input'));
define('API_KEY','BOT_API_TOKEN');
define('CHAT_ID','YOUR_CHAT_ID');
function make_req($method, $datas=[]) {
$url = "https://api.telegram.org/bot" . API_KEY . "/" . $method;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($datas));
$res = curl_exec($ch);
if (curl_error($ch)) {
var_dump(curl_error($ch));
} else {
return json_decode($res);
}
}
function send_message($msg) {
make_req('sendMessage',[
'chat_id'=>CHAT_ID,
'text'=>$msg,
'parse_mode'=>"HTML"
]);
}
send_message($_POST);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment