Skip to content

Instantly share code, notes, and snippets.

@m-ostadi
Created June 13, 2021 09:35
Show Gist options
  • Save m-ostadi/4fa95ad57a6cfe8dd3c581142f55a0fd to your computer and use it in GitHub Desktop.
Save m-ostadi/4fa95ad57a6cfe8dd3c581142f55a0fd to your computer and use it in GitHub Desktop.
simple telegram logger in php
/**
* @param $input mixed
*/
function telegramLogger($input){
$bot_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //get from @botfather
$id = 'xxxxxxxxxx'; //reciever telegram id (not username)
ob_start();
var_dump($input);
$message = ob_get_clean();
$method = 'sendMessage';
$parameters = array( 'chat_id' => $id,'text'=>$message);
$url = "https://api.telegram.org/bot$bot_token/$method";
$handle = curl_init($url);
curl_setopt($handle , CURLOPT_HTTPHEADER , array("Content-Type: application/json"));
//curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POSTFIELDS , json_encode($parameters));
curl_exec($handle);
curl_close($handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment