Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ai
/
ai-workflow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3c4e1142
authored
May 25, 2026
by
sunqi02
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
更新企微消息发送请求的构建
1 parent
9d4f1051
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
5 deletions
workspace/agent-admin/backend/app/api/v1/endpoints/agent_hub.py
workspace/agent-admin/backend/app/service/console_im_service.py
workspace/agent-admin/backend/app/service/im_service.py
workspace/agent-admin/backend/config/settings.json
workspace/agent-admin/backend/app/api/v1/endpoints/agent_hub.py
View file @
3c4e114
...
...
@@ -87,8 +87,9 @@ async def chat(
# 2. 提取 user_id:取最后一条消息的 sender_id
user_id
=
request
.
messages
[
-
1
]
.
sender_id
# 3. 提取 allowed_agent_codes
:agent_id → 内部 agent code 映射
# 3. 提取 allowed_agent_codes
和 bot_id_mapping
allowed_agent_codes
:
Optional
[
list
]
=
None
bot_id_mapping
:
dict
=
{}
if
request
.
agents
:
# 构建 agent.code → 内部名称(dict key)映射
code_to_name
=
{
...
...
@@ -100,6 +101,9 @@ async def chat(
internal_name
=
code_to_name
.
get
(
agent_code_str
)
if
internal_name
and
internal_name
!=
"main"
:
allowed_agent_codes
.
append
(
internal_name
)
# 提取 bot_id 映射:{internal_agent_name: bot_id}
if
internal_name
and
agent_info
.
bot_id
:
bot_id_mapping
[
internal_name
]
=
agent_info
.
bot_id
if
not
allowed_agent_codes
:
allowed_agent_codes
=
None
# 无有效子 agent,走默认路由
...
...
@@ -113,6 +117,7 @@ async def chat(
user_query
=
query
,
file_url
=
file_url
,
allowed_agent_codes
=
allowed_agent_codes
,
bot_id_mapping
=
bot_id_mapping
,
)
return
{
"status"
:
"ok"
,
"session_id"
:
session_id
}
...
...
@@ -126,6 +131,7 @@ async def _process_message_async(
user_query
:
str
,
file_url
:
Optional
[
str
],
allowed_agent_codes
:
Optional
[
list
],
bot_id_mapping
:
Optional
[
dict
]
=
None
,
):
"""后台执行 Agent 处理流程,异常不影响 HTTP 响应。"""
try
:
...
...
@@ -136,6 +142,7 @@ async def _process_message_async(
user_query
=
user_query
,
file_url
=
file_url
,
allowed_agent_codes
=
allowed_agent_codes
,
bot_id_mapping
=
bot_id_mapping
,
)
except
Exception
:
logger
.
exception
(
...
...
workspace/agent-admin/backend/app/service/console_im_service.py
View file @
3c4e114
"""Console IM service — prints hook output instead of sending to real IM."""
import
json
import
time
from
typing
import
Dict
,
Any
,
Optional
...
...
@@ -21,6 +22,7 @@ class ConsoleIMService:
"content"
:
content
,
"contact_id"
:
contact_id
,
"msg_type"
:
"text"
,
"biz_rela_no"
:
f
"biz-msg-{int(time.time() * 1000)}"
,
}
if
at_list
:
payload
[
"at_list"
]
=
at_list
...
...
workspace/agent-admin/backend/app/service/im_service.py
View file @
3c4e114
import
time
from
typing
import
Dict
,
Any
,
Optional
import
httpx
...
...
@@ -45,6 +46,7 @@ class IMService:
"content"
:
content
,
"bot_id"
:
bot_id
,
"msg_type"
:
"text"
,
"biz_rela_no"
:
f
"biz-msg-{int(time.time() * 1000)}"
,
}
if
at_list
:
payload
[
"at_list"
]
=
at_list
...
...
@@ -53,14 +55,20 @@ class IMService:
if
self
.
api_key
:
headers
[
"X-Api-Key"
]
=
self
.
api_key
url
=
f
"{self.base_url}/api/v1/business/messages/send"
print
(
f
"
\n
[IM] 调用: {url}"
)
print
(
f
"[IM] 请求体: {payload}
\n
"
)
try
:
response
=
await
self
.
client
.
post
(
f
"{self.base_url}/api/v1/business/messages/send"
,
url
,
json
=
payload
,
headers
=
headers
)
response
.
raise_for_status
()
return
response
.
json
()
result
=
response
.
json
()
print
(
f
"[IM] 响应: {result}
\n
"
)
return
result
except
httpx
.
HTTPStatusError
as
e
:
raise
IMServiceError
(
f
"IM服务返回错误: {e.response.status_code} - {e.response.text}"
)
except
httpx
.
RequestError
as
e
:
...
...
workspace/agent-admin/backend/config/settings.json
View file @
3c4e114
...
...
@@ -8,8 +8,8 @@
"base_path"
:
""
},
"im"
:
{
"use_console"
:
tru
e
,
"base_url"
:
"http://
0.0.0.0:8080
"
,
"use_console"
:
fals
e
,
"base_url"
:
"http://
yjy.dev.glsx.com.cn/webim
"
,
"api_key"
:
""
},
"wecom_sync"
:
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment