Skip to content

Commit 2a27568

Browse files
Enhance: tools wecom bot support markdown message (langgenius#5791)
1 parent 1d3e96f commit 2a27568

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

api/core/tools/provider/builtin/wecom/tools/wecom_group_bot.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,28 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]
2222
return self.create_text_message(
2323
f'Invalid parameter hook_key ${hook_key}, not a valid UUID')
2424

25-
msgtype = 'text'
25+
message_type = tool_parameters.get('message_type', 'text')
26+
if message_type == 'markdown':
27+
payload = {
28+
"msgtype": 'markdown',
29+
"markdown": {
30+
"content": content,
31+
}
32+
}
33+
else:
34+
payload = {
35+
"msgtype": 'text',
36+
"text": {
37+
"content": content,
38+
}
39+
}
2640
api_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send'
2741
headers = {
2842
'Content-Type': 'application/json',
2943
}
3044
params = {
3145
'key': hook_key,
3246
}
33-
payload = {
34-
"msgtype": msgtype,
35-
"text": {
36-
"content": content,
37-
}
38-
}
3947

4048
try:
4149
res = httpx.post(api_url, headers=headers, params=params, json=payload)

api/core/tools/provider/builtin/wecom/tools/wecom_group_bot.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,27 @@ parameters:
3838
pt_BR: Content to sent to the group.
3939
llm_description: Content of the message
4040
form: llm
41+
- name: message_type
42+
type: select
43+
default: text
44+
required: true
45+
label:
46+
en_US: Wecom Group bot message type
47+
zh_Hans: 群机器人webhook的消息类型
48+
pt_BR: Wecom Group bot message type
49+
human_description:
50+
en_US: Wecom Group bot message type
51+
zh_Hans: 群机器人webhook的消息类型
52+
pt_BR: Wecom Group bot message type
53+
options:
54+
- value: text
55+
label:
56+
en_US: Text
57+
zh_Hans: 文本
58+
pt_BR: Text
59+
- value: markdown
60+
label:
61+
en_US: Markdown
62+
zh_Hans: Markdown
63+
pt_BR: Markdown
64+
form: form

0 commit comments

Comments
 (0)