Skip to content

Commit fad0309

Browse files
feat: update hermes qq wecom channel config
1 parent 02bd500 commit fad0309

12 files changed

Lines changed: 95 additions & 30 deletions

File tree

agent/app/service/agents_hermes_channels.go

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"path"
55

66
"github.com/1Panel-dev/1Panel/agent/app/dto"
7+
"github.com/1Panel-dev/1Panel/agent/buserr"
78
)
89

910
const hermesWeixinLoginScript = `import asyncio
@@ -51,11 +52,17 @@ func readHermesQQBotChannelConfig(confDir string) (*dto.AgentQQBotConfig, error)
5152
dmPolicy = "open"
5253
}
5354
allowFrom := extractStringList(extra["allow_from"])
55+
if len(allowFrom) == 0 {
56+
allowFrom = splitHermesEnvList(envMap["QQ_ALLOWED_USERS"])
57+
}
5458
groupPolicy := extractStringValue(extra["group_policy"])
5559
if groupPolicy == "" {
5660
groupPolicy = "open"
5761
}
5862
groupAllowFrom := extractStringList(extra["group_allow_from"])
63+
if len(groupAllowFrom) == 0 {
64+
groupAllowFrom = splitHermesEnvList(envMap["QQ_GROUP_ALLOWED_USERS"])
65+
}
5966

6067
result := &dto.AgentQQBotConfig{
6168
Enabled: extractBoolValue(platform["enabled"], false) && appID != "" && clientSecret != "",
@@ -92,15 +99,27 @@ func writeHermesQQBotChannelConfig(confDir string, config dto.AgentQQBotConfig)
9299
envMap["QQ_APP_ID"] = defaultBot.AppID
93100
envMap["QQ_CLIENT_SECRET"] = defaultBot.ClientSecret
94101
delete(envMap, "QQ_ALLOWED_USERS")
102+
delete(envMap, "QQ_GROUP_ALLOWED_USERS")
95103
delete(envMap, "QQ_ALLOW_ALL_USERS")
96104
delete(envMap, "QQ_MARKDOWN_SUPPORT")
97105
if config.DmPolicy == "open" {
98106
envMap["QQ_ALLOW_ALL_USERS"] = "true"
107+
} else if config.DmPolicy == "allowlist" {
108+
if allow := joinHermesEnvList(config.AllowFrom); allow != "" {
109+
envMap["QQ_ALLOWED_USERS"] = allow
110+
}
111+
}
112+
if config.GroupPolicy == "allowlist" {
113+
if allow := joinHermesEnvList(config.GroupAllowFrom); allow != "" {
114+
envMap["QQ_GROUP_ALLOWED_USERS"] = allow
115+
}
99116
}
100117
if err := writeHermesEnvMap(envPath, envMap, []string{
101118
"QQ_APP_ID",
102119
"QQ_CLIENT_SECRET",
103120
"QQ_ALLOW_ALL_USERS",
121+
"QQ_ALLOWED_USERS",
122+
"QQ_GROUP_ALLOWED_USERS",
104123
"QQ_HOME_CHANNEL",
105124
"QQ_HOME_CHANNEL_NAME",
106125
"QQ_STT_API_KEY",
@@ -171,15 +190,18 @@ func readHermesWecomChannelConfig(confDir string) (*dto.AgentWecomConfig, error)
171190
allowFrom = splitHermesEnvList(envMap["WECOM_ALLOWED_USERS"])
172191
}
173192
groupAllowFrom := extractStringList(extra["group_allow_from"])
193+
if len(groupAllowFrom) == 0 {
194+
groupAllowFrom = splitHermesEnvList(envMap["WECOM_GROUP_ALLOWED_USERS"])
195+
}
174196
dmPolicy := "pairing"
175-
if extractHermesEnvBool(envMap, "WECOM_ALLOW_ALL_USERS", false) {
197+
if envMap["WECOM_DM_POLICY"] == "open" || extractHermesEnvBool(envMap, "WECOM_ALLOW_ALL_USERS", false) {
176198
dmPolicy = "open"
177199
} else if len(allowFrom) > 0 {
178200
dmPolicy = "allowlist"
179-
} else if policy := extractStringValue(extra["dm_policy"]); policy != "" {
201+
} else if policy := firstHermesEnvValue(envMap, "WECOM_DM_POLICY", extractStringValue(extra["dm_policy"])); policy != "" {
180202
dmPolicy = policy
181203
}
182-
groupPolicy := extractStringValue(extra["group_policy"])
204+
groupPolicy := firstHermesEnvValue(envMap, "WECOM_GROUP_POLICY", extractStringValue(extra["group_policy"]))
183205
if groupPolicy == "" {
184206
groupPolicy = "open"
185207
}
@@ -215,22 +237,33 @@ func writeHermesWecomChannelConfig(confDir string, config dto.AgentWecomConfig)
215237
delete(envMap, "WECOM_SECRET")
216238
}
217239
delete(envMap, "WECOM_ALLOWED_USERS")
240+
delete(envMap, "WECOM_GROUP_ALLOWED_USERS")
218241
delete(envMap, "WECOM_ALLOW_ALL_USERS")
219242
delete(envMap, "WECOM_DM_POLICY")
220243
delete(envMap, "WECOM_GROUP_POLICY")
221-
switch config.DmPolicy {
222-
case "open":
223-
envMap["WECOM_ALLOW_ALL_USERS"] = "true"
224-
case "allowlist":
244+
if config.DmPolicy != "" {
245+
envMap["WECOM_DM_POLICY"] = config.DmPolicy
246+
}
247+
if config.GroupPolicy != "" {
248+
envMap["WECOM_GROUP_POLICY"] = config.GroupPolicy
249+
}
250+
if config.DmPolicy == "allowlist" {
225251
if allow := joinHermesEnvList(config.AllowFrom); allow != "" {
226252
envMap["WECOM_ALLOWED_USERS"] = allow
227253
}
228254
}
255+
if config.GroupPolicy == "allowlist" {
256+
if allow := joinHermesEnvList(config.GroupAllowFrom); allow != "" {
257+
envMap["WECOM_GROUP_ALLOWED_USERS"] = allow
258+
}
259+
}
229260
if err := writeHermesEnvMap(envPath, envMap, []string{
230261
"WECOM_BOT_ID",
231262
"WECOM_SECRET",
232-
"WECOM_ALLOW_ALL_USERS",
263+
"WECOM_DM_POLICY",
233264
"WECOM_ALLOWED_USERS",
265+
"WECOM_GROUP_POLICY",
266+
"WECOM_GROUP_ALLOWED_USERS",
234267
}); err != nil {
235268
return err
236269
}
@@ -264,8 +297,10 @@ func deleteHermesWecomChannelConfig(confDir string) error {
264297
if err := deleteHermesEnvKeys(confDir,
265298
"WECOM_BOT_ID",
266299
"WECOM_SECRET",
267-
"WECOM_ALLOW_ALL_USERS",
300+
"WECOM_DM_POLICY",
268301
"WECOM_ALLOWED_USERS",
302+
"WECOM_GROUP_POLICY",
303+
"WECOM_GROUP_ALLOWED_USERS",
269304
"WECOM_HOME_CHANNEL",
270305
); err != nil {
271306
return err
@@ -448,6 +483,9 @@ func writeHermesFeishuChannelConfig(confDir string, config dto.AgentFeishuConfig
448483
return err
449484
}
450485
bot := firstHermesFeishuBot(config.Bots)
486+
if config.GroupPolicy == "allowlist" && bot.DmPolicy == "pairing" {
487+
return buserr.New("ErrHermesFeishuGroupAllowlistRequiresAllowlist")
488+
}
451489
if bot.AppID != "" {
452490
envMap["FEISHU_APP_ID"] = bot.AppID
453491
} else {
@@ -471,6 +509,11 @@ func writeHermesFeishuChannelConfig(confDir string, config dto.AgentFeishuConfig
471509
envMap["FEISHU_ALLOWED_USERS"] = allow
472510
}
473511
}
512+
if config.GroupPolicy == "allowlist" {
513+
if allow := joinHermesEnvList(bot.AllowFrom); allow != "" {
514+
envMap["FEISHU_ALLOWED_USERS"] = allow
515+
}
516+
}
474517
if err := writeHermesEnvMap(envPath, envMap, []string{
475518
"FEISHU_APP_ID",
476519
"FEISHU_APP_SECRET",

agent/i18n/lang/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ ErrAgentWebsiteTypeUnsupported: 'Only proxy or static websites can be bound'
6666
ErrAgentWebsiteInUse: 'This website is already bound to another agent'
6767
ErrAgentWebsiteUnbindUnsupported: 'Deployment websites cannot be unbound manually'
6868
ErrHermesPairingCodeUnavailable: 'The pairing code is temporarily unavailable in Hermes, possibly due to network issues. Please try again later.'
69+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'When the Feishu group policy is Allowlist, the DM policy cannot be Pairing Code.'
6970

7071
#backup
7172
Localhost: 'Local'

agent/i18n/lang/es-ES.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: 'Solo se pueden vincular sitios proxy o estátic
6161
ErrAgentWebsiteInUse: 'Este sitio web ya está vinculado a otro agente'
6262
ErrAgentWebsiteUnbindUnsupported: 'Los sitios web de despliegue no se pueden desvincular manualmente'
6363
ErrHermesPairingCodeUnavailable: 'El código de emparejamiento no está disponible temporalmente en Hermes, posiblemente por un problema de red. Inténtalo de nuevo más tarde.'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'Cuando la política de grupo de Feishu es Lista permitida, la política de MD no puede ser Código de emparejamiento.'
6465
Localhost: 'Máquina local'
6566
ErrBackupInUsed: 'Cuenta de respaldo en uso por tarea programada'
6667
ErrBackupCheck: 'Conexión de respaldo falló: {{ .err }}'

agent/i18n/lang/ja.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: '関連付けできるのはプロキシサイ
6161
ErrAgentWebsiteInUse: 'このサイトはすでに別のエージェントに関連付けられています'
6262
ErrAgentWebsiteUnbindUnsupported: 'ワンクリックデプロイのサイトは手動で関連解除できません'
6363
ErrHermesPairingCodeUnavailable: 'Hermes でペアリングコードが一時的に見つかりません。ネットワーク要因の可能性があるため、しばらくしてから再試行してください。'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'Feishu のグループポリシーが許可リストの場合、DM ポリシーをペアリングコードにはできません。'
6465
Localhost: 'ローカルマシン'
6566
ErrBackupInUsed: 'バックアップアカウントがスケジュールで使用中'
6667
ErrBackupCheck: '接続テストに失敗しました: {{ .err }}'

agent/i18n/lang/ko.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: '프록시 또는 정적 웹사이트만 연결
6161
ErrAgentWebsiteInUse: '이 웹사이트는 이미 다른 에이전트에 연결되어 있습니다'
6262
ErrAgentWebsiteUnbindUnsupported: '원클릭 배포 웹사이트는 수동으로 연결 해제할 수 없습니다'
6363
ErrHermesPairingCodeUnavailable: 'Hermes에서 페어링 코드가 일시적으로 존재하지 않습니다. 네트워크 문제일 수 있으니 잠시 후 다시 시도해 주세요.'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'Feishu 그룹 정책이 허용 목록이면 DM 정책을 페어링 코드로 설정할 수 없습니다.'
6465
Localhost: '로컬 머신'
6566
ErrBackupInUsed: '백업 계정이 예약에 사용 중'
6667
ErrBackupCheck: '연결 테스트 실패: {{ .err }}'

agent/i18n/lang/ms.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: 'Hanya laman web proxy atau statik boleh dipautk
6161
ErrAgentWebsiteInUse: 'Laman web ini sudah dipautkan ke ejen lain'
6262
ErrAgentWebsiteUnbindUnsupported: 'Laman web one-click deployment tidak menyokong nyahikat manual'
6363
ErrHermesPairingCodeUnavailable: 'Kod pasangan buat sementara waktu tidak wujud dalam Hermes, mungkin disebabkan masalah rangkaian. Sila cuba lagi sebentar nanti.'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'Apabila dasar kumpulan Feishu ialah senarai benarkan, dasar DM tidak boleh menggunakan kod pasangan.'
6465
Localhost: 'Mesin Tempatan'
6566
ErrBackupInUsed: 'Akaun sandaran sedang digunakan oleh tugas'
6667
ErrBackupCheck: 'Ujian sambungan gagal: {{ .err }}'

agent/i18n/lang/pt-BR.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: 'Somente sites proxy ou estáticos podem ser vin
6161
ErrAgentWebsiteInUse: 'Este site já está vinculado a outro agente'
6262
ErrAgentWebsiteUnbindUnsupported: 'Sites implantados em um clique não podem ser desvinculados manualmente'
6363
ErrHermesPairingCodeUnavailable: 'O código de pareamento está temporariamente indisponível no Hermes, possivelmente por causa de rede. Tente novamente mais tarde.'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'Quando a política de grupo do Feishu é Lista de permissões, a política de DM não pode ser Código de pareamento.'
6465
Localhost: 'Máquina Local'
6566
ErrBackupInUsed: 'Conta de backup em uso por tarefa'
6667
ErrBackupCheck: 'Teste de conexão falhou: {{ .err }}'

agent/i18n/lang/ru.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: 'Можно связывать только prox
6161
ErrAgentWebsiteInUse: 'Этот сайт уже связан с другим агентом'
6262
ErrAgentWebsiteUnbindUnsupported: 'Сайты one-click deployment нельзя отвязать вручную'
6363
ErrHermesPairingCodeUnavailable: 'Код сопряжения временно недоступен в Hermes, возможно из-за проблем с сетью. Повторите попытку позже.'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'Когда групповая политика Feishu — белый список, политика личных сообщений не может быть кодом сопряжения.'
6465
Localhost: 'Локальная машина'
6566
ErrBackupInUsed: 'Аккаунт бэкапа занят задачей'
6667
ErrBackupCheck: 'Проверка подключения не удалась: {{ .err }}'

agent/i18n/lang/tr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: 'Yalnızca proxy veya statik web siteleri bağla
6161
ErrAgentWebsiteInUse: 'Bu web sitesi zaten başka bir ajana bağlı'
6262
ErrAgentWebsiteUnbindUnsupported: 'Tek tıkla dağıtılan web sitelerinin bağlantısı manuel olarak kaldırılamaz'
6363
ErrHermesPairingCodeUnavailable: 'Eşleştirme kodu Hermes içinde geçici olarak bulunamıyor; bu durum ağ kaynaklı olabilir. Lütfen daha sonra tekrar deneyin.'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: 'Feishu grup ilkesi izin listesi olduğunda, DM ilkesi eşleştirme kodu olamaz.'
6465
Localhost: 'Yerel Makine'
6566
ErrBackupInUsed: 'Yedek hesabı görevde kullanılıyor'
6667
ErrBackupCheck: 'Bağlantı testi başarısız: {{ .err }}'

agent/i18n/lang/zh-Hant.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ErrAgentWebsiteTypeUnsupported: '只能關聯反向代理或靜態網站'
6161
ErrAgentWebsiteInUse: '該網站已被其他智能體關聯'
6262
ErrAgentWebsiteUnbindUnsupported: '一鍵部署網站不支援手動解綁'
6363
ErrHermesPairingCodeUnavailable: '配對碼在 Hermes 中暫時不存在,可能是由於網路原因,請稍後再試'
64+
ErrHermesFeishuGroupAllowlistRequiresAllowlist: '飛書群組策略為白名單時,私聊策略不能為配對碼'
6465
Localhost: '本機'
6566
ErrBackupInUsed: '此備份帳號已在排程任務中使用,無法刪除'
6667
ErrBackupCheck: '備份帳號測試連線失敗{{ .err }}'

0 commit comments

Comments
 (0)