Lewati ke konten

Telegram

Provider Telegram memungkinkan digital worker Anda berkomunikasi melalui bot Telegram. Provider ini mendukung:

  • Pesan teks
  • Inline keyboard (tombol)
  • Reply keyboard
  • Lampiran file
  • Media (foto, video, dokumen)
  • Chat grup
  • Akun Telegram
  • Bot Telegram (dibuat melalui @BotFather)
  1. Buat bot Telegram

    Buka Telegram dan kirim pesan ke @BotFather:

    /newbot

    Ikuti petunjuknya:

    • Masukkan nama untuk bot Anda (misalnya, “My Support Bot”)
    • Masukkan username (harus diakhiri dengan bot, misalnya, “my_support_bot”)

    BotFather akan memberikan bot token seperti:

    123456789:ABCdefGHIjklMNOpqrsTUVwxyz
  2. Konfigurasikan provider

    Buat atau perbarui file jawaban Anda:

    answers.json
    {
    "messaging-telegram": {
    "enabled": true,
    "public_base_url": "https://your-domain.ngrok-free.app",
    "bot_token": "123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
    }
    }
  3. Jalankan setup

    Terminal window
    gtc setup --answers answers.json ./my-bundle
  4. Mulai runtime

    Terminal window
    gtc start ./my-bundle
  5. Uji bot Anda

    Buka Telegram, cari bot Anda berdasarkan username, lalu kirim pesan!

OpsiWajibDeskripsi
enabledYaAktifkan/nonaktifkan provider
public_base_urlYaURL publik untuk webhook
bot_tokenYaBot token dari @BotFather
api_base_urlTidakURL API Telegram (default: https://api.telegram.org)
- id: reply
type: reply
config:
message: "Hello! How can I help you today?"

Telegram mendukung MarkdownV2:

- id: formatted_reply
type: reply
config:
message: |
*Bold* _Italic_ `Code`
[Link](https://example.com)
parse_mode: MarkdownV2
- id: ask_action
type: reply
config:
message: "What would you like to do?"
buttons:
- row:
- label: "Get Help"
callback_data: "action:help"
- label: "Settings"
callback_data: "action:settings"
- row:
- label: "Contact Support"
url: "https://support.example.com"
- id: ask_choice
type: reply
config:
message: "Choose an option:"
reply_keyboard:
- ["Option A", "Option B"]
- ["Option C", "Cancel"]
resize_keyboard: true
one_time_keyboard: true
- id: send_image
type: reply
config:
photo:
url: "https://example.com/image.jpg"
caption: "Here's your image!"
- id: send_file
type: reply
config:
document:
url: "https://example.com/report.pdf"
filename: "report.pdf"
caption: "Your monthly report"
- id: reply_to_message
type: reply
config:
message: "This is a reply to your previous message"
reply_to_message_id: "{{original_message_id}}"

Saat pengguna mengklik tombol inline keyboard, Anda menerima callback:

flows/on_callback.ygtc
name: handle_callback
version: "1.0"
nodes:
- id: check_action
type: branch
config:
conditions:
- expression: "callback_data == 'action:help'"
next: show_help
- expression: "callback_data == 'action:settings'"
next: show_settings
default: unknown_action
- id: show_help
type: reply
config:
message: "Here's how I can help..."
- id: show_settings
type: reply
config:
message: "Settings menu..."
- id: unknown_action
type: reply
config:
message: "Unknown action"
triggers:
- type: callback_query
target: check_action

Provider Telegram mendukung chat grup:

greentic.demo.yaml
tenants:
demo:
teams:
support:
channels:
telegram-group:
provider: messaging-telegram
config:
chat_id: "-1001234567890" # Group chat ID
  1. Tambahkan bot Anda ke grup
  2. Kirim pesan di grup
  3. Periksa payload webhook untuk chat.id

Atau gunakan API Telegram:

Terminal window
curl "https://api.telegram.org/bot<TOKEN>/getUpdates"

Alur setup secara otomatis mengonfigurasi webhook:

POST https://api.telegram.org/bot<TOKEN>/setWebhook
{
"url": "https://your-domain.com/webhook/telegram/{tenant}/{team}",
"allowed_updates": ["message", "callback_query"]
}

Jika diperlukan, konfigurasikan secara manual:

Terminal window
curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-domain.com/webhook/telegram/demo/default",
"allowed_updates": ["message", "callback_query"]
}'
  1. Periksa status webhook:

    Terminal window
    curl "https://api.telegram.org/bot<TOKEN>/getWebhookInfo"
  2. Verifikasi URL publik dapat diakses:

    Terminal window
    curl https://your-domain.ngrok-free.app/health
  3. Periksa log:

    Terminal window
    gtc start ./my-bundle --verbose
Error: 401 Unauthorized

Verifikasi bot token Anda benar dan belum kedaluwarsa.

  1. Pastikan bot sudah dimulai (pengguna mengirim /start)
  2. Periksa apakah bot ada di grup (untuk chat grup)
  3. Verifikasi URL webhook sesuai dengan URL publik Anda

Telegram memiliki batas rate:

  • 1 pesan per detik per chat
  • 30 pesan per detik secara keseluruhan

Tangani rate limit dengan baik:

- id: reply
type: reply
config:
message: "Response"
retry_on_429: true
max_retries: 3

Telegram mengirim secret token bersama request webhook. Greentic memvalidasi ini secara otomatis.

Selalu validasi input pengguna:

- id: validate
type: script
config:
script: |
if message.len() > 4096 {
return error("Message too long")
}
message