Membuat Telegram Bot
Untuk membuat bot baru, ikuti langkah berikut:
- Buka alamat Bot Father: https://t.me/botfather
- Ketikkan perintah /newbot
- Namai bot dengan nama alertlogbot atau nama bot Anda (nama harus ada akhiran bot).
- Salin token API untuk akses program lain ke alertlogbot, contoh menggunakan bahasa Python yang akan di bahas dibagian berikutnya.
Perintah-perintah di Bot Father
/newbot – create a new bot
/mybots – edit your bots [beta]
Edit Bots
/setname – change a bot’s name
/setdescription – change bot description
/setabouttext – change bot about info
/setuserpic – change bot profile photo
/setcommands – change the list of commands
/deletebot – delete a bot
Bot Settings
/token – generate authorization token
/revoke – revoke bot access token
/setinline – toggle inline mode
/setinlinegeo – toggle inline location requests
/setinlinefeedback – change inline feedback settings
/setjoingroups – can your bot be added to groups?
/setprivacy – toggle privacy mode in groups
Games
/mygames – edit your games [beta]
/newgame – create a new game
/listgames – get a list of your games
/editgame – edit a game
/deletegame – delete an existing game
Menambah bot ke dalam kontak Telegram
- Install Telegram atau menggunakan versi web: https://web.telegram.org
- Tambahkan Alert Log Bot dengan menambah kontak @alertlogbot atau dengan alamat berikut: https://telegram.me/alertlogbot
Enviroment Bot menggunakan Python
Untuk mencoba @alertlogbot, gunakan environment Python sebagai berikut:
- Install Python 3.7 atau versi terbaru.
- Install library Telegram: pip install python-telegram-bot –upgrade
- Berikut contoh script python untuk berinteraksi dengan bot:
from telegram import Bot token = 'YOUR-TOKEN' bot = Bot(token=token) updates = bot.get_updates() print([u.message.text for u in updates]) chat_id = bot.get_updates()[-1].message.chat_id bot.send_message(chat_id=chat_id, text="I'm sorry Zo, I'm afraid I can't do that.")
- Contoh hasil message dari Telegram:
Cek Error Log Database
Contoh untuk mengambil pesan error dari log database:
- Program Python dapat di-cron untuk memeriksa error log database. Misalnya tiap 10 menit, 1 jam, dsb.
- Tambahkan hasil log error ke AlertLogBot untuk di-broardcast.
- Tambahkan perintah dalam bot untuk keperluan lainnya.
Demikian contoh sederhana yang dapat Anda implementasikan dengan menggunakan bantuan bot dari Telegram.