Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
hookio.php
$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;
}
@banghasan

This comment has been minimized.

Show comment Hide comment
@banghasan

banghasan Apr 25, 2017

Tutorial bisa dilihat di https://goo.gl/hrN9IK

Owner

banghasan commented Apr 25, 2017

Tutorial bisa dilihat di https://goo.gl/hrN9IK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment