Created
July 19, 2019 10:36
-
-
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.
This file contains hidden or 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
| <?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