Skip to content

Commit a714d5a

Browse files
feat: update hermes qq wecom channel config (#12555)
1 parent 4f97a78 commit a714d5a

12 files changed

Lines changed: 91 additions & 37 deletions

File tree

agent/app/service/agents_hermes_channels.go

Lines changed: 48 additions & 16 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
@@ -50,12 +51,12 @@ func readHermesQQBotChannelConfig(confDir string) (*dto.AgentQQBotConfig, error)
5051
if dmPolicy == "" {
5152
dmPolicy = "open"
5253
}
53-
allowFrom := extractStringList(extra["allow_from"])
54+
allowFrom := splitHermesEnvList(envMap["QQ_ALLOWED_USERS"])
5455
groupPolicy := extractStringValue(extra["group_policy"])
5556
if groupPolicy == "" {
5657
groupPolicy = "open"
5758
}
58-
groupAllowFrom := extractStringList(extra["group_allow_from"])
59+
groupAllowFrom := splitHermesEnvList(envMap["QQ_GROUP_ALLOWED_USERS"])
5960

6061
result := &dto.AgentQQBotConfig{
6162
Enabled: extractBoolValue(platform["enabled"], false) && appID != "" && clientSecret != "",
@@ -92,15 +93,27 @@ func writeHermesQQBotChannelConfig(confDir string, config dto.AgentQQBotConfig)
9293
envMap["QQ_APP_ID"] = defaultBot.AppID
9394
envMap["QQ_CLIENT_SECRET"] = defaultBot.ClientSecret
9495
delete(envMap, "QQ_ALLOWED_USERS")
96+
delete(envMap, "QQ_GROUP_ALLOWED_USERS")
9597
delete(envMap, "QQ_ALLOW_ALL_USERS")
9698
delete(envMap, "QQ_MARKDOWN_SUPPORT")
9799
if config.DmPolicy == "open" {
98100
envMap["QQ_ALLOW_ALL_USERS"] = "true"
101+
} else if config.DmPolicy == "allowlist" {
102+
if allow := joinHermesEnvList(config.AllowFrom); allow != "" {
103+
envMap["QQ_ALLOWED_USERS"] = allow
104+
}
105+
}
106+
if config.GroupPolicy == "allowlist" {
107+
if allow := joinHermesEnvList(config.GroupAllowFrom); allow != "" {
108+
envMap["QQ_GROUP_ALLOWED_USERS"] = allow
109+
}
99110
}
100111
if err := writeHermesEnvMap(envPath, envMap, []string{
101112
"QQ_APP_ID",
102113
"QQ_CLIENT_SECRET",
103114
"QQ_ALLOW_ALL_USERS",
115+
"QQ_ALLOWED_USERS",
116+
"QQ_GROUP_ALLOWED_USERS",
104117
"QQ_HOME_CHANNEL",
105118
"QQ_HOME_CHANNEL_NAME",
106119
"QQ_STT_API_KEY",
@@ -143,6 +156,7 @@ func deleteHermesQQBotChannelConfig(confDir string) error {
143156
"QQ_CLIENT_SECRET",
144157
"QQ_ALLOW_ALL_USERS",
145158
"QQ_ALLOWED_USERS",
159+
"QQ_GROUP_ALLOWED_USERS",
146160
"QQ_HOME_CHANNEL",
147161
"QQ_HOME_CHANNEL_NAME",
148162
"QQ_STT_API_KEY",
@@ -165,21 +179,17 @@ func readHermesWecomChannelConfig(confDir string) (*dto.AgentWecomConfig, error)
165179
}
166180

167181
platform := childMap(childMap(cfg, "platforms"), "wecom")
168-
extra := childMap(platform, "extra")
169-
allowFrom := extractStringList(extra["allow_from"])
170-
if len(allowFrom) == 0 {
171-
allowFrom = splitHermesEnvList(envMap["WECOM_ALLOWED_USERS"])
172-
}
173-
groupAllowFrom := extractStringList(extra["group_allow_from"])
182+
allowFrom := splitHermesEnvList(envMap["WECOM_ALLOWED_USERS"])
183+
groupAllowFrom := splitHermesEnvList(envMap["WECOM_GROUP_ALLOWED_USERS"])
174184
dmPolicy := "pairing"
175-
if extractHermesEnvBool(envMap, "WECOM_ALLOW_ALL_USERS", false) {
185+
if envMap["WECOM_DM_POLICY"] == "open" {
176186
dmPolicy = "open"
177187
} else if len(allowFrom) > 0 {
178188
dmPolicy = "allowlist"
179-
} else if policy := extractStringValue(extra["dm_policy"]); policy != "" {
189+
} else if policy := envMap["WECOM_DM_POLICY"]; policy != "" {
180190
dmPolicy = policy
181191
}
182-
groupPolicy := extractStringValue(extra["group_policy"])
192+
groupPolicy := envMap["WECOM_GROUP_POLICY"]
183193
if groupPolicy == "" {
184194
groupPolicy = "open"
185195
}
@@ -215,22 +225,33 @@ func writeHermesWecomChannelConfig(confDir string, config dto.AgentWecomConfig)
215225
delete(envMap, "WECOM_SECRET")
216226
}
217227
delete(envMap, "WECOM_ALLOWED_USERS")
228+
delete(envMap, "WECOM_GROUP_ALLOWED_USERS")
218229
delete(envMap, "WECOM_ALLOW_ALL_USERS")
219230
delete(envMap, "WECOM_DM_POLICY")
220231
delete(envMap, "WECOM_GROUP_POLICY")
221-
switch config.DmPolicy {
222-
case "open":
223-
envMap["WECOM_ALLOW_ALL_USERS"] = "true"
224-
case "allowlist":
232+
if config.DmPolicy != "" {
233+
envMap["WECOM_DM_POLICY"] = config.DmPolicy
234+
}
235+
if config.GroupPolicy != "" {
236+
envMap["WECOM_GROUP_POLICY"] = config.GroupPolicy
237+
}
238+
if config.DmPolicy == "allowlist" {
225239
if allow := joinHermesEnvList(config.AllowFrom); allow != "" {
226240
envMap["WECOM_ALLOWED_USERS"] = allow
227241
}
228242
}
243+
if config.GroupPolicy == "allowlist" {
244+
if allow := joinHermesEnvList(config.GroupAllowFrom); allow != "" {
245+
envMap["WECOM_GROUP_ALLOWED_USERS"] = allow
246+
}
247+
}
229248
if err := writeHermesEnvMap(envPath, envMap, []string{
230249
"WECOM_BOT_ID",
231250
"WECOM_SECRET",
232-
"WECOM_ALLOW_ALL_USERS",
251+
"WECOM_DM_POLICY",
233252
"WECOM_ALLOWED_USERS",
253+
"WECOM_GROUP_POLICY",
254+
"WECOM_GROUP_ALLOWED_USERS",
234255
}); err != nil {
235256
return err
236257
}
@@ -265,7 +286,10 @@ func deleteHermesWecomChannelConfig(confDir string) error {
265286
"WECOM_BOT_ID",
266287
"WECOM_SECRET",
267288
"WECOM_ALLOW_ALL_USERS",
289+
"WECOM_DM_POLICY",
268290
"WECOM_ALLOWED_USERS",
291+
"WECOM_GROUP_POLICY",
292+
"WECOM_GROUP_ALLOWED_USERS",
269293
"WECOM_HOME_CHANNEL",
270294
); err != nil {
271295
return err
@@ -448,6 +472,9 @@ func writeHermesFeishuChannelConfig(confDir string, config dto.AgentFeishuConfig
448472
return err
449473
}
450474
bot := firstHermesFeishuBot(config.Bots)
475+
if config.GroupPolicy == "allowlist" && bot.DmPolicy == "pairing" {
476+
return buserr.New("ErrHermesFeishuGroupAllowlistRequiresAllowlist")
477+
}
451478
if bot.AppID != "" {
452479
envMap["FEISHU_APP_ID"] = bot.AppID
453480
} else {
@@ -471,6 +498,11 @@ func writeHermesFeishuChannelConfig(confDir string, config dto.AgentFeishuConfig
471498
envMap["FEISHU_ALLOWED_USERS"] = allow
472499
}
473500
}
501+
if config.GroupPolicy == "allowlist" {
502+
if allow := joinHermesEnvList(bot.AllowFrom); allow != "" {
503+
envMap["FEISHU_ALLOWED_USERS"] = allow
504+
}
505+
}
474506
if err := writeHermesEnvMap(envPath, envMap, []string{
475507
"FEISHU_APP_ID",
476508
"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)