Back to Templates

Agent for IM

An OpenAI Agents SDK chat agent that connects Slack, Discord, Telegram, Feishu, WeCom, and DingTalk via webhooks, with a streaming web UI for debugging.

View Demo
FrameworkReact.js
Use CaseAgents,AI
An OpenAI Agents SDK chat agent that connects Slack, Discord, Telegram, Feishu, WeCom, and DingTalk via webhooks, with a streaming web UI for debugging.

Agent for IM

A multi-platform IM agent on EdgeOne Makers. Use agent to answers Slack, Discord, Telegram, Feishu, WeCom, and DingTalk.

Framework: Chat SDK · Language: TypeScript

Supported platforms

PlatformRouteSetup
SlackPOST /slackEvents API Request URL
DiscordPOST /discordInteractions Endpoint URL
DiscordPOST /discord-gatewayGateway listener for channel @mentions
TelegramPOST /telegramBot API setWebhook
FeishuPOST /feishuEvent Request URL
WeComGET / POST /wecomSelf-built app callback (1:1)
DingTalkPOST /dingtalkInternal-app robot HTTP callback

Discord channel messages need POST /discord-gateway, or npm run gateway locally. Do not run two listeners on one bot token.

Web inbox

The frontend is a read-only archive, not a live chat box. After each IM turn the agent writes channel metadata, the user message, and the reply to Makers context.store. The UI calls:

RouteRole
POST /inboxList threads (filter by platform / DM / keyword)
POST /historyLoad one transcript
POST /delete-conversationDelete an archived thread

New conversations appear after this version is deployed. Older IM threads were not indexed for the inbox.

Environment variables

Copy .env.example to .env. Only configure the platforms you use.

Always required

VariableDescription
AI_GATEWAY_API_KEYModel gateway API key (Makers Models or any OpenAI-compatible provider).
AI_GATEWAY_BASE_URLGateway base URL. Makers Models: https://ai-gateway.edgeone.link/v1.
AI_GATEWAY_MODELOptional. Defaults to @makers/deepseek-v4-flash.
AGENT_CALLBACK_SECRETShared secret for delivering IM replies.

Slack

Request URL: https://<domain>/slack

VariableDescription
SLACK_SIGNING_SECRETApp Credentials → Signing Secret
SLACK_BOT_TOKENBot User OAuth Token (xoxb-). Reinstall the app after changing scopes.

Required scopes: users:read, app_mentions:read, chat:write, plus channels/groups/im/mpim history and read. Subscribe to app_mention and/or message.channels, and message.im for DMs.

Discord

Interactions URL: https://<domain>/discord. Enable Message Content Intent.

VariableDescription
DISCORD_BOT_TOKENBot token
DISCORD_PUBLIC_KEYApplication public key (64-char hex)
DISCORD_APPLICATION_IDApplication ID
DISCORD_GATEWAY_SECRETBearer token for POST /discord-gateway (falls back to CRON_SECRET)

Optional: DISCORD_MENTION_ROLE_IDS, DISCORD_RESPOND_TO_CHANNEL_IDS, DISCORD_WEBHOOK_URL (local gateway target).

Telegram

Register once (re-run if the domain changes):

curl -X POST "https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/setWebhook" \
  -d url=https://<domain>/telegram \
  -d secret_token=<TELEGRAM_WEBHOOK_SECRET_TOKEN>
VariableDescription
TELEGRAM_BOT_TOKENFrom BotFather
TELEGRAM_WEBHOOK_SECRET_TOKENWebhook secret token. /telegram refuses to run without it.

In groups the bot only sees @mentions unless you disable privacy mode (/setprivacy).

Feishu

Event Request URL: https://<domain>/feishu (https, no trailing slash). Subscribe to im.message.receive_v1. Configure Encrypt Key and Verification Token under 事件与回调 → 加密策略.

VariableDescription
FEISHU_APP_IDcli_…
FEISHU_APP_SECRETApp secret
FEISHU_ENCRYPT_KEYEncrypt Key
FEISHU_VERIFICATION_TOKENVerification Token

WeCom (self-built app, 1:1)

接收消息服务器 URL: https://<domain>/wecom. Replies go through a hardcoded SCF with a static outbound IP. Add that IP under 企业可信IP.

VariableDescription
WECOM_CORP_IDCorp ID
WECOM_AGENT_IDAgent ID
WECOM_APP_SECRETApp secret
WECOM_TOKENCallback token
WECOM_ENCODING_AES_KEY43-char EncodingAESKey

DingTalk (internal-app robot)

HTTP callback: https://<domain>/dingtalk

VariableDescription
DINGTALK_APP_KEYApp key
DINGTALK_APP_SECRETApp secret
DINGTALK_ROBOT_CODERobot code

Local development

Prerequisites: Node.js ≥ 18 and the EdgeOne CLI (npm i -g edgeone).

npm install
cp .env.example .env
npm run dev:agents
  • Web UI: Vite on the usual local port (read-only inbox for archived IM threads).
  • Agent metrics: http://localhost:8080/agent-metrics.
  • Discord Gateway locally (do not run this and /discord-gateway at the same time):
npm run gateway

Project structure

agent-for-im/
├── agents/                          # EdgeOne Makers Agents
│   ├── chat/index.ts               # POST /chat
│   ├── stop/index.ts               # POST /stop
│   ├── discord-gateway/index.ts    # POST /discord-gateway
│   └── _tools.ts                   # Sample tools
├── cloud-functions/                 # IM webhooks and conversation APIs
│   ├── slack/ · discord/ · telegram/ · feishu/ · wecom/ · dingtalk/
│   ├── chat-callback/
│   ├── history/ · inbox/ · delete-conversation/
│   └── _adapters/                  # One file per vendor
├── src/                             # React + Vite inbox (read-only archive)
├── scripts/discord-gateway.mjs
├── package.json
├── edgeone.json
└── .env.example

Files prefixed with _ are private modules — not public routes.

Adding another IM vendor

  1. Add the official @chat-adapter/<name> package, or a community adapter such as @edgeone/chat-adapter-feishu.
  2. Create cloud-functions/_adapters/<name>.ts and register it in _adapters/index.ts.
  3. Add cloud-functions/<name>/index.ts with createVendorWebhook.
  4. If the vendor has no HTTP events (Discord Gateway), add a long-lived listener in agents/.

Resources

License

MIT.