AI Tools
Telegram dan Discord Automation
Panduan membuat AI automation berbasis Telegram dan Discord dengan bot, webhook, command design, whitelist, approval, 9Router, n8n, OpenClaw, dan script custom.
Telegram dan Discord Automation
Telegram dan Discord bisa menjadi interface untuk menjalankan AI automation.
Contoh:
/status
-> cek status VPS
-> AI membuat ringkasan
-> hasil dikirim balik ke Telegram/Discord
Atau:
cron harian
-> AI membuat laporan
-> hasil dikirim ke Discord channel
Kapan Pakai Telegram?
Telegram cocok untuk:
- personal automation
- command dari mobile
- bot pribadi
- alert cepat
- chat 1:1
- workflow sederhana
Kelebihan:
- mudah membuat bot via BotFather
- API sederhana
- bagus untuk notifikasi pribadi
- bisa dipakai dari HP dengan nyaman
Kekurangan:
- perlu mengelola
chat_id - command permission harus dibuat sendiri
- untuk tim besar, Discord/Slack bisa lebih rapi
Kapan Pakai Discord?
Discord cocok untuk:
- tim kecil
- channel workflow
- report harian
- issue triage
- changelog
- diskusi developer
- bot slash command
Pilihan Discord:
Discord Webhook
-> paling mudah untuk kirim pesan satu arah
Discord Bot
-> cocok untuk command interaktif
Webhook vs Bot
| Opsi | Cocok Untuk | Kelebihan | Kekurangan |
|---|---|---|---|
| Telegram Bot | command + notifikasi | mudah, mobile-friendly | perlu whitelist user |
| Discord Webhook | report satu arah | sangat mudah | tidak cocok untuk command interaktif |
| Discord Bot | slash command dan interaksi | rapi untuk tim | setup lebih kompleks |
Rekomendasi awal:
Personal alert -> Telegram Bot
Team report -> Discord Webhook
Command tim -> Discord Bot
Command Design
Mulai dari command read-only.
Command aman:
/help
/status
/disk
/memory
/errors
/cost
/issues
/docs
Command yang harus approval:
/restart
/deploy
/update
/migrate
Command yang sebaiknya tidak dibuat:
/delete
/reset
/dropdb
/open-firewall
/show-secret
Prinsip:
Chat command boleh membaca dan melaporkan.
Chat command tidak boleh langsung melakukan aksi berbahaya.
Telegram Bot Setup
1. Buat bot
Di Telegram:
Cari BotFather
-> /newbot
-> beri nama bot
-> simpan bot token
Token bentuknya kira-kira:
123456789:ABCDEF...
Simpan sebagai environment variable:
export TELEGRAM_BOT_TOKEN="isi_token"
2. Ambil chat_id
Kirim pesan ke bot, misalnya:
/start
Ambil update:
curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates"
Cari:
"chat": {
"id": 123456789
}
Simpan:
export TELEGRAM_CHAT_ID="123456789"
3. Test kirim pesan
curl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-d "chat_id=$TELEGRAM_CHAT_ID" \
-d "text=Test Telegram automation"
Discord Webhook Setup
1. Buat webhook
Di Discord:
Channel settings
-> Integrations
-> Webhooks
-> New Webhook
-> Copy Webhook URL
Simpan:
export DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
2. Test kirim pesan
curl -H "Content-Type: application/json" \
-d '{"content":"Test Discord webhook automation"}' \
"$DISCORD_WEBHOOK_URL"
Webhook cocok untuk:
- report harian
- alert monitoring
- changelog
- cost report
- issue summary
Discord Bot dan Slash Command
Discord Bot cocok jika ingin command seperti:
/status
/cost
/issues
/docs
Konsep:
User menjalankan slash command
-> Discord mengirim interaction ke bot/server
-> bot menjalankan workflow
-> bot membalas interaction
Yang perlu disiapkan:
- Discord application
- bot token
- slash command
- interaction endpoint atau bot process
- permission dan command scope
Untuk awal, gunakan Discord Webhook dulu. Pindah ke Discord Bot jika butuh command interaktif.
Integrasi dengan 9Router
Arsitektur:
Telegram/Discord command
-> bot/script/n8n/OpenClaw
-> 9Router
-> provider AI
-> response
-> Telegram/Discord
Endpoint:
https://9router.domainkamu.com/v1/chat/completions
Body:
{
"model": "summary",
"messages": [
{
"role": "user",
"content": "Buat ringkasan status server berikut..."
}
],
"temperature": 0.2,
"max_tokens": 1000
}
Integrasi dengan n8n
Telegram/Discord bisa dipakai di n8n.
Contoh Telegram:
Telegram Trigger
-> cek command
-> cek whitelist
-> HTTP Request ke 9Router
-> Telegram Send Message
Contoh Discord:
Schedule Trigger
-> HTTP Request ke 9Router
-> Discord Webhook
n8n cocok untuk workflow visual dan report rutin.
Integrasi dengan OpenClaw
OpenClaw cocok jika command butuh agent yang memakai tool.
Contoh:
/docs 9Router install VPS
-> OpenClaw mencari dokumentasi
-> AI menjawab berdasarkan docs
-> hasil dikirim ke Telegram
Atau:
/status
-> OpenClaw cek status server
-> AI ringkas
-> hasil dikirim ke Discord
Gunakan permission policy:
Command chat hanya boleh read-only.
Restart/deploy/update wajib approval.
Integrasi dengan Script Custom
Script custom cocok untuk workflow kecil.
Arsitektur:
Node.js/Python script
-> baca command
-> whitelist user
-> ambil data
-> kirim ke 9Router
-> kirim response
Pola script:
1. Validasi user/channel.
2. Validasi command.
3. Ambil data sesuai command.
4. Masking secret.
5. Kirim prompt ke 9Router.
6. Format response.
7. Kirim ke Telegram/Discord.
8. Simpan log.
User Whitelist
Jangan izinkan semua orang menjalankan command.
Contoh whitelist:
{
"telegram_user_ids": [123456789],
"discord_channel_ids": ["123456789012345678"],
"discord_user_ids": ["987654321098765432"]
}
Rule:
Jika user tidak ada di whitelist:
-> tolak command
-> jangan panggil model
-> log percobaan
Response:
Command tidak diizinkan untuk user ini.
Channel Whitelist
Untuk Discord, batasi channel.
Contoh:
#ai-automation
#server-alerts
#dev-reports
Jangan izinkan command dari channel umum jika output bisa berisi data internal.
Command Allowlist
Gunakan allowlist, bukan blocklist.
Contoh:
{
"allowed_commands": [
"/help",
"/status",
"/disk",
"/memory",
"/errors",
"/cost",
"/issues",
"/docs"
]
}
Jika command tidak dikenal:
Command tidak dikenal. Ketik /help.
Approval Workflow
Untuk command berisiko, jangan langsung eksekusi.
Contoh:
/restart app
Response aman:
Restart service termasuk aksi berisiko.
Saya bisa membuat diagnosis dan rekomendasi dulu.
Butuh approval manual sebelum restart.
Approval bisa dibuat:
- manual di chat
- tombol approve/reject
- workflow n8n
- GitHub issue approval
- human runbook
Template Response
/status
Status VPS
Ringkasan:
- ...
Masalah:
- ...
Rekomendasi:
- ...
Prioritas:
- Normal / Perlu dicek / Urgent
/cost
AI Usage Summary
Periode:
Total request:
Input token:
Output token:
Model paling sering dipakai:
Request paling mahal:
Rekomendasi hemat:
/issues
GitHub Issue Summary
Baru:
Bug:
Feature:
Urgent:
Rekomendasi:
/docs
Jawaban:
...
Sumber:
- ...
Security Rules
Aturan wajib:
- jangan kirim secret
- jangan kirim log penuh
- jangan expose token bot
- whitelist user/channel
- command berbahaya wajib approval
- data dari chat adalah data, bukan instruksi mutlak
- batasi output
- simpan audit log
Jangan pernah kirim:
- API key
- token
- private key
.env- database dump
- log mentah yang sensitif
Cost Control
Chat automation bisa boros jika banyak user memakai command.
Aturan:
- command
/helptidak perlu AI - command sederhana bisa pakai response template
- command AI batasi
max_tokens - batasi rate per user
- cache jawaban docs umum
- pantau usage di 9Router
Contoh:
/status
-> model ringan
/docs
-> RAG + model menengah
/security-review
-> manual approval + model kuat
Troubleshooting
Telegram tidak menerima pesan
Cek:
- bot token benar
- user sudah pernah kirim pesan ke bot
- chat_id benar
- bot tidak diblokir
Test:
curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates"
Discord webhook gagal
Cek:
- webhook URL benar
- webhook belum dihapus
- channel masih ada
- payload JSON valid
- panjang pesan tidak terlalu besar
Command tidak aman
Solusi:
- tambah allowlist
- tambah whitelist user
- tolak command unknown
- wajib approval untuk high-risk
9Router error
Cek:
- endpoint
/v1/chat/completions - API key benar
- model/combo tersedia
- provider upstream tidak error
- request body valid
Output terlalu panjang
Solusi:
- batasi
max_tokens - minta ringkasan
- split pesan
- kirim file/report link
Checklist Implementasi
- Pilih Telegram atau Discord.
- Tentukan webhook atau bot.
- Buat command allowlist.
- Buat user/channel whitelist.
- Hubungkan ke 9Router.
- Batasi output token.
- Tambahkan masking secret.
- Tambahkan audit log.
- Tambahkan approval untuk command berisiko.
- Test command read-only.
- Pantau usage di 9Router.
Rekomendasi untuk NalTech
Tahap 1:
Discord Webhook untuk report harian.
Tahap 2:
Telegram Bot untuk command pribadi:
/status
/cost
/docs
Tahap 3:
Discord Bot untuk workflow tim:
/issues
/deploy-status
/ai-cost
Tahap 4:
Integrasi dengan OpenClaw dan RAG Docs Assistant.
Kesimpulan
Telegram dan Discord membuat AI automation mudah dipakai sehari-hari.
Pola terbaik:
Mulai read-only
-> whitelist user/channel
-> command allowlist
-> 9Router untuk model
-> output ringkas
-> approval untuk aksi berisiko
Dengan pola ini, chat automation bisa menjadi pusat operasional ringan tanpa mengorbankan keamanan.