Telegram Bot 노드 — 메신저 자동화

Telegram Bot 노드 — 메신저 자동화

Telegram Bot은 무료이고, API가 강력하며, 개인 알림부터 팀 자동화까지 폭넓게 쓸 수 있다. n8n과의 궁합도 최고다.

Telegram Bot 생성

BotFather로 봇 만들기

  1. Telegram에서 @BotFather 검색 → 대화 시작
  2. /newbot 명령어 전송
  3. 봇 이름 입력: "My n8n Bot"
  4. 봇 username 입력: my_n8n_automation_bot
  5. Bot Token 복사 (123456789:ABCdefGHIjklMNOpqrsTUVwxyz)

n8n Credential 등록

n8n → Credentials → Add → "Telegram API" → Access Token 입력


Telegram Trigger — 메시지 수신

[Telegram Trigger] → [Switch: 명령어 분기] → [Telegram: 응답]
설정 설명
Updates message, callback_query, edited_message 등
수신 데이터 chat.id, text, from.username 등

메시지 데이터 구조

{
  "message": {
    "message_id": 42,
    "from": { "id": 123456, "username": "myuser" },
    "chat": { "id": 123456, "type": "private" },
    "text": "/status api-server-01"
  }
}

명령어 기반 챗봇

Switch로 명령어 라우팅

[Telegram Trigger] → [Switch: message.text]
  /start   → "안녕하세요! 사용 가능한 명령어: /status, /report"
  /status  → [HTTP: 서버 헬스체크] → [Telegram: 결과 전송]
  /report  → [DB 조회] → [Telegram: 보고서 전송]
  default  → "알 수 없는 명령어입니다."

응답 전송

Resource: Message
Operation: Send
Chat ID: {{ $json.message.chat.id }}
Text: {{ $json.responseText }}
Parse Mode: MarkdownV2  (서식 적용)

Markdown 서식 예시:

*굵은 글씨*
_기울임_
`코드`
[링크](https://example.com)

인라인 키보드 (버튼)

{
  "inline_keyboard": [
    [
      { "text": "✅ 승인", "callback_data": "approve_123" },
      { "text": "❌ 거절", "callback_data": "reject_123" }
    ],
    [
      { "text": "📊 상세 보기", "url": "https://dashboard.example.com" }
    ]
  ]
}

콜백 처리:

[Telegram Trigger: callback_query] → [IF: data = "approve_*"] → [승인 처리]

실전: 서버 상태 조회 봇

사용자: /status api-01
봇:     🟢 api-01: 정상
        응답시간: 142ms
        CPU: 45%
        메모리: 68%
[Telegram Trigger]
  → [Code: 명령어 파싱]
  → [HTTP: 서버 헬스체크 API]
  → [Edit Fields: 메시지 구성]
  → [Telegram: 결과 전송]

📝 정리

  • [x] BotFather: /newbot으로 봇 생성 → Token 발급
  • [x] Telegram Trigger: 메시지, 콜백 쿼리 수신
  • [x] 메시지 전송: 텍스트(Markdown), 이미지, 문서, 인라인 키보드
  • [x] 콜백 처리: 인라인 버튼 클릭 → callback_data로 분기
  • [x] 실전: 명령어 기반 서버 상태 조회 챗봇

다음 편 예고

17편: PostgreSQL / MySQL 노드 — 데이터베이스 자동화

n8n에서 직접 DB를 조회하고, 입력하고, 업데이트하자. PostgreSQL과 MySQL 노드의 모든 것.