n8n-nodes-wecom 0.3.51 → 0.3.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,24 @@ const commonFields_1 = require("./commonFields");
7
7
  async function executeMessage(operation, items) {
8
8
  var _a, _b;
9
9
  const returnData = [];
10
+ const parseOptionalJsonParameter = (value, parameterName, itemIndex) => {
11
+ if (value === undefined || value === null) {
12
+ return undefined;
13
+ }
14
+ if (typeof value === 'string') {
15
+ const trimmed = value.trim();
16
+ if (!trimmed || trimmed === '{}' || trimmed === '[]') {
17
+ return undefined;
18
+ }
19
+ try {
20
+ return JSON.parse(trimmed);
21
+ }
22
+ catch (error) {
23
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${parameterName} 必须是有效的 JSON: ${error.message}`, { itemIndex });
24
+ }
25
+ }
26
+ return value;
27
+ };
10
28
  for (let i = 0; i < items.length; i++) {
11
29
  try {
12
30
  const credentials = await this.getCredentials('weComApi');
@@ -184,24 +202,43 @@ async function executeMessage(operation, items) {
184
202
  }
185
203
  }
186
204
  else if (operation === 'sendNews') {
205
+ const newsInputMode = this.getNodeParameter('news_input_mode', i, 'form');
206
+ const newsJson = newsInputMode === 'json'
207
+ ? parseOptionalJsonParameter(this.getNodeParameter('news_json', i, '[]'), 'news_json', i)
208
+ : undefined;
187
209
  const articles = this.getNodeParameter('articles', i, {});
188
210
  const enable_id_trans = this.getNodeParameter('enable_id_trans', i, false);
189
211
  const enable_duplicate_check = this.getNodeParameter('enable_duplicate_check', i, false);
190
- const articleList = (articles.article || []).map((article) => {
191
- const processedArticle = {
192
- title: article.title,
193
- description: article.description,
194
- picurl: article.picurl,
195
- };
196
- if (article.jump_type === 'miniprogram' && article.appid && article.pagepath) {
197
- processedArticle.appid = article.appid;
198
- processedArticle.pagepath = article.pagepath;
212
+ let articleList = [];
213
+ if (newsInputMode === 'json') {
214
+ if (!newsJson) {
215
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), '请选择 JSON 输入并提供 news_json', { itemIndex: i });
199
216
  }
200
- else if (article.url) {
201
- processedArticle.url = article.url;
217
+ const newsPayload = Array.isArray(newsJson)
218
+ ? { articles: newsJson }
219
+ : newsJson;
220
+ if (!Array.isArray(newsPayload.articles) || newsPayload.articles.length === 0) {
221
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'news_json 必须包含 articles 数组,且至少提供一条图文', { itemIndex: i });
202
222
  }
203
- return processedArticle;
204
- });
223
+ articleList = newsPayload.articles;
224
+ }
225
+ else {
226
+ articleList = (articles.article || []).map((article) => {
227
+ const processedArticle = {
228
+ title: article.title,
229
+ description: article.description,
230
+ picurl: article.picurl,
231
+ };
232
+ if (article.jump_type === 'miniprogram' && article.appid && article.pagepath) {
233
+ processedArticle.appid = article.appid;
234
+ processedArticle.pagepath = article.pagepath;
235
+ }
236
+ else if (article.url) {
237
+ processedArticle.url = article.url;
238
+ }
239
+ return processedArticle;
240
+ });
241
+ }
205
242
  body = {
206
243
  ...body,
207
244
  msgtype: 'news',
@@ -217,11 +254,30 @@ async function executeMessage(operation, items) {
217
254
  }
218
255
  }
219
256
  else if (operation === 'sendMpNews') {
257
+ const mpnewsInputMode = this.getNodeParameter('mpnews_input_mode', i, 'form');
258
+ const mpnewsJson = mpnewsInputMode === 'json'
259
+ ? parseOptionalJsonParameter(this.getNodeParameter('mpnews_json', i, '[]'), 'mpnews_json', i)
260
+ : undefined;
220
261
  const articles = this.getNodeParameter('articles', i, {});
221
262
  const safe = this.getNodeParameter('safe', i, 0);
222
263
  const enable_id_trans = this.getNodeParameter('enable_id_trans', i, false);
223
264
  const enable_duplicate_check = this.getNodeParameter('enable_duplicate_check', i, false);
224
- const articleList = articles.article || [];
265
+ let articleList = [];
266
+ if (mpnewsInputMode === 'json') {
267
+ if (!mpnewsJson) {
268
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), '请选择 JSON 输入并提供 mpnews_json', { itemIndex: i });
269
+ }
270
+ const mpnewsPayload = Array.isArray(mpnewsJson)
271
+ ? { articles: mpnewsJson }
272
+ : mpnewsJson;
273
+ if (!Array.isArray(mpnewsPayload.articles) || mpnewsPayload.articles.length === 0) {
274
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'mpnews_json 必须包含 articles 数组,且至少提供一条图文', { itemIndex: i });
275
+ }
276
+ articleList = mpnewsPayload.articles;
277
+ }
278
+ else {
279
+ articleList = articles.article || [];
280
+ }
225
281
  body = {
226
282
  ...body,
227
283
  msgtype: 'mpnews',
@@ -238,6 +294,10 @@ async function executeMessage(operation, items) {
238
294
  }
239
295
  }
240
296
  else if (operation === 'sendMiniprogramNotice') {
297
+ const miniprogramNoticeInputMode = this.getNodeParameter('miniprogram_notice_input_mode', i, 'form');
298
+ const miniprogramNoticeJson = miniprogramNoticeInputMode === 'json'
299
+ ? parseOptionalJsonParameter(this.getNodeParameter('miniprogram_notice_json', i, '{}'), 'miniprogram_notice_json', i)
300
+ : undefined;
241
301
  const appid = this.getNodeParameter('appid', i);
242
302
  const page = this.getNodeParameter('page', i, '');
243
303
  const title = this.getNodeParameter('title', i);
@@ -246,18 +306,31 @@ async function executeMessage(operation, items) {
246
306
  const content_items = this.getNodeParameter('content_items', i, {});
247
307
  const enable_id_trans = this.getNodeParameter('enable_id_trans', i, false);
248
308
  const enable_duplicate_check = this.getNodeParameter('enable_duplicate_check', i, false);
249
- const contentItemList = content_items.item || [];
250
- body = {
251
- ...body,
252
- msgtype: 'miniprogram_notice',
253
- miniprogram_notice: {
309
+ let miniprogramNotice;
310
+ if (miniprogramNoticeInputMode === 'json') {
311
+ if (!miniprogramNoticeJson) {
312
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), '请选择 JSON 输入并提供 miniprogram_notice_json', { itemIndex: i });
313
+ }
314
+ if (Array.isArray(miniprogramNoticeJson)) {
315
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'miniprogram_notice_json 必须是对象', { itemIndex: i });
316
+ }
317
+ miniprogramNotice = miniprogramNoticeJson;
318
+ }
319
+ else {
320
+ const contentItemList = content_items.item || [];
321
+ miniprogramNotice = {
254
322
  appid,
255
323
  page,
256
324
  title,
257
325
  description,
258
326
  emphasis_first_item: emphasis_first_item ? true : false,
259
327
  content_item: contentItemList,
260
- },
328
+ };
329
+ }
330
+ body = {
331
+ ...body,
332
+ msgtype: 'miniprogram_notice',
333
+ miniprogram_notice: miniprogramNotice,
261
334
  enable_id_trans: enable_id_trans ? 1 : 0,
262
335
  enable_duplicate_check: enable_duplicate_check ? 1 : 0,
263
336
  };
@@ -267,6 +340,10 @@ async function executeMessage(operation, items) {
267
340
  }
268
341
  }
269
342
  else if (operation === 'sendTaskCard') {
343
+ const taskcardInputMode = this.getNodeParameter('taskcard_input_mode', i, 'form');
344
+ const taskcardJson = taskcardInputMode === 'json'
345
+ ? parseOptionalJsonParameter(this.getNodeParameter('taskcard_json', i, '{}'), 'taskcard_json', i)
346
+ : undefined;
270
347
  const title = this.getNodeParameter('title', i);
271
348
  const description = this.getNodeParameter('description', i);
272
349
  const url = this.getNodeParameter('url', i, '');
@@ -274,23 +351,36 @@ async function executeMessage(operation, items) {
274
351
  const buttons = this.getNodeParameter('buttons', i, {});
275
352
  const enable_id_trans = this.getNodeParameter('enable_id_trans', i, false);
276
353
  const enable_duplicate_check = this.getNodeParameter('enable_duplicate_check', i, false);
277
- const buttonList = (buttons.button || []).map((btn) => ({
278
- key: btn.key,
279
- name: btn.name,
280
- replace_name: btn.replace_name || '已处理',
281
- color: btn.color || 'blue',
282
- is_bold: btn.is_bold ? true : false,
283
- }));
284
- body = {
285
- ...body,
286
- msgtype: 'taskcard',
287
- taskcard: {
354
+ let taskcard;
355
+ if (taskcardInputMode === 'json') {
356
+ if (!taskcardJson) {
357
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), '请选择 JSON 输入并提供 taskcard_json', { itemIndex: i });
358
+ }
359
+ if (Array.isArray(taskcardJson)) {
360
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'taskcard_json 必须是对象', { itemIndex: i });
361
+ }
362
+ taskcard = taskcardJson;
363
+ }
364
+ else {
365
+ const buttonList = (buttons.button || []).map((btn) => ({
366
+ key: btn.key,
367
+ name: btn.name,
368
+ replace_name: btn.replace_name || '已处理',
369
+ color: btn.color || 'blue',
370
+ is_bold: btn.is_bold ? true : false,
371
+ }));
372
+ taskcard = {
288
373
  title,
289
374
  description,
290
375
  url,
291
376
  task_id,
292
377
  btn: buttonList,
293
- },
378
+ };
379
+ }
380
+ body = {
381
+ ...body,
382
+ msgtype: 'taskcard',
383
+ taskcard,
294
384
  enable_id_trans: enable_id_trans ? 1 : 0,
295
385
  enable_duplicate_check: enable_duplicate_check ? 1 : 0,
296
386
  };
@@ -300,145 +390,164 @@ async function executeMessage(operation, items) {
300
390
  }
301
391
  }
302
392
  else if (operation === 'sendTemplateCard') {
393
+ const templateCardInputMode = this.getNodeParameter('template_card_input_mode', i, 'form');
394
+ const templateCardJson = templateCardInputMode === 'json'
395
+ ? parseOptionalJsonParameter(this.getNodeParameter('template_card_json', i, '{}'), 'template_card_json', i)
396
+ : undefined;
303
397
  const card_type = this.getNodeParameter('card_type', i);
304
398
  const enable_id_trans = this.getNodeParameter('enable_id_trans', i, false);
305
399
  const enable_duplicate_check = this.getNodeParameter('enable_duplicate_check', i, false);
306
- const sourceData = this.getNodeParameter('source', i, {});
307
- const mainTitleData = this.getNodeParameter('main_title', i, {});
308
- const emphasisContentData = this.getNodeParameter('emphasis_content', i, {});
309
- const quoteAreaData = this.getNodeParameter('quote_area', i, {});
310
- const sub_title_text = this.getNodeParameter('sub_title_text', i, '');
311
- const horizontalContentListData = this.getNodeParameter('horizontal_content_list', i, {});
312
- const jumpListData = this.getNodeParameter('jump_list', i, {});
313
- const cardActionData = this.getNodeParameter('card_action', i, {});
314
- const task_id = this.getNodeParameter('task_id', i, '');
315
- const actionMenuData = this.getNodeParameter('action_menu', i, {});
316
- const template_card = {
317
- card_type,
318
- };
319
- if (sourceData.sourceInfo) {
320
- template_card.source = sourceData.sourceInfo;
321
- }
322
- if (mainTitleData.titleInfo) {
323
- template_card.main_title = mainTitleData.titleInfo;
324
- }
325
- if (emphasisContentData.emphasisInfo) {
326
- template_card.emphasis_content = emphasisContentData.emphasisInfo;
327
- }
328
- if (quoteAreaData.quoteInfo) {
329
- template_card.quote_area = quoteAreaData.quoteInfo;
330
- }
331
- if (sub_title_text) {
332
- template_card.sub_title_text = sub_title_text;
333
- }
334
- if (horizontalContentListData.items && Array.isArray(horizontalContentListData.items)) {
335
- template_card.horizontal_content_list = horizontalContentListData.items;
336
- }
337
- if (jumpListData.items && Array.isArray(jumpListData.items)) {
338
- template_card.jump_list = jumpListData.items;
339
- }
340
- if (cardActionData.actionInfo) {
341
- template_card.card_action = cardActionData.actionInfo;
342
- }
343
- if (task_id) {
344
- template_card.task_id = task_id;
345
- }
346
- if (card_type === 'button_interaction') {
347
- const buttonListData = this.getNodeParameter('button_list', i, {});
348
- if (buttonListData.buttons && Array.isArray(buttonListData.buttons)) {
349
- template_card.button_list = buttonListData.buttons;
400
+ let template_card;
401
+ if (templateCardInputMode === 'json') {
402
+ if (!templateCardJson) {
403
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), '请选择 JSON 输入并提供 template_card_json', { itemIndex: i });
350
404
  }
351
- const buttonSelectionData = this.getNodeParameter('button_selection', i, {});
352
- if (buttonSelectionData.selectionInfo) {
353
- const selectionInfo = buttonSelectionData.selectionInfo;
354
- template_card.button_selection = {
355
- question_key: selectionInfo.question_key,
356
- title: selectionInfo.title,
357
- selected_id: selectionInfo.selected_id,
358
- option_list: ((_a = selectionInfo.option_list) === null || _a === void 0 ? void 0 : _a.options) || [],
359
- };
405
+ if (Array.isArray(templateCardJson)) {
406
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'template_card_json 必须是对象', { itemIndex: i });
407
+ }
408
+ template_card = { ...templateCardJson };
409
+ if (!template_card.card_type) {
410
+ template_card.card_type = card_type;
360
411
  }
361
412
  }
362
- else if (card_type === 'vote_interaction') {
363
- const checkbox_question_key = this.getNodeParameter('checkbox_question_key', i, '');
364
- const checkbox_mode = this.getNodeParameter('checkbox_mode', i, 0);
365
- const optionListData = this.getNodeParameter('option_list', i, {});
366
- const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
367
- const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
368
- if (checkbox_question_key) {
369
- const options = Array.isArray(optionListData.options)
370
- ? optionListData.options
371
- : [];
372
- template_card.checkbox = {
373
- question_key: checkbox_question_key,
374
- mode: checkbox_mode,
375
- option_list: options.map((opt) => ({
376
- id: opt.id,
377
- text: opt.text,
378
- is_checked: opt.is_checked || false,
379
- })),
380
- };
413
+ else {
414
+ const sourceData = this.getNodeParameter('source', i, {});
415
+ const mainTitleData = this.getNodeParameter('main_title', i, {});
416
+ const emphasisContentData = this.getNodeParameter('emphasis_content', i, {});
417
+ const quoteAreaData = this.getNodeParameter('quote_area', i, {});
418
+ const sub_title_text = this.getNodeParameter('sub_title_text', i, '');
419
+ const horizontalContentListData = this.getNodeParameter('horizontal_content_list', i, {});
420
+ const jumpListData = this.getNodeParameter('jump_list', i, {});
421
+ const cardActionData = this.getNodeParameter('card_action', i, {});
422
+ const task_id = this.getNodeParameter('task_id', i, '');
423
+ const actionMenuData = this.getNodeParameter('action_menu', i, {});
424
+ template_card = {
425
+ card_type,
426
+ };
427
+ if (sourceData.sourceInfo) {
428
+ template_card.source = sourceData.sourceInfo;
381
429
  }
382
- if (submit_button_key) {
383
- template_card.submit_button = {
384
- text: submit_button_text,
385
- key: submit_button_key,
386
- };
430
+ if (mainTitleData.titleInfo) {
431
+ template_card.main_title = mainTitleData.titleInfo;
387
432
  }
388
- }
389
- else if (card_type === 'multiple_interaction') {
390
- const selectListData = this.getNodeParameter('select_list', i, {});
391
- const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
392
- const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
393
- if (selectListData.selectors && Array.isArray(selectListData.selectors)) {
394
- template_card.select_list = selectListData.selectors.map((selector) => {
395
- const optionList = selector.option_list;
396
- const options = optionList && Array.isArray(optionList.options)
397
- ? optionList.options
398
- : [];
399
- return {
400
- question_key: selector.question_key,
401
- title: selector.title,
402
- selected_id: selector.selected_id,
403
- option_list: options,
404
- };
405
- });
433
+ if (emphasisContentData.emphasisInfo) {
434
+ template_card.emphasis_content = emphasisContentData.emphasisInfo;
406
435
  }
407
- if (submit_button_key) {
408
- template_card.submit_button = {
409
- text: submit_button_text,
410
- key: submit_button_key,
411
- };
436
+ if (quoteAreaData.quoteInfo) {
437
+ template_card.quote_area = quoteAreaData.quoteInfo;
412
438
  }
413
- }
414
- else if (card_type === 'news_notice') {
415
- const imageTextAreaData = this.getNodeParameter('image_text_area', i, {});
416
- if (imageTextAreaData.imageTextInfo) {
417
- template_card.image_text_area = imageTextAreaData.imageTextInfo;
439
+ if (sub_title_text) {
440
+ template_card.sub_title_text = sub_title_text;
418
441
  }
419
- const cardImageData = this.getNodeParameter('card_image', i, {});
420
- if (cardImageData.imageInfo) {
421
- template_card.card_image = cardImageData.imageInfo;
442
+ if (horizontalContentListData.items && Array.isArray(horizontalContentListData.items)) {
443
+ template_card.horizontal_content_list = horizontalContentListData.items;
422
444
  }
423
- const verticalContentListData = this.getNodeParameter('vertical_content_list', i, {});
424
- if (verticalContentListData.items && Array.isArray(verticalContentListData.items)) {
425
- template_card.vertical_content_list = verticalContentListData.items;
445
+ if (jumpListData.items && Array.isArray(jumpListData.items)) {
446
+ template_card.jump_list = jumpListData.items;
426
447
  }
427
- }
428
- if (actionMenuData.menuInfo) {
429
- const menuInfo = actionMenuData.menuInfo;
430
- const menuData = {};
431
- if (menuInfo.desc) {
432
- menuData.desc = menuInfo.desc;
448
+ if (cardActionData.actionInfo) {
449
+ template_card.card_action = cardActionData.actionInfo;
433
450
  }
434
- if (menuInfo.action_list) {
435
- const actionListData = menuInfo.action_list;
436
- if (actionListData.actions && Array.isArray(actionListData.actions)) {
437
- menuData.action_list = actionListData.actions;
451
+ if (task_id) {
452
+ template_card.task_id = task_id;
453
+ }
454
+ if (card_type === 'button_interaction') {
455
+ const buttonListData = this.getNodeParameter('button_list', i, {});
456
+ if (buttonListData.buttons && Array.isArray(buttonListData.buttons)) {
457
+ template_card.button_list = buttonListData.buttons;
458
+ }
459
+ const buttonSelectionData = this.getNodeParameter('button_selection', i, {});
460
+ if (buttonSelectionData.selectionInfo) {
461
+ const selectionInfo = buttonSelectionData.selectionInfo;
462
+ template_card.button_selection = {
463
+ question_key: selectionInfo.question_key,
464
+ title: selectionInfo.title,
465
+ selected_id: selectionInfo.selected_id,
466
+ option_list: ((_a = selectionInfo.option_list) === null || _a === void 0 ? void 0 : _a.options) || [],
467
+ };
438
468
  }
439
469
  }
440
- if (Object.keys(menuData).length > 0) {
441
- template_card.action_menu = menuData;
470
+ else if (card_type === 'vote_interaction') {
471
+ const checkbox_question_key = this.getNodeParameter('checkbox_question_key', i, '');
472
+ const checkbox_mode = this.getNodeParameter('checkbox_mode', i, 0);
473
+ const optionListData = this.getNodeParameter('option_list', i, {});
474
+ const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
475
+ const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
476
+ if (checkbox_question_key) {
477
+ const options = Array.isArray(optionListData.options)
478
+ ? optionListData.options
479
+ : [];
480
+ template_card.checkbox = {
481
+ question_key: checkbox_question_key,
482
+ mode: checkbox_mode,
483
+ option_list: options.map((opt) => ({
484
+ id: opt.id,
485
+ text: opt.text,
486
+ is_checked: opt.is_checked || false,
487
+ })),
488
+ };
489
+ }
490
+ if (submit_button_key) {
491
+ template_card.submit_button = {
492
+ text: submit_button_text,
493
+ key: submit_button_key,
494
+ };
495
+ }
496
+ }
497
+ else if (card_type === 'multiple_interaction') {
498
+ const selectListData = this.getNodeParameter('select_list', i, {});
499
+ const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
500
+ const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
501
+ if (selectListData.selectors && Array.isArray(selectListData.selectors)) {
502
+ template_card.select_list = selectListData.selectors.map((selector) => {
503
+ const optionList = selector.option_list;
504
+ const options = optionList && Array.isArray(optionList.options)
505
+ ? optionList.options
506
+ : [];
507
+ return {
508
+ question_key: selector.question_key,
509
+ title: selector.title,
510
+ selected_id: selector.selected_id,
511
+ option_list: options,
512
+ };
513
+ });
514
+ }
515
+ if (submit_button_key) {
516
+ template_card.submit_button = {
517
+ text: submit_button_text,
518
+ key: submit_button_key,
519
+ };
520
+ }
521
+ }
522
+ else if (card_type === 'news_notice') {
523
+ const imageTextAreaData = this.getNodeParameter('image_text_area', i, {});
524
+ if (imageTextAreaData.imageTextInfo) {
525
+ template_card.image_text_area = imageTextAreaData.imageTextInfo;
526
+ }
527
+ const cardImageData = this.getNodeParameter('card_image', i, {});
528
+ if (cardImageData.imageInfo) {
529
+ template_card.card_image = cardImageData.imageInfo;
530
+ }
531
+ const verticalContentListData = this.getNodeParameter('vertical_content_list', i, {});
532
+ if (verticalContentListData.items && Array.isArray(verticalContentListData.items)) {
533
+ template_card.vertical_content_list = verticalContentListData.items;
534
+ }
535
+ }
536
+ if (actionMenuData.menuInfo) {
537
+ const menuInfo = actionMenuData.menuInfo;
538
+ const menuData = {};
539
+ if (menuInfo.desc) {
540
+ menuData.desc = menuInfo.desc;
541
+ }
542
+ if (menuInfo.action_list) {
543
+ const actionListData = menuInfo.action_list;
544
+ if (actionListData.actions && Array.isArray(actionListData.actions)) {
545
+ menuData.action_list = actionListData.actions;
546
+ }
547
+ }
548
+ if (Object.keys(menuData).length > 0) {
549
+ template_card.action_menu = menuData;
550
+ }
442
551
  }
443
552
  }
444
553
  body = {
@@ -455,6 +564,10 @@ async function executeMessage(operation, items) {
455
564
  }
456
565
  else if (operation === 'updateTemplateCard') {
457
566
  const response_code = this.getNodeParameter('response_code', i);
567
+ const templateCardInputMode = this.getNodeParameter('template_card_input_mode', i, 'form');
568
+ const templateCardJson = templateCardInputMode === 'json'
569
+ ? parseOptionalJsonParameter(this.getNodeParameter('template_card_json', i, '{}'), 'template_card_json', i)
570
+ : undefined;
458
571
  const card_type = this.getNodeParameter('card_type', i);
459
572
  const button_key = this.getNodeParameter('button_key', i, '');
460
573
  const enable_id_trans = this.getNodeParameter('enable_id_trans', i, false);
@@ -478,144 +591,159 @@ async function executeMessage(operation, items) {
478
591
  const cardActionData = this.getNodeParameter('card_action', i, {});
479
592
  const task_id = this.getNodeParameter('task_id', i, '');
480
593
  const actionMenuData = this.getNodeParameter('action_menu', i, {});
481
- const template_card = {
482
- card_type,
483
- };
484
- if (sourceData.sourceInfo) {
485
- template_card.source = sourceData.sourceInfo;
486
- }
487
- if (mainTitleData.titleInfo) {
488
- template_card.main_title = mainTitleData.titleInfo;
489
- }
490
- if (emphasisContentData.emphasisInfo) {
491
- template_card.emphasis_content = emphasisContentData.emphasisInfo;
492
- }
493
- if (quoteAreaData.quoteInfo) {
494
- template_card.quote_area = quoteAreaData.quoteInfo;
495
- }
496
- if (sub_title_text) {
497
- template_card.sub_title_text = sub_title_text;
498
- }
499
- if (horizontalContentListData.items && Array.isArray(horizontalContentListData.items)) {
500
- template_card.horizontal_content_list = horizontalContentListData.items;
501
- }
502
- if (jumpListData.items && Array.isArray(jumpListData.items)) {
503
- template_card.jump_list = jumpListData.items;
504
- }
505
- if (cardActionData.actionInfo) {
506
- template_card.card_action = cardActionData.actionInfo;
507
- }
508
- if (task_id) {
509
- template_card.task_id = task_id;
594
+ let template_card;
595
+ if (templateCardInputMode === 'json') {
596
+ if (!templateCardJson) {
597
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), '请选择 JSON 输入并提供 template_card_json', { itemIndex: i });
598
+ }
599
+ if (Array.isArray(templateCardJson)) {
600
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'template_card_json 必须是对象', { itemIndex: i });
601
+ }
602
+ template_card = { ...templateCardJson };
603
+ if (!template_card.card_type) {
604
+ template_card.card_type = card_type;
605
+ }
510
606
  }
511
- if (card_type === 'button_interaction') {
512
- const buttonListData = this.getNodeParameter('button_list', i, {});
513
- if (buttonListData.buttons && Array.isArray(buttonListData.buttons)) {
514
- template_card.button_list = buttonListData.buttons;
607
+ else {
608
+ template_card = {
609
+ card_type,
610
+ };
611
+ if (sourceData.sourceInfo) {
612
+ template_card.source = sourceData.sourceInfo;
515
613
  }
516
- const buttonSelectionData = this.getNodeParameter('button_selection', i, {});
517
- if (buttonSelectionData.selectionInfo) {
518
- const selectionInfo = buttonSelectionData.selectionInfo;
519
- template_card.button_selection = {
520
- question_key: selectionInfo.question_key,
521
- title: selectionInfo.title,
522
- selected_id: selectionInfo.selected_id,
523
- option_list: ((_b = selectionInfo.option_list) === null || _b === void 0 ? void 0 : _b.options) || [],
524
- };
614
+ if (mainTitleData.titleInfo) {
615
+ template_card.main_title = mainTitleData.titleInfo;
525
616
  }
526
- if (replace_text) {
527
- template_card.replace_text = replace_text;
528
- }
529
- }
530
- else if (card_type === 'vote_interaction') {
531
- const checkbox_question_key = this.getNodeParameter('checkbox_question_key', i, '');
532
- const checkbox_mode = this.getNodeParameter('checkbox_mode', i, 0);
533
- const checkbox_disable = this.getNodeParameter('checkbox_disable', i, false);
534
- const optionListData = this.getNodeParameter('option_list', i, {});
535
- const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
536
- const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
537
- if (checkbox_question_key) {
538
- const options = Array.isArray(optionListData.options)
539
- ? optionListData.options
540
- : [];
541
- template_card.checkbox = {
542
- question_key: checkbox_question_key,
543
- mode: checkbox_mode,
544
- disable: checkbox_disable,
545
- option_list: options.map((opt) => ({
546
- id: opt.id,
547
- text: opt.text,
548
- is_checked: opt.is_checked || false,
549
- })),
550
- };
617
+ if (emphasisContentData.emphasisInfo) {
618
+ template_card.emphasis_content = emphasisContentData.emphasisInfo;
551
619
  }
552
- if (submit_button_key) {
553
- template_card.submit_button = {
554
- text: submit_button_text,
555
- key: submit_button_key,
556
- };
620
+ if (quoteAreaData.quoteInfo) {
621
+ template_card.quote_area = quoteAreaData.quoteInfo;
557
622
  }
558
- if (replace_text) {
559
- template_card.replace_text = replace_text;
623
+ if (sub_title_text) {
624
+ template_card.sub_title_text = sub_title_text;
560
625
  }
561
- }
562
- else if (card_type === 'multiple_interaction') {
563
- const selectListData = this.getNodeParameter('select_list', i, {});
564
- const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
565
- const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
566
- if (selectListData.selectors && Array.isArray(selectListData.selectors)) {
567
- template_card.select_list = selectListData.selectors.map((selector) => {
568
- const optionList = selector.option_list;
569
- const options = optionList && Array.isArray(optionList.options)
570
- ? optionList.options
571
- : [];
572
- return {
573
- question_key: selector.question_key,
574
- title: selector.title,
575
- selected_id: selector.selected_id,
576
- disable: selector.disable || false,
577
- option_list: options,
578
- };
579
- });
626
+ if (horizontalContentListData.items && Array.isArray(horizontalContentListData.items)) {
627
+ template_card.horizontal_content_list = horizontalContentListData.items;
580
628
  }
581
- if (submit_button_key) {
582
- template_card.submit_button = {
583
- text: submit_button_text,
584
- key: submit_button_key,
585
- };
629
+ if (jumpListData.items && Array.isArray(jumpListData.items)) {
630
+ template_card.jump_list = jumpListData.items;
586
631
  }
587
- if (replace_text) {
588
- template_card.replace_text = replace_text;
632
+ if (cardActionData.actionInfo) {
633
+ template_card.card_action = cardActionData.actionInfo;
589
634
  }
590
- }
591
- else if (card_type === 'news_notice') {
592
- const imageTextAreaData = this.getNodeParameter('image_text_area', i, {});
593
- if (imageTextAreaData.imageTextInfo) {
594
- template_card.image_text_area = imageTextAreaData.imageTextInfo;
635
+ if (task_id) {
636
+ template_card.task_id = task_id;
595
637
  }
596
- const cardImageData = this.getNodeParameter('card_image', i, {});
597
- if (cardImageData.imageInfo) {
598
- template_card.card_image = cardImageData.imageInfo;
638
+ if (card_type === 'button_interaction') {
639
+ const buttonListData = this.getNodeParameter('button_list', i, {});
640
+ if (buttonListData.buttons && Array.isArray(buttonListData.buttons)) {
641
+ template_card.button_list = buttonListData.buttons;
642
+ }
643
+ const buttonSelectionData = this.getNodeParameter('button_selection', i, {});
644
+ if (buttonSelectionData.selectionInfo) {
645
+ const selectionInfo = buttonSelectionData.selectionInfo;
646
+ template_card.button_selection = {
647
+ question_key: selectionInfo.question_key,
648
+ title: selectionInfo.title,
649
+ selected_id: selectionInfo.selected_id,
650
+ option_list: ((_b = selectionInfo.option_list) === null || _b === void 0 ? void 0 : _b.options) || [],
651
+ };
652
+ }
653
+ if (replace_text) {
654
+ template_card.replace_text = replace_text;
655
+ }
599
656
  }
600
- const verticalContentListData = this.getNodeParameter('vertical_content_list', i, {});
601
- if (verticalContentListData.items && Array.isArray(verticalContentListData.items)) {
602
- template_card.vertical_content_list = verticalContentListData.items;
657
+ else if (card_type === 'vote_interaction') {
658
+ const checkbox_question_key = this.getNodeParameter('checkbox_question_key', i, '');
659
+ const checkbox_mode = this.getNodeParameter('checkbox_mode', i, 0);
660
+ const checkbox_disable = this.getNodeParameter('checkbox_disable', i, false);
661
+ const optionListData = this.getNodeParameter('option_list', i, {});
662
+ const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
663
+ const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
664
+ if (checkbox_question_key) {
665
+ const options = Array.isArray(optionListData.options)
666
+ ? optionListData.options
667
+ : [];
668
+ template_card.checkbox = {
669
+ question_key: checkbox_question_key,
670
+ mode: checkbox_mode,
671
+ disable: checkbox_disable,
672
+ option_list: options.map((opt) => ({
673
+ id: opt.id,
674
+ text: opt.text,
675
+ is_checked: opt.is_checked || false,
676
+ })),
677
+ };
678
+ }
679
+ if (submit_button_key) {
680
+ template_card.submit_button = {
681
+ text: submit_button_text,
682
+ key: submit_button_key,
683
+ };
684
+ }
685
+ if (replace_text) {
686
+ template_card.replace_text = replace_text;
687
+ }
603
688
  }
604
- }
605
- if (actionMenuData.menuInfo) {
606
- const menuInfo = actionMenuData.menuInfo;
607
- const menuData = {};
608
- if (menuInfo.desc) {
609
- menuData.desc = menuInfo.desc;
689
+ else if (card_type === 'multiple_interaction') {
690
+ const selectListData = this.getNodeParameter('select_list', i, {});
691
+ const submit_button_text = this.getNodeParameter('submit_button_text', i, '提交');
692
+ const submit_button_key = this.getNodeParameter('submit_button_key', i, '');
693
+ if (selectListData.selectors && Array.isArray(selectListData.selectors)) {
694
+ template_card.select_list = selectListData.selectors.map((selector) => {
695
+ const optionList = selector.option_list;
696
+ const options = optionList && Array.isArray(optionList.options)
697
+ ? optionList.options
698
+ : [];
699
+ return {
700
+ question_key: selector.question_key,
701
+ title: selector.title,
702
+ selected_id: selector.selected_id,
703
+ disable: selector.disable || false,
704
+ option_list: options,
705
+ };
706
+ });
707
+ }
708
+ if (submit_button_key) {
709
+ template_card.submit_button = {
710
+ text: submit_button_text,
711
+ key: submit_button_key,
712
+ };
713
+ }
714
+ if (replace_text) {
715
+ template_card.replace_text = replace_text;
716
+ }
610
717
  }
611
- if (menuInfo.action_list) {
612
- const actionListData = menuInfo.action_list;
613
- if (actionListData.actions && Array.isArray(actionListData.actions)) {
614
- menuData.action_list = actionListData.actions;
718
+ else if (card_type === 'news_notice') {
719
+ const imageTextAreaData = this.getNodeParameter('image_text_area', i, {});
720
+ if (imageTextAreaData.imageTextInfo) {
721
+ template_card.image_text_area = imageTextAreaData.imageTextInfo;
722
+ }
723
+ const cardImageData = this.getNodeParameter('card_image', i, {});
724
+ if (cardImageData.imageInfo) {
725
+ template_card.card_image = cardImageData.imageInfo;
726
+ }
727
+ const verticalContentListData = this.getNodeParameter('vertical_content_list', i, {});
728
+ if (verticalContentListData.items && Array.isArray(verticalContentListData.items)) {
729
+ template_card.vertical_content_list = verticalContentListData.items;
615
730
  }
616
731
  }
617
- if (Object.keys(menuData).length > 0) {
618
- template_card.action_menu = menuData;
732
+ if (actionMenuData.menuInfo) {
733
+ const menuInfo = actionMenuData.menuInfo;
734
+ const menuData = {};
735
+ if (menuInfo.desc) {
736
+ menuData.desc = menuInfo.desc;
737
+ }
738
+ if (menuInfo.action_list) {
739
+ const actionListData = menuInfo.action_list;
740
+ if (actionListData.actions && Array.isArray(actionListData.actions)) {
741
+ menuData.action_list = actionListData.actions;
742
+ }
743
+ }
744
+ if (Object.keys(menuData).length > 0) {
745
+ template_card.action_menu = menuData;
746
+ }
619
747
  }
620
748
  }
621
749
  body = {