الأكاديمية ← قنوات المراسلةتوثيق رسمي · إرشاد عربي

قناة LINE

LINE

متوسط إلى متقدم7 دقائق قراءةالدرس 244 أسئلة✓ 2026-08-18
قبل أن تقرأ

ما هذه الصفحة، وماذا تحتوي.

بوابة المراسلة: الوصلة التي تجعلك تكلّم Hermes من تطبيق تستعمله أصلًا، مثل Telegram أو WhatsApp، بدل الطرفية. الوكيل الذي تصله من هاتفك تستعمله فعلًا. الذي يحتاج فتح الحاسوب تنساه بعد أسبوع. ستستعمل هنا hermes gateway وhermes gateway setup، والقراءة نحو 7 دقائق. انتبه: افتح القناة لنفسك فقط في البداية عبر قائمة سماح. القناة المفتوحة تعني أن أي شخص يراسل وكيلك.

11أقسام
8أمثلة برمجية
2جداول
2أوامر
1,124كلمة من المصدر
الوصف الرسمي في سطر

Set up Hermes Agent as a LINE Messaging API bot

ماذا ستستطيع بعدها

نتائج مأخوذة من هذه الصفحة، لا من قالب.

  • تعرف ما بوابة المراسلة ولماذا قد تحتاجه.
  • تنفّذ hermes gateway وhermes gateway setup وتفهم ما يحدث بعدها.
  • تقرأ الجدول وتأخذ منه السطر الذي يخصّك فقط.
  • تضبط LINE_PORT في المكان الصحيح.
ما ستقابله من أسماء

كما تظهر تمامًا داخل Hermes.

الأوامر
  • hermes gateway
  • hermes gateway setup
متغيرات البيئة
  • LINE_PORT
  • LINE_CHANNEL_ACCESS_TOKEN
  • YOUR_LONG_LIVED_TOKEN
  • LINE_CHANNEL_SECRET
  • YOUR_CHANNEL_SECRET
  • LINE_ALLOW_ALL_USERS
  • LINE_ALLOWED_USERS
  • LINE_ALLOWED_GROUPS
خريطة الصفحة

انتقل مباشرة إلى ما تحتاجه.

  1. 01How the bot responds
  2. 02Step 1: Create a LINE Messaging API channel
  3. 03Step 2: Expose the webhook port
  4. 04Step 3: Configure Hermes
  5. 05Step 4: Set the webhook URL
  6. 06Step 5: Run the gateway
  7. 07Slow LLM responses
  8. 08Cron / notification delivery
  9. 09Environment variable reference
  10. 10Troubleshooting
  11. 11Limitations
الصفحة الرسمية كاملة

بلا اختصار أو حذف.

النص أدناه منقول من المصدر الرسمي بالإنجليزية حتى تبقى الأوامر والأسماء دقيقة كما هي. قبل كل قسم شرح عربي يوضّح ما بداخله.

Run Hermes Agent as a LINE ↗ bot via the official LINE Messaging API. The adapter lives as a bundled platform plugin under plugins/platforms/line/ — no core edits, just enable it like any other platform.

LINE is the dominant messaging app in Japan, Taiwan, and Thailand. If your users live there, this is how they reach you.

Run hermes gateway setup and pick LINE for a guided walk-through.

How the bot responds

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه. تذكير: الوصلة التي تجعلك تكلّم Hermes من تطبيق تستعمله أصلًا، مثل Telegram أو WhatsApp، بدل الطرفية.

ContextBehavior
1:1 chat (U IDs)Responds to every message
Group chat (C IDs)Responds when the group is on the allowlist
Multi-user room (R IDs)Responds when the room is on the allowlist

Inbound text, images, audio, video, files, stickers, and locations are all handled. Outbound text uses the free reply token first (single-use, ~60s window) and falls back to the metered Push API when the token has expired.

---

Step 1: Create a LINE Messaging API channel

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية.

  1. Go to the LINE Developers Console ↗.
  2. Create a Provider, then under it a Messaging API channel.
  3. From the channel's Basic settings tab, copy the Channel secret.
  4. From the Messaging API tab, scroll to Channel access token (long-lived) and click Issue. Copy the token.
  5. In the Messaging API tab, also disable Auto-reply messages and Greeting messages so they don't fight your bot's replies.

---

