Created
May 28, 2020 11:55
-
-
Save Humayung/0478df74aa4bbd71d43635f1761b8cf8 to your computer and use it in GitHub Desktop.
Send message telegram bot
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
<form method=post> | |
<input type=text name='input_message'> | |
<input type=submit value='send'> | |
</form> | |
<?php | |
if($_POST){ | |
function sendMessage($message){ | |
if($message != ''){ | |
$url = 'https://api.telegram.org/botXXX:ZZZ/sendMessage'; | |
$data = array('chat_id' => 'zzzzzzzzzz', 'text' => $message); | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query($data) | |
) | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
if ($result === FALSE) { /* Handle error */ } | |
} | |
} | |
$message = $_POST['input_message']; | |
sendMessage($message); | |
// var_dump($result); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment