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

استدعاءات WeCom للتطبيق الذاتي

WeCom Callback (Self-Built App)

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

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

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

10أقسام
4أمثلة برمجية
2جداول
5أوامر
868كلمة من المصدر
ماذا ستستطيع بعدها

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

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

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

الأوامر
  • hermes gateway run
  • hermes gateway
  • hermes gateway setup
  • hermes gateway start
  • hermes gateway install
متغيرات البيئة
  • WECOM_CALLBACK_CORP_ID
  • WECOM_CALLBACK_CORP_SECRET
  • WECOM_CALLBACK_AGENT_ID
  • WECOM_CALLBACK_TOKEN
  • WECOM_CALLBACK_ENCODING_AES_KEY
  • WECOM_CALLBACK_HOST
  • WECOM_CALLBACK_PORT
  • WECOM_CALLBACK_ALLOWED_USERS
خريطة الصفحة

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

  1. 01How It Works
  2. 02Prerequisites
  3. 03Setup
  4. 04Configuration Reference
  5. 05Multi-App Routing
  6. 06Access Control
  7. 07Endpoints
  8. 08Encryption
  9. 09Limitations
  10. 10Troubleshooting
الصفحة الرسمية كاملة

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

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

Connect Hermes to WeCom (Enterprise WeChat) as a self-built enterprise application using the callback/webhook model.

See also: WeCom Bot for the bot-style integration.

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

How It Works

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

  1. You register a self-built application in the WeCom Admin Console
  2. WeCom pushes encrypted XML to your HTTP callback endpoint
  3. Hermes decrypts the message, queues it for the agent
  4. Immediately acknowledges (silent — nothing displayed to the user)
  5. The agent processes the request (typically 3–30 minutes)
  6. The reply is delivered proactively via the WeCom message/send API

Prerequisites

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

  • A WeCom enterprise account with admin access
  • aiohttp and httpx Python packages (included in the default install)
  • A publicly reachable server for the callback URL (or a tunnel like ngrok)

Setup

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

1. Create a Self-Built App in WeCom

  1. Go to WeCom Admin Console ↗ → Applications → Create App
  2. Note your Corp ID (shown at the top of the admin console)
  3. In the app settings, create a Corp Secret
  4. Note the Agent ID from the app's overview page
  5. Under Receive Messages, configure the callback URL:
  6. URL: http://YOUR_PUBLIC_IP:8645/wecom/callback
  7. Token: Generate a random token (WeCom provides one)
  8. EncodingAESKey: Generate a key (WeCom provides one)

2. Configure Environment Variables

Add to your .env file:

Shell10 أسطر
WECOM_CALLBACK_CORP_ID=your-corp-id
WECOM_CALLBACK_CORP_SECRET=your-corp-secret
WECOM_CALLBACK_AGENT_ID=1000002
WECOM_CALLBACK_TOKEN=your-callback-token
WECOM_CALLBACK_ENCODING_AES_KEY=your-43-char-aes-key

# Optional
# WECOM_CALLBACK_HOST=  # optional pin; unset = dual-stack (all interfaces, IPv4+IPv6)
WECOM_CALLBACK_PORT=8645
WECOM_CALLBACK_ALLOWED_USERS=user1,user2

3. Start the Gateway

Shellسطر واحد
hermes gateway

(Use hermes gateway start only after hermes gateway install has registered the systemd/launchd service.)

The callback adapter starts an HTTP server on the configured port. WeCom will verify the callback URL via a GET request, then begin sending messages via POST.

Configuration Reference

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

Set these in config.yaml under platforms.wecom_callback.extra, or use environment variables:

SettingDefaultDescription
corp_id—WeCom enterprise Corp ID (required)
corp_secret—Corp secret for the self-built app (required)
agent_id—Agent ID of the self-built app (required)
token—Callback verification token (required)
encoding_aes_key—43-character AES key for callback encryption (required)
hostunset (dual-stack: all interfaces, IPv4+IPv6)Bind address for the HTTP callback server
port8645Port for the HTTP callback server
path/wecom/callbackURL path for the callback endpoint

Multi-App Routing

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

For enterprises running multiple self-built apps (e.g., across different departments or subsidiaries), configure the apps list in config.yaml:

YAML19 سطرًا
platforms:
  wecom_callback:
    enabled: true
    extra:
      host: "0.0.0.0"
      port: 8645
      apps:
        - name: "dept-a"
          corp_id: "ww_corp_a"
          corp_secret: "secret-a"
          agent_id: "1000002"
          token: "token-a"
          encoding_aes_key: "key-a-43-chars..."
        - name: "dept-b"
          corp_id: "ww_corp_b"
          corp_secret: "secret-b"
          agent_id: "1000003"
          token: "token-b"
          encoding_aes_key: "key-b-43-chars..."

Users are scoped by corp_id:user_id to prevent cross-corp collisions. When a user sends a message, the adapter records which app (corp) they belong to and routes replies through the correct app's access token.

Access Control

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

Restrict which users can interact with the app:

Shell5 أسطر
# Allowlist specific users
WECOM_CALLBACK_ALLOWED_USERS=zhangsan,lisi,wangwu

# Or allow all users
WECOM_CALLBACK_ALLOW_ALL_USERS=true

Endpoints

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

The adapter exposes:

MethodPathPurpose
GET/wecom/callbackURL verification handshake (WeCom sends this during setup)
POST/wecom/callbackEncrypted message callback (WeCom sends user messages here)
GET/healthHealth check — returns {"status": "ok"}

Encryption

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

All callback payloads are encrypted with AES-CBC using the EncodingAESKey. The adapter handles:

  • Inbound: Decrypt XML payload, verify SHA1 signature
  • Outbound: Replies sent via proactive API (not encrypted callback response)

The crypto implementation is compatible with Tencent's official WXBizMsgCrypt SDK.

Limitations

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

  • No streaming — replies arrive as complete messages after the agent finishes
  • No typing indicators — the callback model doesn't support typing status
  • Text only — currently supports text messages for input; image/file/voice input not yet implemented. The agent is aware of outbound media capabilities via the WeCom platform hint (images, documents, video, voice).
  • Response latency — agent sessions take 3–30 minutes; users see the reply when processing completes

Troubleshooting

قسم لحل المشكلات. ابحث فيه عن العطل الذي يشبه حالتك بدل قراءته كاملًا. الأوامر هنا: hermes gateway run.

Signature verification failing. WeCom signs every request with the Token you registered in the admin console. A mismatch between the token configured in Hermes and the token the admin console expects is the most common cause. Re-copy both the Token and EncodingAESKey from the admin console — they're easy to truncate. Whitespace in ~/.hermes/.env values around = will also break signature checks. After fixing, restart hermes gateway run.

Callback URL not reachable / verification step fails. WeCom hits the public URL you registered. Confirm:

  1. Your reverse proxy / tunnel forwards /wecom/callback to the gateway's port.
  2. The URL in the admin console is HTTPS (WeCom rejects plain HTTP).
  3. From outside your network, curl -i https://<your-domain>/wecom/callback returns something other than a timeout (a 4xx without query params is fine — it just means the listener is reachable).

Port not reachable / listener not bound. Check hermes gateway run logs for the bound host/port. If the adapter bound to 127.0.0.1 you must front it with a reverse proxy or tunnel — WeCom's servers can't reach loopback. Leave extra.host unset so the default dual-stack bind (all interfaces, IPv4+IPv6) applies, or pin an interface in config.yaml (plus allowed_source_cidrs if exposing directly) or keep loopback and use a tunnel such as Cloudflare Tunnel / nginx.

اختبار الفهم

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

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

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