Step 2: Expose the webhook port

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية.

LINE delivers webhooks over public HTTPS. The default port is 8646 — override with LINE_PORT if needed.

Shell10 أسطر
# Cloudflare Tunnel (recommended for production — fixed hostname)
cloudflared tunnel --url http://localhost:8646

# ngrok (good for dev)
ngrok http 8646

# devtunnel
devtunnel create hermes-line --allow-anonymous
devtunnel port create hermes-line -p 8646 --protocol https
devtunnel host hermes-line

Copy the https://... URL — you'll set it as the webhook URL below. Leave the tunnel running while testing. For production, set up a fixed Cloudflare named tunnel so the webhook URL doesn't change on restart.

---

Step 3: Configure Hermes

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية.

Add to ~/.hermes/.env:

ENV11 سطرًا
LINE_CHANNEL_ACCESS_TOKEN=YOUR_LONG_LIVED_TOKEN
LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET

# Allowlist — at least one of these (or LINE_ALLOW_ALL_USERS=true for dev)
LINE_ALLOWED_USERS=U1234567890abcdef...           # comma-separated U-prefixed IDs
LINE_ALLOWED_GROUPS=C1234567890abcdef...          # optional group IDs
LINE_ALLOWED_ROOMS=R1234567890abcdef...           # optional room IDs

# Required for image / audio / video sends — the public HTTPS base URL
# the tunnel resolves to.  Without it, send_image/voice/video will refuse.
LINE_PUBLIC_URL=https://my-tunnel.example.com

Then in ~/.hermes/config.yaml:

YAML4 أسطر
gateway:
  platforms:
    line:
      enabled: true

That's enough — the bundled-plugin scan in gateway/config.py automatically picks up plugins/platforms/line/. No Platform.LINE enum edit, no _create_adapter registration.

---

Step 4: Set the webhook URL

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية.

Back in the LINE console:

  1. Open your channel → Messaging API tab.
  2. Under Webhook settings → Webhook URL, paste https://<your-tunnel>/line/webhook (note the /line/webhook path — the adapter listens there).
  3. Click Verify. LINE pings the URL; you should see a 200.
  4. Toggle Use webhook to On.

---

Step 5: Run the gateway

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية. الأوامر هنا: hermes gateway.

Shellسطر واحد
hermes gateway

The agent log shows:

