Skip to content

Commit 3b6638c

Browse files
authored
Merge pull request #34 from funcodingdev/dev/update
Dev/update
2 parents 4c69c97 + d5c1014 commit 3b6638c

9 files changed

Lines changed: 465 additions & 90 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ npm install n8n-nodes-wecom
321321
-[获取群聊会话信息](https://developer.work.weixin.qq.com/document/path/98914)
322322
-[修改群聊会话](https://developer.work.weixin.qq.com/document/path/98913)
323323
-[发送消息到群聊](https://developer.work.weixin.qq.com/document/path/90248)
324-
- 发送文本消息到群聊
324+
- 发送文本消息到群聊(支持 `@群成员` / `@所有人`
325325
- 发送图片消息到群聊
326326
- 发送文件消息到群聊
327327
- 发送 Markdown 消息到群聊
@@ -625,6 +625,7 @@ npm install n8n-nodes-wecom
625625
-[添加记录](https://developer.work.weixin.qq.com/document/path/99907)
626626
-[删除记录](https://developer.work.weixin.qq.com/document/path/99908)
627627
-[更新记录](https://developer.work.weixin.qq.com/document/path/99909)
628+
-[接收外部数据到智能表格](https://developer.work.weixin.qq.com/document/path/101239/)
628629

629630
#### 获取文档数据
630631

@@ -642,7 +643,7 @@ npm install n8n-nodes-wecom
642643
#### 设置文档权限
643644

644645
-[获取文档权限信息](https://developer.work.weixin.qq.com/document/path/97461)
645-
-[修改文档查看规则](https://developer.work.weixin.qq.com/document/path/97778)
646+
-[修改文档加入规则](https://developer.work.weixin.qq.com/document/path/97778)
646647
-[修改文档通知范围及权限](https://developer.work.weixin.qq.com/document/path/97781)
647648
-[修改文档安全设置](https://developer.work.weixin.qq.com/document/path/97782)
648649
-[管理智能表格内容权限](https://developer.work.weixin.qq.com/document/path/99935)

nodes/WeCom/resources/appChat/execute.ts

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,58 @@ export async function executeAppChat(
4949
}
5050
return undefined;
5151
};
52+
const parseCommaSeparatedList = (value: string): string[] => {
53+
if (!value.trim()) {
54+
return [];
55+
}
56+
57+
return value
58+
.split(',')
59+
.map((item) => item.trim())
60+
.filter((item) => item);
61+
};
62+
const normalizeMentionedUsers = (value: unknown): string[] => {
63+
if (Array.isArray(value)) {
64+
return value
65+
.map((item) => String(item).trim())
66+
.filter((item) => item);
67+
}
68+
69+
if (typeof value === 'string') {
70+
const trimmed = value.trim();
71+
if (!trimmed) {
72+
return [];
73+
}
74+
75+
if (trimmed.startsWith('[')) {
76+
try {
77+
const parsed = JSON.parse(trimmed) as unknown;
78+
if (Array.isArray(parsed)) {
79+
return parsed
80+
.map((item) => String(item).trim())
81+
.filter((item) => item);
82+
}
83+
} catch (error) {
84+
void error;
85+
}
86+
}
87+
88+
if (trimmed.includes(',')) {
89+
return parseCommaSeparatedList(trimmed);
90+
}
91+
92+
if (trimmed.includes('|')) {
93+
return trimmed
94+
.split('|')
95+
.map((item) => item.trim())
96+
.filter((item) => item);
97+
}
98+
99+
return [trimmed];
100+
}
101+
102+
return [];
103+
};
52104

53105
for (let i = 0; i < items.length; i++) {
54106
try {
@@ -162,13 +214,22 @@ export async function executeAppChat(
162214
if (operation === 'sendText') {
163215
const content = this.getNodeParameter('content', i) as string;
164216
const safe = this.getNodeParameter('safe', i, false) as boolean;
217+
const mentionedList = this.getNodeParameter('mentionedList', i, []) as
218+
| string
219+
| string[];
220+
const text: IDataObject = {
221+
content,
222+
};
223+
const mentionedUsers = normalizeMentionedUsers(mentionedList);
224+
225+
if (mentionedUsers.length > 0) {
226+
text.mentioned_list = mentionedUsers;
227+
}
165228

166229
body = {
167230
...body,
168231
msgtype: 'text',
169-
text: {
170-
content,
171-
},
232+
text,
172233
safe: safe ? 1 : 0,
173234
};
174235
} else if (operation === 'sendImage') {

nodes/WeCom/resources/appChat/sendMarkdown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const showOnlyForSendMarkdown = {
77

88
export const sendMarkdownDescription: INodeProperties[] = [
99
{
10-
displayName: '群聊ID',
10+
displayName: '群聊 ID',
1111
name: 'chatid',
1212
type: 'string',
1313
displayOptions: {
@@ -17,7 +17,7 @@ export const sendMarkdownDescription: INodeProperties[] = [
1717
placeholder: 'mychat001',
1818
required: true,
1919
description:
20-
'群聊的唯一标识。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
20+
'群聊会话的唯一标识。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
2121
},
2222
{
2323
displayName: '消息内容',
@@ -33,6 +33,6 @@ export const sendMarkdownDescription: INodeProperties[] = [
3333
placeholder: '# 标题\n\n**加粗** *斜体*',
3434
required: true,
3535
description:
36-
'Markdown 格式的消息内容。最长不超过2048个字节,必须是utf8编码。目前仅支持markdown语法的子集。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
36+
'Markdown 格式的消息内容,最长不超过 2048 字节,必须为 UTF-8 编码。目前仅支持 Markdown 子集。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
3737
},
3838
];

nodes/WeCom/resources/appChat/sendText.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const showOnlyForSendText = {
77

88
export const sendTextDescription: INodeProperties[] = [
99
{
10-
displayName: '群聊ID',
10+
displayName: '群聊 ID',
1111
name: 'chatid',
1212
type: 'string',
1313
displayOptions: {
@@ -17,7 +17,7 @@ export const sendTextDescription: INodeProperties[] = [
1717
placeholder: 'mychat001',
1818
required: true,
1919
description:
20-
'群聊的唯一标识。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
20+
'群聊会话的唯一标识。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
2121
},
2222
{
2323
displayName: '消息内容',
@@ -30,10 +30,24 @@ export const sendTextDescription: INodeProperties[] = [
3030
show: showOnlyForSendText,
3131
},
3232
default: '',
33-
placeholder: '请输入消息内容',
33+
placeholder: '请输入文本消息内容',
3434
required: true,
3535
description:
36-
'文本消息内容。最长不超过2048个字节。支持换行,换行符请用转义过的\\n。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
36+
'文本消息内容,最长不超过 2048 字节。支持换行,换行请使用 \\n。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
37+
},
38+
{
39+
displayName: '@ 成员 Names or IDs',
40+
name: 'mentionedList',
41+
type: 'multiOptions',
42+
typeOptions: {
43+
loadOptionsMethod: 'getAllUsersWithAllOption',
44+
},
45+
displayOptions: {
46+
show: showOnlyForSendText,
47+
},
48+
default: [],
49+
description:
50+
'可选。支持从下拉列表选择群成员,也支持切换到表达式后输入 UserID 数组或字符串。下拉列表第一项为“所有人”。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
3751
},
3852
{
3953
displayName: '保密消息',
@@ -44,6 +58,6 @@ export const sendTextDescription: INodeProperties[] = [
4458
},
4559
default: false,
4660
description:
47-
'可选。表示是否是保密消息,0表示否,1表示是,默认0。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
61+
'可选。是否发送为保密消息。开启后消息不可转发、复制等。<a href="https://developer.work.weixin.qq.com/document/path/90248" target="_blank">官方文档</a>',
4862
},
4963
];

0 commit comments

Comments
 (0)