Created
June 13, 2021 09:35
-
-
Save m-ostadi/4fa95ad57a6cfe8dd3c581142f55a0fd to your computer and use it in GitHub Desktop.
simple telegram logger in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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