Textسطر واحد
LINE: webhook listening on * (all interfaces, IPv4+IPv6):8646/line/webhook (public: https://my-tunnel.example.com)

Add the bot as a friend from the LINE app (scan the QR in the channel's Messaging API tab) and send it a message.

---

Slow LLM responses

إعدادات تضبطها مرة وتنساها. غيّر واحدًا في كل مرة حتى تعرف أثر كل تغيير. تضبط LINE_SLOW_RESPONSE_THRESHOLD خارج المحادثة، في بيئة التشغيل.

LINE's reply token is single-use and expires roughly 60 seconds after the inbound event. Slow LLMs can't reply in time, which would normally force a paid Push API call.

When the LLM is still running past LINE_SLOW_RESPONSE_THRESHOLD seconds (default 45), the adapter consumes the original reply token to send a Template Buttons bubble:

🤔 Still thinking. Tap below to fetch the answer when it's ready. [ Get answer ]

The user taps Get answer when convenient — that postback delivers a fresh reply token, which the adapter uses to send the cached answer (still free).

State machine: PENDING → READY → DELIVERED, plus ERROR for cancelled runs (the orphan PENDING resolves to "Run was interrupted before completion." after /stop so the persistent button doesn't loop).

To disable the postback button and always Push-fallback instead:

ENVسطر واحد
LINE_SLOW_RESPONSE_THRESHOLD=0

For the postback flow to fire reliably, suppress chatter that would consume the reply token before the threshold:

YAML6 أسطر
# ~/.hermes/config.yaml
display:
  interim_assistant_messages: false
  platforms:
    line:
      tool_progress: off

---

Cron / notification delivery

إعدادات تضبطها مرة وتنساها. غيّر واحدًا في كل مرة حتى تعرف أثر كل تغيير. تضبط LINE_HOME_CHANNEL خارج المحادثة، في بيئة التشغيل.

ENVسطر واحد
LINE_HOME_CHANNEL=Uxxxxxxxxxxxxxxxxxxxx     # default delivery target

Cron jobs with deliver: line route to LINE_HOME_CHANNEL. The adapter ships a standalone Push-only sender so cron jobs work even when cron runs in a separate process from the gateway.

---

Environment variable reference

جدول مرجعي. لا تقرأه كله، ابحث عن السطر الذي يخصّك فقط.

VariableRequiredDefaultDescription
LINE_CHANNEL_ACCESS_TOKENyes—Long-lived channel access token
LINE_CHANNEL_SECRETyes—Channel secret (HMAC-SHA256 webhook verification)
LINE_HOSTnounset (dual-stack: all interfaces, IPv4+IPv6)Webhook bind host
LINE_PORTno8646Webhook bind port
LINE_PUBLIC_URLfor media—Public HTTPS base URL; required for image/voice/video sends
LINE_ALLOWED_USERSone of—Comma-separated user IDs (U-prefixed)
LINE_ALLOWED_GROUPSone of—Comma-separated group IDs (C-prefixed)
LINE_ALLOWED_ROOMSone of—Comma-separated room IDs (R-prefixed)
LINE_ALLOW_ALL_USERSdev onlyfalseSkip allowlist entirely
LINE_HOME_CHANNELno—Default cron / notification delivery target
LINE_SLOW_RESPONSE_THRESHOLDno45Seconds before the postback button fires (0 = disabled)
LINE_PENDING_TEXTno"🤔 Still thinking…"Bubble text shown alongside the postback button
LINE_BUTTON_LABELno"Get answer"Button label
LINE_DELIVERED_TEXTno"Already replied ✅"Reply when an already-delivered button is tapped again
LINE_INTERRUPTED_TEXTno"Run was interrupted before completion."Reply when a /stop orphan button is tapped

---

Troubleshooting

قسم لحل المشكلات. ابحث فيه عن العطل الذي يشبه حالتك بدل قراءته كاملًا.

"invalid signature" on webhook verify. The Channel secret was copied wrong, or your tunnel rewrote the request body. Verify with curl -i https://<tunnel>/line/webhook/health first — that should return {"status":"ok","platform":"line"}.

Bot receives nothing in groups. Check LINE_ALLOWED_GROUPS includes the C... group ID. To find a group ID, send a test message and grep ~/.hermes/logs/gateway.log for LINE: rejecting unauthorized source — the rejected source dict has the IDs.

send_image fails with "LINE_PUBLIC_URL must be set". LINE's Messaging API does not accept binary uploads — images, audio, and video must be reachable HTTPS URLs. Set LINE_PUBLIC_URL to the tunnel's public hostname and the adapter will serve files from /line/media/<token>/<filename> automatically.

Postback button never appears. Either the LLM responded faster than LINE_SLOW_RESPONSE_THRESHOLD, or another bubble (tool-progress, streaming) consumed the reply token first. See the suppression block under "Slow LLM responses".

"already in use by another profile". The same channel access token is bound to another running Hermes profile. Stop the other gateway or use a separate channel.

---

Limitations

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه.

  • Bubble and length caps. Each LINE text bubble is capped at 5000 characters. Longer responses are smart-chunked at ~4500 characters across up to 5 bubbles per Reply/Push call, splitting on natural boundaries where possible.
  • No native message editing. LINE has no edit-message API — streaming responses always send fresh bubbles, never edit prior ones.
  • No Markdown rendering. Bold (**), italics (*), code fences, and headings render as literal characters. The adapter strips them before sending; URLs are preserved ([label](https://hermes-agent.nousresearch.com/docs/url) becomes label (url)).
  • Loading indicator is DM-only. LINE rejects the chat/loading API for groups and rooms, so the typing indicator only shows in 1:1 chats.
اختبار الفهم

4 أسئلة إجاباتها كلها في هذه الصفحة.

كل خيار اسم حقيقي من توثيق Hermes. حتى الخيارات الخاطئة حقيقية، لكنها من صفحات أخرى.

1. في جدول هذا الدرس، ما «Behavior» المقابل لـ«1:1 chat (U IDs)»؟
2. أي متغير بيئة من التالي يظهر فعليًا في هذا الدرس؟
3. أي عنوان من التالي لا يظهر في هذا الدرس؟
4. أي مفتاح إعداد يظهر في أمثلة هذا الدرس؟