EP07: Gateway – คุยกับ Hermes ผ่าน Telegram Discord Slack ได้ [Hermes Agent 101]

Gateway: AI Coworker ที่ไม่ได้อยู่แค่หน้า Terminal

AI Coworker ที่ดีต้องอยู่ที่คุณอยู่ ไม่ใช่แค่อยู่ที่เครื่องคุณ

นั่นคือหัวใจของ Hermes Gateway ระบบที่แปลง Hermes agent จาก CLI tool ใน terminal ให้กลายเป็น AI coworker ที่รับส่งข้อความผ่าน Telegram, Discord, Slack และอีกกว่า 15 platform พร้อม full tool access เต็มรูปแบบ

Gateway คืออะไร และทำงานยังไง

Gateway ใน Hermes คือ background daemon process ที่รันอยู่บน server หรือ VPS ของคุณ ทำหน้าที่เป็นตัวกลางระหว่าง messaging platform กับ Hermes agent loop

โครงสร้างแบบง่าย:

Telegram → Gateway → Hermes Agent → Tools → Response → Telegram
Discord  →         ↗                                 → Discord
Slack    →                                           → Slack

สิ่งที่ทำให้ Gateway ต่างจาก bot relay ธรรมดาคือ ทุก message ที่รับมาจาก platform จะผ่าน full Hermes agent loop ไม่ใช่แค่ echo หรือ rule-based reply แปลว่า:

  • Web search และ content extraction ทำได้จากโทรศัพท์
  • Terminal commands รันได้ผ่าน Telegram
  • File operations, memory, skills ทั้งหมดพร้อมใช้
  • Cron jobs ส่ง notification กลับมาที่ messaging platform คุณ

Platform ที่รองรับ

Hermes Gateway รองรับ 15+ platform โดยแต่ละ platform มี feature ต่างกันนิดหน่อย:

Platform Voice รูปภาพ ไฟล์ Thread Streaming
Telegram
Discord
Slack
WhatsApp : :
Signal : :
Email : :

Plus: SMS, Matrix, Mattermost, DingTalk, Feishu/Lark, WeCom, iMessage (BlueBubbles), QQ, Home Assistant

Setup Gateway: เริ่มต้นยังไง

วิธีที่ง่ายที่สุดคือใช้ interactive wizard:

hermes gateway setup     # ตั้งค่า platform ที่ต้องการ
hermes gateway start     # เริ่ม gateway
hermes gateway status    # ตรวจสถานะ

สำหรับ production (VPS หรือ server) ติดตั้งเป็น system service:

hermes gateway install   # ติดตั้งเป็น launchd (macOS) หรือ systemd (Linux)
hermes gateway start

Telegram: Platform ที่ง่ายและเร็วที่สุด

Telegram เป็น platform ที่ผู้ใช้ส่วนใหญ่เริ่มก่อน เพราะ setup ง่ายมาก:

ขั้นตอน:

  1. เปิด Telegram หา @BotFather แล้วส่ง /newbot
  2. ตั้งชื่อ bot และ username ตามที่ต้องการ
  3. คัดลอก token ที่ได้
# ~/.hermes/.env
TELEGRAM_BOT_TOKEN=7123456789:AAH...
TELEGRAM_ALLOWED_USERS=123456789   # Telegram user ID คุณ (รับจาก @userinfobot)
hermes gateway start

เท่านี้ bot พร้อมรับ message แล้ว รองรับ voice messages (auto-transcribe), รูปภาพ, เอกสาร และ threads

Discord: Full-Featured พร้อม Thread Support

Discord setup ละเอียดขึ้นนิดหน่อยแต่ให้ feature ครบมาก รวมถึง emoji reactions และ voice channel integration:

ขั้นตอน:

  1. ไปที่ Discord Developer Portal สร้าง Application ใหม่
  2. ไปที่ Bot tab → Add Bot → คัดลอก token
  3. สำคัญ: เปิด “Message Content Intent” ใต้ Privileged Gateway Intents
  4. OAuth2 → URL Generator → เลือก scope bot + permissions (Send Messages, Read Message History) → invite bot เข้า server
# ~/.hermes/.env
DISCORD_BOT_TOKEN=MTI...
DISCORD_ALLOWED_USERS=123456789012345678

ถ้าไม่เปิด Message Content Intent bot จะเงียบและไม่ตอบ ซึ่งเป็น pitfall ที่เจอบ่อย

Slack: Workspace Integration ผ่าน Socket Mode

Slack ใช้ Socket Mode ซึ่งไม่ต้องมี public webhook URL:

ขั้นตอน:

  1. ไปที่ api.slack.com/apps → Create New App
  2. เปิด Socket Mode → สร้าง App-Level Token (scope: connections:write)
  3. OAuth & Permissions → Bot Token Scopes: chat:write, im:history, channels:history, im:read, im:write
  4. Event Subscriptions: subscribe to message.im และ message.channels
  5. Install to Workspace → คัดลอก Bot Token
# ~/.hermes/.env
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
SLACK_ALLOWED_USERS=U0123456789

ถ้า bot ตอบใน DM แต่ไม่ตอบใน channel ให้ตรวจว่า subscribe to message.channels แล้วหรือยัง

WhatsApp: ไม่ต้องมี Third-Party API

Hermes ใช้ Baileys library built-in สำหรับ WhatsApp ไม่ต้องซื้อ service หรือใช้ unofficial API:

# ~/.hermes/.env
WHATSAPP_ENABLED=true
WHATSAPP_ALLOWED_USERS=15551234567   # เบอร์โทรใน E.164 format ไม่มี +
hermes whatsapp   # แสดง QR code ให้ scan ด้วยโทรศัพท์

Home Channel: รับ Notification จาก Agent

Feature ที่ทำให้ Gateway มีประโยชน์จริงในชีวิตประจำวันคือ Home Channel

พิมพ์ /sethome ใน chat ใดก็ได้ใน Telegram, Discord, หรือ Slack และ Hermes จะส่ง notification ทุกอย่างมาที่นั่น:

  • Cron job results: “Daily report พร้อมแล้วครับ นี่ summary …”
  • Background task completion: “รัน deploy script เสร็จแล้ว exit code 0”
  • Monitoring alerts: “Server XYZ ตอบ health check ช้าผิดปกติ”

ไม่ต้อง monitor terminal ตลอดเวลา ให้ Hermes report หาคุณเอง

Security: Allowlist และ DM Pairing

Security เป็นเรื่องสำคัญเพราะ bot มี terminal access

Default behavior: ปฏิเสธทุกคนที่ไม่อยู่ใน allowlist

วิธีที่ 1 – Allowlist โดยตรง:

TELEGRAM_ALLOWED_USERS=123456789,987654321
DISCORD_ALLOWED_USERS=123456789012345678

วิธีที่ 2 – DM Pairing (ไม่ต้องรู้ user ID ล่วงหน้า): คนที่ DM bot จะได้รับ pairing code → คุณ approve ผ่านเครื่อง:

hermes pairing approve telegram XKGH5N7P
hermes pairing list    # ดูรายชื่อ
hermes pairing revoke telegram 123456789   # เพิกถอน

Pairing code หมดอายุใน 1 ชั่วโมง rate-limited และใช้ cryptographic randomness

Slash Commands ใน Messaging Platform

Hermes รองรับ slash commands ผ่าน messaging platform ด้วย เช่น:

/new         - เริ่ม session ใหม่
/model       - เปลี่ยน model
/status      - ดูข้อมูล session ปัจจุบัน
/sethome     - ตั้ง home channel
/background  - รัน task ในพื้นหลัง
/stop        - หยุด agent ที่กำลังทำงาน
/voice       - เปิด/ปิด voice mode

Voice Memo Transcription

Telegram, Discord, WhatsApp และ Slack รองรับการส่ง voice message แล้ว Hermes auto-transcribe ก่อนส่งให้ agent ประมวลผล

ไม่ต้องตั้งค่าเพิ่ม ถ้า STT provider พร้อมแล้ว (default: local faster-whisper ไม่ต้อง API key):

# ~/.hermes/config.yaml
stt:
  enabled: true
  provider: local    # local | groq | openai
  local:
    model: base

Background Session ผ่าน Messaging

ส่งข้อความ /background เพื่อให้ Hermes รับงานโดยไม่บล็อก conversation หลัก:

/background ตรวจ health ของ server ทุกตัว แล้วรายงานถ้ามีตัวไหนมีปัญหา

Hermes จะ confirm ทันที และส่งผลกลับมาใน home channel เมื่อเสร็จ ระหว่างนั้นคุณคุยเรื่องอื่นต่อได้เลย

ทำไม Gateway สำคัญสำหรับ AI Coworker จริง

ถ้า Hermes รันอยู่แค่ใน terminal บน laptop คุณ มันทำงานได้เฉพาะตอนที่คุณเปิดเครื่องนั่งอยู่ด้วย

แต่ถ้า Hermes รันบน VPS หรือ sandbox และ Gateway เชื่อมกับ Telegram แล้ว:

  • คุณสั่งงานจากโทรศัพท์ได้ทุกที่
  • Cron job ส่ง report มาตอนเช้าโดยไม่ต้องรอคุณ
  • Background task รันค้างคืน แล้วแจ้งคุณตอนเช้า
  • ทีมสามารถ share bot เดียวกันผ่าน Discord server

AI coworker จริงต้องทำงานได้แม้ตอนที่คุณนอนหลับ Gateway คือส่วนที่ทำให้เป็นไปได้

ตอนต่อไปใน series นี้: Cron/Webhook ให้ AI ทำงานตามเวลาโดยไม่ต้อง prompt ทุกวัน

Hermes Agent 101: จาก Chatbot สู่ AI Coworker ที่ทำงานจริง

OPB Stack tie-in: AI coworker ต้องอยู่ในช่องทางที่เจ้าของธุรกิจใช้จริง

ถ้า ICP คือ founder/operator ทีมเล็ก ช่องทางทำงานจริงมักไม่ใช่ terminal แต่เป็น LINE, Telegram, inbox, Docs, Sheets และ dashboard ต่าง ๆ

Gateway จึงไม่ใช่แค่ “ต่อบอตได้หลาย platform” แต่คือสะพานที่ทำให้ AI coworker อยู่ในชีวิตการทำงานจริง เจ้าของธุรกิจส่งโจทย์จากมือถือ แล้วให้ sandbox ด้านหลังอ่าน context ใช้ tools ทำงาน และส่ง proof กลับมา

OPB Stack ควรใช้ภาษานี้ในการเล่า Gateway: ไม่ใช่เรื่อง bot integration แต่คือการทำให้ AI coworker อยู่กับคุณได้ตลอดวัน

ดู managed path ได้ที่ opbstack.com

Leave a Comment

สอบถามข้อมูล
Scroll to Top