forked from LorenzCK/heroku-test-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.php
34 lines (27 loc) · 920 Bytes
/
hook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$content = file_get_contents("php://input");
$token = getenv('BOTTOKEN');
echo $token;
if($content) {
$update = json_decode($content, true);
if(isset($update['message'])) {
$message = $update['message'];
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
$from_id = $message['from']['id'];
$text = $message['text'];
$parameters = array(
'chat_id' => $chat_id,
'text' => "You wrote '{$text}'"
);
$url = "https://api.telegram.org/bot{$token}/sendMessage";
$query_string = http_build_query($parameters);
if(!empty($query_string)) {
$url .= '?' . $query_string;
}
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POST, true);
$response = curl_exec($handle);
}
}