Advertisement

Responsive Advertisement

MEMBUAT BOT TELEGRAM WEBHOOK SENDIRI DENGAN PHP

 Persiapan Awal Bot Telegram Webhook

Hal-hal yang harus disiapkan untuk membuat bot telegram dengan metode webhook secara mandiri yaitu:

  • Domain & server yang sudah HTTPS, bisa VPS atau shared hosting. Saya juga masih menggunakan shared hosting.
  • Bot Telegram
  • Pemahaman basic pemrograman PHP
https://api.telegram.org/bot{token}/getUpdates

https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to}

https://api.telegram.org/bot{my_bot_token}/deleteWebhook

https://api.telegram.org/bot{my_bot_token}/getWebhookInfo


$content = json_decode(file_get_contents("php://input"), TRUE);
        $chat_id = $content["message"]["chat"]["id"];
        $message = $content["message"]["text"];
        //$chat_id = '';
        if (strpos($message"/start") === 0) {
            $pesan = "<strong>اَلسَّلَامُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَا تُهُ</strong>\nSelamat Datang Di Bot NFBS Boarding School System\ncontoh\nREG#HRT#10 IPA 1#Achmad Erhanantya, S.Pd.\nREG#WALAS#Umar Bin Khattab 2#Thibul Attfal S.Pd \nTerima Kasih\n<strong>وَعَلَيْكُمُ السَّلاَمُ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ</strong>";
            $data = $this->telegram_lib->sendmsg($pesan$chat_id'HTML');
            echo json_encode($data);
        } elseif (strpos($message"/cek_presensi") === 0) {
            $pesan = '<strong>CHAT ID ' . $chat_id . '</strong><pre></pre>Pesan anda belum ada dalam list Command (Contoh : <strong>/cek_presensi</strong>)';
            $data = $this->telegram_lib->sendmsg($pesan$chat_id'HTML');
            echo json_encode($data);
        } else {
            $pesan = explode('#'$message);
            $kode_pertama =  $pesan[0];
            $kode_kedua =  $pesan[1];
            if (strtoupper($kode_pertama) == "REG") {
                $this->registrasi_telegram($chat_id$pesan);
            }
        }
        die;



 

Post a Comment

0 Comments