forked from Jevenus/bot-telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.io
48 lines (41 loc) · 1.39 KB
/
hook.io
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$tokenbot = $Hook['env']['tokenbot'];
$endpoint = "https://api.telegram.org/bot$tokenbot/";
$messages = $Hook["params"];
if (isset($messages['message'])) {
$messages = $messages['message'];
} else {
echo 'URL hook.io: https://'.$Hook['input']['host'].$Hook['input']['path'];
}
// ngucapin selamat datang member baru
if (isset($messages['new_chat_member'])) {
$pesan = "Hai ".$messages['new_chat_member']['first_name']."!\n";
$pesan.= "Selamat datang di Grup ".$messages['chat']['title'];
kirimPesan($messages['chat']['id'], $pesan);
}
// ngucapin selamat tinggal buat user yang pergi
// HANYA jika telegram mengirimkan signal left member
if (isset($messages['left_chat_member'])) {
$pesan = "Sampai jumpa lagi ".$messages['left_chat_member']['first_name'] ;
kirimPesan($messages['chat']['id'], $pesan);
}
// fungsi Kirim Pesan
function kirimPesan($chat_id, $text)
{
global $endpoint;
$data = array(
'chat_id' => $chat_id,
'text' => $text
);
// Buat parameter pengiriman
$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($endpoint.'sendMessage', false, $context);
return $result;
}
//code by bang Hasan