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>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-25 07:27:59 +00:00 committed by GitHub
parent b6f088e77b
commit 8e234afcf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 57 additions and 13 deletions

View File

@ -164,6 +164,8 @@ export class WxPusherBotNotification extends NotificationBaseInfo {
export class OpeniLinkNotification extends NotificationBaseInfo { export class OpeniLinkNotification extends NotificationBaseInfo {
public openiLinkAppToken = ''; public openiLinkAppToken = '';
public openiLinkHubUrl = '';
public openiLinkContextToken = '';
} }
export interface NotificationInfo export interface NotificationInfo

View File

@ -861,15 +861,21 @@ export default class NotificationService {
} }
private async openiLink() { private async openiLink() {
const { openiLinkAppToken } = this.params; const { openiLinkAppToken, openiLinkHubUrl, openiLinkContextToken } =
const url = 'https://hub.openilink.com/bot/v1/message/send'; this.params;
const baseUrl = openiLinkHubUrl?.replace(/\/$/, '') || 'https://hub.openilink.com';
const url = `${baseUrl}/bot/v1/message/send`;
const body: Record<string, string> = {
type: 'text',
content: `${this.title}\n\n${this.content}`,
};
if (openiLinkContextToken) {
body.context_token = openiLinkContextToken;
}
try { try {
const res = await httpClient.post(url, { const res = await httpClient.post(url, {
...this.gotOption, ...this.gotOption,
json: { json: body,
type: 'text',
content: `${this.title}\n\n${this.content}`,
},
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Bearer ${openiLinkAppToken}`, Authorization: `Bearer ${openiLinkAppToken}`,

View File

@ -263,5 +263,9 @@ export WEBHOOK_CONTENT_TYPE=""
## 官方文档: https://openilink.com/docs/hub/apps ## 官方文档: https://openilink.com/docs/hub/apps
## 在 OpeniLink Hub 后台安装 App 后获取 app_token ## 在 OpeniLink Hub 后台安装 App 后获取 app_token
export OPENILINK_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 变量名= 声明即可 ## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可

View File

@ -154,6 +154,8 @@ const push_config = {
// 官方文档: https://openilink.com/docs/hub/apps // 官方文档: https://openilink.com/docs/hub/apps
OPENILINK_APP_TOKEN: '', // OpeniLink 的 app_token在 OpeniLink Hub 后台安装 App 后获取 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) { for (const key in push_config) {
@ -1413,14 +1415,22 @@ function wxPusherNotify(text, desp) {
function openiLinkNotify(text, desp) { function openiLinkNotify(text, desp) {
return new Promise((resolve) => { 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) { if (OPENILINK_APP_TOKEN) {
const options = { const baseUrl = OPENILINK_HUB_URL
url: 'https://hub.openilink.com/bot/v1/message/send', ? OPENILINK_HUB_URL.replace(/\/$/, '')
body: JSON.stringify({ : 'https://hub.openilink.com';
const body = {
type: 'text', type: 'text',
content: `${text}\n\n${desp}`, content: `${text}\n\n${desp}`,
}), };
if (OPENILINK_CONTEXT_TOKEN) {
body.context_token = OPENILINK_CONTEXT_TOKEN;
}
const options = {
url: `${baseUrl}/bot/v1/message/send`,
body: JSON.stringify(body),
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Bearer ${OPENILINK_APP_TOKEN}`, Authorization: `Bearer ${OPENILINK_APP_TOKEN}`,

View File

@ -137,6 +137,8 @@ push_config = {
'WXPUSHER_UIDS': '', # wxpusher 的 用户ID多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行 'WXPUSHER_UIDS': '', # wxpusher 的 用户ID多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
'OPENILINK_APP_TOKEN': '', # OpeniLink 的 app_token在 OpeniLink Hub 后台安装 App 后获取 官方文档: https://openilink.com/docs/hub/apps '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 # fmt: on
@ -905,13 +907,19 @@ def openilink(title: str, content: str) -> None:
通过 OpeniLink 推送消息 通过 OpeniLink 推送消息
支持的环境变量: 支持的环境变量:
- OPENILINK_APP_TOKEN: OpeniLink Hub 后台安装 App 后获取的 app_token - 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"): if not push_config.get("OPENILINK_APP_TOKEN"):
return return
print("OpeniLink 服务启动") 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 = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": f'Bearer {push_config.get("OPENILINK_APP_TOKEN")}', "Authorization": f'Bearer {push_config.get("OPENILINK_APP_TOKEN")}',
@ -920,6 +928,8 @@ def openilink(title: str, content: str) -> None:
"type": "text", "type": "text",
"content": f"{title}\n\n{content}", "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() response = requests.post(url=url, json=data, headers=headers).json()

View File

@ -396,6 +396,18 @@ export default {
), ),
required: true, required: true,
}, },
{
label: 'openiLinkHubUrl',
tip: intl.get(
'OpeniLink Hub地址默认为 https://hub.openilink.com自建Hub时填写自己的地址',
),
},
{
label: 'openiLinkContextToken',
tip: intl.get(
'OpeniLink的context_token用于标识消息会话上下文可从消息事件中获取',
),
},
], ],
lark: [ lark: [
{ {