Skip to content

Commit 5dd56f2

Browse files
authored
Merge pull request #455 from EkkoG/wechat_bot
2 parents 05eae71 + 275b095 commit 5dd56f2

4 files changed

Lines changed: 186 additions & 63 deletions

File tree

src/components/cards/NotificationChannelCard.vue

Lines changed: 153 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,39 @@ const notificationTypes = [
6767
{ value: '其它', title: t('notificationSwitch.other') },
6868
]
6969
70+
function ensureWechatConfigDefaults(notification: NotificationConf) {
71+
if (notification.type !== 'wechat') {
72+
return
73+
}
74+
if (!notification.config) {
75+
notification.config = {}
76+
}
77+
if (!notification.config.WECHAT_MODE) {
78+
notification.config.WECHAT_MODE = 'app'
79+
}
80+
if (!notification.config.WECHAT_BOT_WS_URL) {
81+
notification.config.WECHAT_BOT_WS_URL = 'wss://openws.work.weixin.qq.com'
82+
}
83+
}
84+
85+
const isWechatBotMode = computed({
86+
get: () => notificationInfo.value.config?.WECHAT_MODE === 'bot',
87+
set: value => {
88+
if (!notificationInfo.value.config) {
89+
notificationInfo.value.config = {}
90+
}
91+
notificationInfo.value.config.WECHAT_MODE = value ? 'bot' : 'app'
92+
if (value && !notificationInfo.value.config.WECHAT_BOT_WS_URL) {
93+
notificationInfo.value.config.WECHAT_BOT_WS_URL = 'wss://openws.work.weixin.qq.com'
94+
}
95+
},
96+
})
97+
7098
// 打开详情弹窗
7199
function openNotificationInfoDialog() {
72100
// 替换成深复制,避免修改时影响原数据
73101
notificationInfo.value = cloneDeep(props.notification)
102+
ensureWechatConfigDefaults(notificationInfo.value)
74103
notificationInfoDialog.value = true
75104
}
76105
@@ -86,6 +115,7 @@ function saveNotificationInfo() {
86115
$toast.error(t('notification.channel') + `【${notificationInfo.value.name}】` + t('common.exists'))
87116
return
88117
}
118+
ensureWechatConfigDefaults(notificationInfo.value)
89119
notificationInfoDialog.value = false
90120
emit('change', notificationInfo.value, props.notification.name)
91121
emit('done')
@@ -190,69 +220,129 @@ function onClose() {
190220
/>
191221
</VCol>
192222
<VCol cols="12" md="6">
193-
<VTextField
194-
v-model="notificationInfo.config.WECHAT_CORPID"
195-
:label="t('notification.wechat.corpId')"
196-
:hint="t('notification.wechat.corpIdHint')"
197-
persistent-hint
198-
prepend-inner-icon="mdi-domain"
199-
/>
200-
</VCol>
201-
<VCol cols="12" md="6">
202-
<VTextField
203-
v-model="notificationInfo.config.WECHAT_APP_ID"
204-
:label="t('notification.wechat.appId')"
205-
:hint="t('notification.wechat.appIdHint')"
206-
persistent-hint
207-
prepend-inner-icon="mdi-application"
208-
/>
209-
</VCol>
210-
<VCol cols="12" md="6">
211-
<VTextField
212-
v-model="notificationInfo.config.WECHAT_APP_SECRET"
213-
:label="t('notification.wechat.appSecret')"
214-
:hint="t('notification.wechat.appSecretHint')"
215-
persistent-hint
216-
prepend-inner-icon="mdi-key"
217-
/>
218-
</VCol>
219-
<VCol cols="12" md="6">
220-
<VTextField
221-
v-model="notificationInfo.config.WECHAT_PROXY"
222-
:label="t('notification.wechat.proxy')"
223-
:hint="t('notification.wechat.proxyHint')"
224-
persistent-hint
225-
prepend-inner-icon="mdi-server-network"
226-
/>
227-
</VCol>
228-
<VCol cols="12" md="6">
229-
<VTextField
230-
v-model="notificationInfo.config.WECHAT_TOKEN"
231-
:label="t('notification.wechat.token')"
232-
:hint="t('notification.wechat.tokenHint')"
233-
persistent-hint
234-
prepend-inner-icon="mdi-key-variant"
235-
/>
236-
</VCol>
237-
<VCol cols="12" md="6">
238-
<VTextField
239-
v-model="notificationInfo.config.WECHAT_ENCODING_AESKEY"
240-
:label="t('notification.wechat.encodingAesKey')"
241-
:hint="t('notification.wechat.encodingAesKeyHint')"
242-
persistent-hint
243-
prepend-inner-icon="mdi-lock"
244-
/>
245-
</VCol>
246-
<VCol cols="12" md="6">
247-
<VTextField
248-
v-model="notificationInfo.config.WECHAT_ADMINS"
249-
:label="t('notification.wechat.admins')"
250-
:placeholder="t('notification.wechat.adminsPlaceholder')"
251-
:hint="t('notification.wechat.adminsHint')"
252-
persistent-hint
253-
prepend-inner-icon="mdi-account-supervisor"
254-
/>
255-
</VCol>
223+
<VSwitch
224+
v-model="isWechatBotMode"
225+
:label="t('notification.wechat.useBotMode')"
226+
:hint="t('notification.wechat.useBotModeHint')"
227+
persistent-hint
228+
color="primary"
229+
/>
230+
</VCol>
231+
<template v-if="isWechatBotMode">
232+
<VCol cols="12" md="6">
233+
<VTextField
234+
v-model="notificationInfo.config.WECHAT_BOT_ID"
235+
:label="t('notification.wechat.botId')"
236+
:hint="t('notification.wechat.botIdHint')"
237+
persistent-hint
238+
prepend-inner-icon="mdi-robot"
239+
/>
240+
</VCol>
241+
<VCol cols="12" md="6">
242+
<VTextField
243+
v-model="notificationInfo.config.WECHAT_BOT_SECRET"
244+
:label="t('notification.wechat.botSecret')"
245+
:hint="t('notification.wechat.botSecretHint')"
246+
persistent-hint
247+
prepend-inner-icon="mdi-key"
248+
/>
249+
</VCol>
250+
<VCol cols="12" md="6">
251+
<VTextField
252+
v-model="notificationInfo.config.WECHAT_BOT_CHAT_ID"
253+
:label="t('notification.wechat.botChatId')"
254+
:placeholder="t('notification.wechat.botChatIdPlaceholder')"
255+
:hint="t('notification.wechat.botChatIdHint')"
256+
persistent-hint
257+
prepend-inner-icon="mdi-chat-processing"
258+
/>
259+
</VCol>
260+
<VCol cols="12" md="6">
261+
<VTextField
262+
v-model="notificationInfo.config.WECHAT_BOT_WS_URL"
263+
:label="t('notification.wechat.botWsUrl')"
264+
:hint="t('notification.wechat.botWsUrlHint')"
265+
persistent-hint
266+
prepend-inner-icon="mdi-lan-connect"
267+
/>
268+
</VCol>
269+
<VCol cols="12" md="6">
270+
<VTextField
271+
v-model="notificationInfo.config.WECHAT_ADMINS"
272+
:label="t('notification.wechat.admins')"
273+
:placeholder="t('notification.wechat.adminsPlaceholder')"
274+
:hint="t('notification.wechat.adminsHint')"
275+
persistent-hint
276+
prepend-inner-icon="mdi-account-supervisor"
277+
/>
278+
</VCol>
279+
</template>
280+
<template v-else>
281+
<VCol cols="12" md="6">
282+
<VTextField
283+
v-model="notificationInfo.config.WECHAT_CORPID"
284+
:label="t('notification.wechat.corpId')"
285+
:hint="t('notification.wechat.corpIdHint')"
286+
persistent-hint
287+
prepend-inner-icon="mdi-domain"
288+
/>
289+
</VCol>
290+
<VCol cols="12" md="6">
291+
<VTextField
292+
v-model="notificationInfo.config.WECHAT_APP_ID"
293+
:label="t('notification.wechat.appId')"
294+
:hint="t('notification.wechat.appIdHint')"
295+
persistent-hint
296+
prepend-inner-icon="mdi-application"
297+
/>
298+
</VCol>
299+
<VCol cols="12" md="6">
300+
<VTextField
301+
v-model="notificationInfo.config.WECHAT_APP_SECRET"
302+
:label="t('notification.wechat.appSecret')"
303+
:hint="t('notification.wechat.appSecretHint')"
304+
persistent-hint
305+
prepend-inner-icon="mdi-key"
306+
/>
307+
</VCol>
308+
<VCol cols="12" md="6">
309+
<VTextField
310+
v-model="notificationInfo.config.WECHAT_PROXY"
311+
:label="t('notification.wechat.proxy')"
312+
:hint="t('notification.wechat.proxyHint')"
313+
persistent-hint
314+
prepend-inner-icon="mdi-server-network"
315+
/>
316+
</VCol>
317+
<VCol cols="12" md="6">
318+
<VTextField
319+
v-model="notificationInfo.config.WECHAT_TOKEN"
320+
:label="t('notification.wechat.token')"
321+
:hint="t('notification.wechat.tokenHint')"
322+
persistent-hint
323+
prepend-inner-icon="mdi-key-variant"
324+
/>
325+
</VCol>
326+
<VCol cols="12" md="6">
327+
<VTextField
328+
v-model="notificationInfo.config.WECHAT_ENCODING_AESKEY"
329+
:label="t('notification.wechat.encodingAesKey')"
330+
:hint="t('notification.wechat.encodingAesKeyHint')"
331+
persistent-hint
332+
prepend-inner-icon="mdi-lock"
333+
/>
334+
</VCol>
335+
<VCol cols="12" md="6">
336+
<VTextField
337+
v-model="notificationInfo.config.WECHAT_ADMINS"
338+
:label="t('notification.wechat.admins')"
339+
:placeholder="t('notification.wechat.adminsPlaceholder')"
340+
:hint="t('notification.wechat.adminsHint')"
341+
persistent-hint
342+
prepend-inner-icon="mdi-account-supervisor"
343+
/>
344+
</VCol>
345+
</template>
256346
</VRow>
257347
<VRow v-else-if="notificationInfo.type == 'telegram'">
258348
<VCol cols="12" md="6">

src/locales/en-US.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ export default {
435435
config: 'Configuration',
436436
wechat: {
437437
name: 'WeChat Work',
438+
useBotMode: 'Use AI Bot',
439+
useBotModeHint: 'Enable WebSocket bot mode with fixed dmPolicy=open and groupPolicy=disabled',
438440
corpId: 'Corp ID',
439441
corpIdHint: 'Corp ID in WeChat Work backend enterprise information',
440442
corpIdRequired: 'Corp ID cannot be empty',
@@ -451,6 +453,15 @@ export default {
451453
tokenHint: 'Token in WeChat Work self-built app -> API message receiving configuration',
452454
encodingAesKey: 'EncodingAESKey',
453455
encodingAesKeyHint: 'EncodingAESKey in WeChat Work self-built app -> API message receiving configuration',
456+
botId: 'Bot ID',
457+
botIdHint: 'Bot ID of the WeChat Work AI bot',
458+
botSecret: 'Bot Secret',
459+
botSecretHint: 'WebSocket secret of the WeChat Work AI bot',
460+
botChatId: 'Default Target',
461+
botChatIdHint: 'Use user userid; for proactive group messages use group:chatid. Leave empty to notify known interacted users',
462+
botChatIdPlaceholder: 'userid or group:chatid',
463+
botWsUrl: 'WebSocket URL',
464+
botWsUrlHint: 'WebSocket endpoint for the WeChat Work AI bot, usually the default value',
454465
admins: 'Admin Whitelist',
455466
adminsHint: 'User IDs that can use admin menu and commands, separated by commas',
456467
adminsPlaceholder: 'User IDs list, separated by commas',

src/locales/zh-CN.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ export default {
433433
config: '配置',
434434
wechat: {
435435
name: '企业微信',
436+
useBotMode: '使用智能机器人',
437+
useBotModeHint: '开启后使用智能机器人长连接,固定 dmPolicy=open、groupPolicy=disabled',
436438
corpId: '企业ID',
437439
corpIdHint: '企业微信后台企业信息中的企业ID',
438440
corpIdRequired: '企业ID不能为空',
@@ -448,6 +450,15 @@ export default {
448450
tokenHint: '微信企业自建应用->API接收消息配置中的Token',
449451
encodingAesKey: 'EncodingAESKey',
450452
encodingAesKeyHint: '微信企业自建应用->API接收消息配置中的EncodingAESKey',
453+
botId: '机器人 BotID',
454+
botIdHint: '企业微信智能机器人的 BotID',
455+
botSecret: '机器人 Secret',
456+
botSecretHint: '企业微信智能机器人长连接专用 Secret',
457+
botChatId: '默认通知目标',
458+
botChatIdHint: '可填写用户 userid;如需主动发群消息可填写 group:群聊chatid,不填则默认发给已互动用户',
459+
botChatIdPlaceholder: 'userid 或 group:chatid',
460+
botWsUrl: '长连接地址',
461+
botWsUrlHint: '企业微信智能机器人 WebSocket 地址,通常使用默认值',
451462
admins: '管理员白名单',
452463
adminsHint: '可使用管理菜单及命令的用户ID列表,多个ID使用,分隔',
453464
adminsPlaceholder: '用户ID列表,多个ID使用,分隔',

src/locales/zh-TW.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ export default {
433433
config: '配置',
434434
wechat: {
435435
name: '企業微信',
436+
useBotMode: '使用智能機器人',
437+
useBotModeHint: '開啟後使用智能機器人長連線,固定 dmPolicy=open、groupPolicy=disabled',
436438
corpId: '企業ID',
437439
corpIdHint: '企業微信後台企業信息中的企業ID',
438440
corpIdRequired: '企業ID不能為空',
@@ -448,6 +450,15 @@ export default {
448450
tokenHint: '微信企業自建應用->API接收消息配置中的Token',
449451
encodingAesKey: 'EncodingAESKey',
450452
encodingAesKeyHint: '微信企業自建應用->API接收消息配置中的EncodingAESKey',
453+
botId: '機器人 BotID',
454+
botIdHint: '企業微信智能機器人的 BotID',
455+
botSecret: '機器人 Secret',
456+
botSecretHint: '企業微信智能機器人長連線專用 Secret',
457+
botChatId: '預設通知目標',
458+
botChatIdHint: '可填寫使用者 userid;如需主動發群消息可填寫 group:群聊chatid,不填則預設發給已互動使用者',
459+
botChatIdPlaceholder: 'userid 或 group:chatid',
460+
botWsUrl: '長連線地址',
461+
botWsUrlHint: '企業微信智能機器人 WebSocket 位址,通常使用預設值',
451462
admins: '管理員白名單',
452463
adminsHint: '可使用管理菜單及命令的用戶ID列表,多個ID使用,分隔',
453464
adminsPlaceholder: '用戶ID列表,多個ID使用,分隔',

0 commit comments

Comments
 (0)