mirror of
https://github.com/whyour/qinglong.git
synced 2026-05-13 23:55:22 +08:00
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:
parent
b6f088e77b
commit
8e234afcf6
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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}`,
|
||||||
|
|
|
||||||
|
|
@ -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 变量名= 声明即可
|
||||||
|
|
|
||||||
|
|
@ -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 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 = {
|
const options = {
|
||||||
url: 'https://hub.openilink.com/bot/v1/message/send',
|
url: `${baseUrl}/bot/v1/message/send`,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(body),
|
||||||
type: 'text',
|
|
||||||
content: `${text}\n\n${desp}`,
|
|
||||||
}),
|
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${OPENILINK_APP_TOKEN}`,
|
Authorization: `Bearer ${OPENILINK_APP_TOKEN}`,
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user