PHP Lesson: Telegram Bot

Menghantar mesej Telegram melalui php memerlukan Telegram Bot Token dan Telegram Chat ID. Cara mendaftarkan Telegram Bot boleh rujuk di ESP32 Telegram Bot. Contoh code php bagi menghantar mesej Telegram seperti di bawah.

<title>Send Telegram</title>
   <form action="" method="post">
   Bot Token: <input type="password" name="apiToken" value="Your BotToken Here" required>
   Chat ID: <input type="password" name="id" value="Your ChatID Here" required>
   Message: <input type="text" name="message" required>
   <input type="submit" name="submit">

         $time_start = microtime(true);
         $data = [
            'chat_id' => $id,
            'text' => $message
         $response = file_get_contents("".$apiToken."/sendMessage?".http_build_query($data));
         $time_end = microtime(true);
         $duration = $time_end - $time_start;
         echo "Executed in ".$duration."s";

Berikut adalah video demo menghantar mesej Telegram.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.