From 8e234afcf6485ca697e3ecd74b9926939be8e4fe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 25 Apr 2026 07:27:59 +0000 Subject: [PATCH] Add context_token and hub_url to OpeniLink notification channel Agent-Logs-Url: https://github.com/whyour/qinglong/sessions/a5e66f5a-dab8-4a65-96ca-960d35fa9d50 Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- back/data/notify.ts | 2 ++ back/services/notify.ts | 18 ++++++++++++------ sample/config.sample.sh | 4 ++++ sample/notify.js | 22 ++++++++++++++++------ sample/notify.py | 12 +++++++++++- src/utils/config.ts | 12 ++++++++++++ 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/back/data/notify.ts b/back/data/notify.ts index ce5c9aea..1d048dfe 100644 --- a/back/data/notify.ts +++ b/back/data/notify.ts @@ -164,6 +164,8 @@ export class WxPusherBotNotification extends NotificationBaseInfo { export class OpeniLinkNotification extends NotificationBaseInfo { public openiLinkAppToken = ''; + public openiLinkHubUrl = ''; + public openiLinkContextToken = ''; } export interface NotificationInfo diff --git a/back/services/notify.ts b/back/services/notify.ts index 55f44fc3..a8b2aeea 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -861,15 +861,21 @@ export default class NotificationService { } private async openiLink() { - const { openiLinkAppToken } = this.params; - const url = 'https://hub.openilink.com/bot/v1/message/send'; + const { openiLinkAppToken, openiLinkHubUrl, openiLinkContextToken } = + this.params; + const baseUrl = openiLinkHubUrl?.replace(/\/$/, '') || 'https://hub.openilink.com'; + const url = `${baseUrl}/bot/v1/message/send`; + const body: Record = { + type: 'text', + content: `${this.title}\n\n${this.content}`, + }; + if (openiLinkContextToken) { + body.context_token = openiLinkContextToken; + } try { const res = await httpClient.post(url, { ...this.gotOption, - json: { - type: 'text', - content: `${this.title}\n\n${this.content}`, - }, + json: body, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${openiLinkAppToken}`, diff --git a/sample/config.sample.sh b/sample/config.sample.sh index caa083f7..9c93e78f 100644 --- a/sample/config.sample.sh +++ b/sample/config.sample.sh @@ -263,5 +263,9 @@ export WEBHOOK_CONTENT_TYPE="" ## 官方文档: https://openilink.com/docs/hub/apps ## 在 OpeniLink Hub 后台安装 App 后获取 app_token export OPENILINK_APP_TOKEN="" +## OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址 +export OPENILINK_HUB_URL="" +## OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取 +export OPENILINK_CONTEXT_TOKEN="" ## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可 diff --git a/sample/notify.js b/sample/notify.js index 741182d7..89803264 100644 --- a/sample/notify.js +++ b/sample/notify.js @@ -154,6 +154,8 @@ const push_config = { // 官方文档: https://openilink.com/docs/hub/apps OPENILINK_APP_TOKEN: '', // OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取 + OPENILINK_HUB_URL: '', // OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址 + OPENILINK_CONTEXT_TOKEN: '', // OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取 }; for (const key in push_config) { @@ -1413,14 +1415,22 @@ function wxPusherNotify(text, desp) { function openiLinkNotify(text, desp) { return new Promise((resolve) => { - const { OPENILINK_APP_TOKEN } = push_config; + const { OPENILINK_APP_TOKEN, OPENILINK_HUB_URL, OPENILINK_CONTEXT_TOKEN } = + push_config; if (OPENILINK_APP_TOKEN) { + const baseUrl = OPENILINK_HUB_URL + ? OPENILINK_HUB_URL.replace(/\/$/, '') + : 'https://hub.openilink.com'; + const body = { + type: 'text', + content: `${text}\n\n${desp}`, + }; + if (OPENILINK_CONTEXT_TOKEN) { + body.context_token = OPENILINK_CONTEXT_TOKEN; + } const options = { - url: 'https://hub.openilink.com/bot/v1/message/send', - body: JSON.stringify({ - type: 'text', - content: `${text}\n\n${desp}`, - }), + url: `${baseUrl}/bot/v1/message/send`, + body: JSON.stringify(body), headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${OPENILINK_APP_TOKEN}`, diff --git a/sample/notify.py b/sample/notify.py index e153bff3..46383498 100644 --- a/sample/notify.py +++ b/sample/notify.py @@ -137,6 +137,8 @@ push_config = { 'WXPUSHER_UIDS': '', # wxpusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行 'OPENILINK_APP_TOKEN': '', # OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取 官方文档: https://openilink.com/docs/hub/apps + 'OPENILINK_HUB_URL': '', # OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址 + 'OPENILINK_CONTEXT_TOKEN': '', # OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取 } # fmt: on @@ -905,13 +907,19 @@ def openilink(title: str, content: str) -> None: 通过 OpeniLink 推送消息。 支持的环境变量: - OPENILINK_APP_TOKEN: 在 OpeniLink Hub 后台安装 App 后获取的 app_token + - OPENILINK_HUB_URL: OpeniLink Hub 地址,默认为 https://hub.openilink.com + - OPENILINK_CONTEXT_TOKEN: 消息会话上下文 token,可从消息事件中获取 """ if not push_config.get("OPENILINK_APP_TOKEN"): return print("OpeniLink 服务启动") - url = "https://hub.openilink.com/bot/v1/message/send" + base_url = ( + push_config.get("OPENILINK_HUB_URL", "").rstrip("/") + or "https://hub.openilink.com" + ) + url = f"{base_url}/bot/v1/message/send" headers = { "Content-Type": "application/json", "Authorization": f'Bearer {push_config.get("OPENILINK_APP_TOKEN")}', @@ -920,6 +928,8 @@ def openilink(title: str, content: str) -> None: "type": "text", "content": f"{title}\n\n{content}", } + if push_config.get("OPENILINK_CONTEXT_TOKEN"): + data["context_token"] = push_config.get("OPENILINK_CONTEXT_TOKEN") response = requests.post(url=url, json=data, headers=headers).json() diff --git a/src/utils/config.ts b/src/utils/config.ts index 3aead8e5..f15a48b5 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -396,6 +396,18 @@ export default { ), required: true, }, + { + label: 'openiLinkHubUrl', + tip: intl.get( + 'OpeniLink Hub地址,默认为 https://hub.openilink.com,自建Hub时填写自己的地址', + ), + }, + { + label: 'openiLinkContextToken', + tip: intl.get( + 'OpeniLink的context_token,用于标识消息会话上下文,可从消息事件中获取', + ), + }, ], lark: [ {