@alex_rexby/n8n-nodes-max 0.3.0 → 0.4.1

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.
@@ -40,10 +40,6 @@ class Max {
40
40
  name: 'Message',
41
41
  value: 'message',
42
42
  },
43
- {
44
- name: 'File',
45
- value: 'file',
46
- },
47
43
  {
48
44
  name: 'Bot',
49
45
  value: 'bot',
@@ -56,10 +52,6 @@ class Max {
56
52
  name: 'Callback',
57
53
  value: 'callback',
58
54
  },
59
- {
60
- name: 'Subscription',
61
- value: 'subscription',
62
- },
63
55
  ],
64
56
  default: 'message',
65
57
  },
@@ -75,28 +67,34 @@ class Max {
75
67
  },
76
68
  options: [
77
69
  {
78
- name: 'Send',
70
+ name: 'Send Text',
79
71
  value: 'send',
80
- description: 'Send a message',
81
- action: 'Send a message',
72
+ description: 'Send a text message',
73
+ action: 'Send text message',
74
+ },
75
+ {
76
+ name: 'Send File',
77
+ value: 'sendFile',
78
+ description: 'Send a file with optional text',
79
+ action: 'Send file',
82
80
  },
83
81
  {
84
82
  name: 'Get',
85
83
  value: 'get',
86
84
  description: 'Get a message by ID',
87
- action: 'Get a message',
85
+ action: 'Get message',
88
86
  },
89
87
  {
90
88
  name: 'Edit',
91
89
  value: 'edit',
92
90
  description: 'Edit a message',
93
- action: 'Edit a message',
91
+ action: 'Edit message',
94
92
  },
95
93
  {
96
94
  name: 'Delete',
97
95
  value: 'delete',
98
96
  description: 'Delete a message',
99
- action: 'Delete a message',
97
+ action: 'Delete message',
100
98
  },
101
99
  ],
102
100
  default: 'send',
@@ -109,11 +107,12 @@ class Max {
109
107
  displayOptions: {
110
108
  show: {
111
109
  resource: ['message'],
112
- operation: ['send'],
110
+ operation: ['send', 'sendFile'],
113
111
  },
114
112
  },
115
113
  default: '',
116
114
  description: 'The ID of the user to send the message to',
115
+ placeholder: '12345',
117
116
  },
118
117
  {
119
118
  displayName: 'Text',
@@ -133,14 +132,187 @@ class Max {
133
132
  description: 'The text of the message to send',
134
133
  },
135
134
  {
136
- displayName: 'Additional Fields',
137
- name: 'additionalFields',
135
+ displayName: 'Input Data Field Name',
136
+ name: 'binaryPropertyName',
137
+ type: 'string',
138
+ required: true,
139
+ displayOptions: {
140
+ show: {
141
+ resource: ['message'],
142
+ operation: ['sendFile'],
143
+ },
144
+ },
145
+ default: 'data',
146
+ description: 'Name of the binary property containing the file',
147
+ },
148
+ {
149
+ displayName: 'Caption (Optional)',
150
+ name: 'caption',
151
+ type: 'string',
152
+ typeOptions: {
153
+ rows: 3,
154
+ },
155
+ displayOptions: {
156
+ show: {
157
+ resource: ['message'],
158
+ operation: ['sendFile'],
159
+ },
160
+ },
161
+ default: '',
162
+ description: 'Text caption for the file',
163
+ },
164
+ {
165
+ displayName: 'Add Buttons',
166
+ name: 'addButtons',
167
+ type: 'boolean',
168
+ displayOptions: {
169
+ show: {
170
+ resource: ['message'],
171
+ operation: ['send', 'sendFile'],
172
+ },
173
+ },
174
+ default: false,
175
+ description: 'Whether to add inline keyboard buttons',
176
+ },
177
+ {
178
+ displayName: 'Button Mode',
179
+ name: 'buttonMode',
180
+ type: 'options',
181
+ displayOptions: {
182
+ show: {
183
+ resource: ['message'],
184
+ operation: ['send', 'sendFile'],
185
+ addButtons: [true],
186
+ },
187
+ },
188
+ options: [
189
+ {
190
+ name: 'Simple (Rows of Buttons)',
191
+ value: 'simple',
192
+ },
193
+ {
194
+ name: 'Advanced (JSON)',
195
+ value: 'json',
196
+ },
197
+ ],
198
+ default: 'simple',
199
+ description: 'How to configure buttons',
200
+ },
201
+ {
202
+ displayName: 'Buttons',
203
+ name: 'buttons',
204
+ type: 'fixedCollection',
205
+ typeOptions: {
206
+ multipleValues: true,
207
+ },
208
+ displayOptions: {
209
+ show: {
210
+ resource: ['message'],
211
+ operation: ['send', 'sendFile'],
212
+ addButtons: [true],
213
+ buttonMode: ['simple'],
214
+ },
215
+ },
216
+ default: {},
217
+ placeholder: 'Add Button Row',
218
+ options: [
219
+ {
220
+ name: 'row',
221
+ displayName: 'Button Row',
222
+ values: [
223
+ {
224
+ displayName: 'Buttons in Row',
225
+ name: 'buttonsInRow',
226
+ type: 'fixedCollection',
227
+ typeOptions: {
228
+ multipleValues: true,
229
+ },
230
+ default: {},
231
+ options: [
232
+ {
233
+ name: 'button',
234
+ displayName: 'Button',
235
+ values: [
236
+ {
237
+ displayName: 'Button Text',
238
+ name: 'text',
239
+ type: 'string',
240
+ default: '',
241
+ description: 'Text on the button',
242
+ },
243
+ {
244
+ displayName: 'Button Type',
245
+ name: 'type',
246
+ type: 'options',
247
+ options: [
248
+ {
249
+ name: 'Callback (Action)',
250
+ value: 'callback',
251
+ },
252
+ {
253
+ name: 'Link (URL)',
254
+ value: 'link',
255
+ },
256
+ ],
257
+ default: 'callback',
258
+ },
259
+ {
260
+ displayName: 'Callback Data',
261
+ name: 'callback',
262
+ type: 'string',
263
+ displayOptions: {
264
+ show: {
265
+ type: ['callback'],
266
+ },
267
+ },
268
+ default: '',
269
+ description: 'Data to receive when button clicked',
270
+ },
271
+ {
272
+ displayName: 'URL',
273
+ name: 'link',
274
+ type: 'string',
275
+ displayOptions: {
276
+ show: {
277
+ type: ['link'],
278
+ },
279
+ },
280
+ default: '',
281
+ description: 'URL to open',
282
+ },
283
+ ],
284
+ },
285
+ ],
286
+ },
287
+ ],
288
+ },
289
+ ],
290
+ },
291
+ {
292
+ displayName: 'Inline Keyboard (JSON)',
293
+ name: 'inlineKeyboard',
294
+ type: 'json',
295
+ displayOptions: {
296
+ show: {
297
+ resource: ['message'],
298
+ operation: ['send', 'sendFile'],
299
+ addButtons: [true],
300
+ buttonMode: ['json'],
301
+ },
302
+ },
303
+ default: '[[{"text": "Button 1", "callback": "btn1"}]]',
304
+ description: 'Inline keyboard buttons as JSON array',
305
+ placeholder: '[[{"text": "Button", "callback": "data"}]]',
306
+ },
307
+ {
308
+ displayName: 'Additional Options',
309
+ name: 'additionalOptions',
138
310
  type: 'collection',
139
- placeholder: 'Add Field',
311
+ placeholder: 'Add Option',
140
312
  displayOptions: {
141
313
  show: {
142
314
  resource: ['message'],
143
- operation: ['send'],
315
+ operation: ['send', 'sendFile'],
144
316
  },
145
317
  },
146
318
  default: {},
@@ -162,14 +334,6 @@ class Max {
162
334
  default: 'markdown',
163
335
  description: 'Text formatting style',
164
336
  },
165
- {
166
- displayName: 'Inline Keyboard (JSON)',
167
- name: 'inlineKeyboard',
168
- type: 'json',
169
- default: '[[{"text": "Button 1", "callback": "btn1"}]]',
170
- description: 'Inline keyboard buttons as JSON array',
171
- placeholder: '[[{"text": "Button", "callback": "data"}]]',
172
- },
173
337
  {
174
338
  displayName: 'Reply To Message ID',
175
339
  name: 'replyToMessageId',
@@ -185,19 +349,11 @@ class Max {
185
349
  description: 'Whether to disable link previews',
186
350
  },
187
351
  {
188
- displayName: 'Notify',
189
- name: 'notify',
352
+ displayName: 'Silent Message',
353
+ name: 'silentMessage',
190
354
  type: 'boolean',
191
- default: true,
192
- description: 'Whether to send notification',
193
- },
194
- {
195
- displayName: 'Attachments (JSON)',
196
- name: 'attachments',
197
- type: 'json',
198
- default: '',
199
- description: 'Attachments as JSON array (from uploaded files)',
200
- placeholder: '[{"type": "image", "file_id": "xyz"}]',
355
+ default: false,
356
+ description: 'Send message without notification',
201
357
  },
202
358
  ],
203
359
  },
@@ -246,45 +402,6 @@ class Max {
246
402
  default: '',
247
403
  description: 'New text for the message',
248
404
  },
249
- {
250
- displayName: 'Additional Fields',
251
- name: 'editFields',
252
- type: 'collection',
253
- placeholder: 'Add Field',
254
- displayOptions: {
255
- show: {
256
- resource: ['message'],
257
- operation: ['edit'],
258
- },
259
- },
260
- default: {},
261
- options: [
262
- {
263
- displayName: 'Format',
264
- name: 'format',
265
- type: 'options',
266
- options: [
267
- {
268
- name: 'Markdown',
269
- value: 'markdown',
270
- },
271
- {
272
- name: 'HTML',
273
- value: 'html',
274
- },
275
- ],
276
- default: 'markdown',
277
- description: 'Text formatting style',
278
- },
279
- {
280
- displayName: 'Inline Keyboard (JSON)',
281
- name: 'inlineKeyboard',
282
- type: 'json',
283
- default: '',
284
- description: 'Updated inline keyboard',
285
- },
286
- ],
287
- },
288
405
  {
289
406
  displayName: 'Delete For All',
290
407
  name: 'deleteForAll',
@@ -298,72 +415,6 @@ class Max {
298
415
  default: false,
299
416
  description: 'Whether to delete for all users (requires admin rights)',
300
417
  },
301
- {
302
- displayName: 'Operation',
303
- name: 'operation',
304
- type: 'options',
305
- noDataExpression: true,
306
- displayOptions: {
307
- show: {
308
- resource: ['file'],
309
- },
310
- },
311
- options: [
312
- {
313
- name: 'Upload',
314
- value: 'upload',
315
- description: 'Upload a file to MAX',
316
- action: 'Upload a file',
317
- },
318
- ],
319
- default: 'upload',
320
- },
321
- {
322
- displayName: 'File Type',
323
- name: 'fileType',
324
- type: 'options',
325
- required: true,
326
- displayOptions: {
327
- show: {
328
- resource: ['file'],
329
- operation: ['upload'],
330
- },
331
- },
332
- options: [
333
- {
334
- name: 'Image',
335
- value: 'image',
336
- },
337
- {
338
- name: 'Video',
339
- value: 'video',
340
- },
341
- {
342
- name: 'Audio',
343
- value: 'audio',
344
- },
345
- {
346
- name: 'File',
347
- value: 'file',
348
- },
349
- ],
350
- default: 'image',
351
- description: 'Type of file to upload',
352
- },
353
- {
354
- displayName: 'Input Data Field Name',
355
- name: 'binaryPropertyName',
356
- type: 'string',
357
- required: true,
358
- displayOptions: {
359
- show: {
360
- resource: ['file'],
361
- operation: ['upload'],
362
- },
363
- },
364
- default: 'data',
365
- description: 'The name of the input field containing the file to upload',
366
- },
367
418
  {
368
419
  displayName: 'Operation',
369
420
  name: 'operation',
@@ -419,36 +470,33 @@ class Max {
419
470
  description: 'The ID of the chat to update',
420
471
  },
421
472
  {
422
- displayName: 'Update Fields',
423
- name: 'updateFields',
424
- type: 'collection',
425
- placeholder: 'Add Field',
473
+ displayName: 'Title',
474
+ name: 'chatTitle',
475
+ type: 'string',
426
476
  displayOptions: {
427
477
  show: {
428
478
  resource: ['chat'],
429
479
  operation: ['update'],
430
480
  },
431
481
  },
432
- default: {},
433
- options: [
434
- {
435
- displayName: 'Title',
436
- name: 'title',
437
- type: 'string',
438
- default: '',
439
- description: 'New chat title',
440
- },
441
- {
442
- displayName: 'Description',
443
- name: 'description',
444
- type: 'string',
445
- typeOptions: {
446
- rows: 3,
447
- },
448
- default: '',
449
- description: 'New chat description',
482
+ default: '',
483
+ description: 'New chat title',
484
+ },
485
+ {
486
+ displayName: 'Description',
487
+ name: 'chatDescription',
488
+ type: 'string',
489
+ typeOptions: {
490
+ rows: 3,
491
+ },
492
+ displayOptions: {
493
+ show: {
494
+ resource: ['chat'],
495
+ operation: ['update'],
450
496
  },
451
- ],
497
+ },
498
+ default: '',
499
+ description: 'New chat description',
452
500
  },
453
501
  {
454
502
  displayName: 'Operation',
@@ -464,8 +512,14 @@ class Max {
464
512
  {
465
513
  name: 'Answer',
466
514
  value: 'answer',
467
- description: 'Answer callback query from inline button',
468
- action: 'Answer callback query',
515
+ description: 'Answer callback query (just notification)',
516
+ action: 'Answer callback',
517
+ },
518
+ {
519
+ name: 'Answer and Send Message',
520
+ value: 'answerAndSend',
521
+ description: 'Answer callback and send a new message',
522
+ action: 'Answer and send message',
469
523
  },
470
524
  ],
471
525
  default: 'answer',
@@ -478,20 +532,20 @@ class Max {
478
532
  displayOptions: {
479
533
  show: {
480
534
  resource: ['callback'],
481
- operation: ['answer'],
535
+ operation: ['answer', 'answerAndSend'],
482
536
  },
483
537
  },
484
538
  default: '={{ $json.event.callback_query_id }}',
485
539
  description: 'ID of the callback query',
486
540
  },
487
541
  {
488
- displayName: 'Text',
542
+ displayName: 'Notification Text',
489
543
  name: 'callbackText',
490
544
  type: 'string',
491
545
  displayOptions: {
492
546
  show: {
493
547
  resource: ['callback'],
494
- operation: ['answer'],
548
+ operation: ['answer', 'answerAndSend'],
495
549
  },
496
550
  },
497
551
  default: '',
@@ -504,87 +558,42 @@ class Max {
504
558
  displayOptions: {
505
559
  show: {
506
560
  resource: ['callback'],
507
- operation: ['answer'],
561
+ operation: ['answer', 'answerAndSend'],
508
562
  },
509
563
  },
510
564
  default: false,
511
565
  description: 'Whether to show alert instead of notification',
512
566
  },
513
567
  {
514
- displayName: 'Operation',
515
- name: 'operation',
516
- type: 'options',
517
- noDataExpression: true,
518
- displayOptions: {
519
- show: {
520
- resource: ['subscription'],
521
- },
522
- },
523
- options: [
524
- {
525
- name: 'Create',
526
- value: 'create',
527
- description: 'Create webhook subscription',
528
- action: 'Create webhook subscription',
529
- },
530
- ],
531
- default: 'create',
532
- },
533
- {
534
- displayName: 'Webhook URL',
535
- name: 'webhookUrl',
568
+ displayName: 'User ID',
569
+ name: 'callbackUserId',
536
570
  type: 'string',
537
571
  required: true,
538
572
  displayOptions: {
539
573
  show: {
540
- resource: ['subscription'],
541
- operation: ['create'],
574
+ resource: ['callback'],
575
+ operation: ['answerAndSend'],
542
576
  },
543
577
  },
544
- default: '',
545
- description: 'The HTTPS URL where MAX will send updates',
546
- placeholder: 'https://your-domain.com/webhook',
578
+ default: '={{ $json.event.user_id }}',
579
+ description: 'User ID to send message to',
547
580
  },
548
581
  {
549
- displayName: 'Update Types',
550
- name: 'updateTypes',
551
- type: 'multiOptions',
582
+ displayName: 'Message Text',
583
+ name: 'callbackMessageText',
584
+ type: 'string',
552
585
  required: true,
553
- displayOptions: {
554
- show: {
555
- resource: ['subscription'],
556
- operation: ['create'],
557
- },
586
+ typeOptions: {
587
+ rows: 4,
558
588
  },
559
- options: [
560
- {
561
- name: 'Message Created',
562
- value: 'message_created',
563
- },
564
- {
565
- name: 'Message Callback',
566
- value: 'message_callback',
567
- },
568
- {
569
- name: 'Bot Started',
570
- value: 'bot_started',
571
- },
572
- ],
573
- default: ['message_created'],
574
- description: 'Types of updates to receive',
575
- },
576
- {
577
- displayName: 'Secret',
578
- name: 'secret',
579
- type: 'string',
580
589
  displayOptions: {
581
590
  show: {
582
- resource: ['subscription'],
583
- operation: ['create'],
591
+ resource: ['callback'],
592
+ operation: ['answerAndSend'],
584
593
  },
585
594
  },
586
595
  default: '',
587
- description: 'Optional secret for webhook verification',
596
+ description: 'Text of the message to send',
588
597
  },
589
598
  ],
590
599
  };
@@ -600,25 +609,143 @@ class Max {
600
609
  if (operation === 'send') {
601
610
  const userId = this.getNodeParameter('userId', i);
602
611
  const text = this.getNodeParameter('text', i);
603
- const additionalFields = this.getNodeParameter('additionalFields', i);
612
+ const addButtons = this.getNodeParameter('addButtons', i);
613
+ const additionalOptions = this.getNodeParameter('additionalOptions', i);
604
614
  const body = { text };
605
- if (additionalFields.format) {
606
- body.format = additionalFields.format;
615
+ if (additionalOptions.format) {
616
+ body.format = additionalOptions.format;
607
617
  }
608
- if (additionalFields.inlineKeyboard) {
609
- body.inline_keyboard = additionalFields.inlineKeyboard;
618
+ if (additionalOptions.replyToMessageId) {
619
+ body.reply_to_message_id = additionalOptions.replyToMessageId;
610
620
  }
611
- if (additionalFields.replyToMessageId) {
612
- body.reply_to_message_id = additionalFields.replyToMessageId;
621
+ if (additionalOptions.disableLinkPreview !== undefined) {
622
+ body.disable_link_preview = additionalOptions.disableLinkPreview;
613
623
  }
614
- if (additionalFields.disableLinkPreview !== undefined) {
615
- body.disable_link_preview = additionalFields.disableLinkPreview;
624
+ if (additionalOptions.silentMessage !== undefined) {
625
+ body.notify = !additionalOptions.silentMessage;
616
626
  }
617
- if (additionalFields.notify !== undefined) {
618
- body.notify = additionalFields.notify;
627
+ if (addButtons) {
628
+ const buttonMode = this.getNodeParameter('buttonMode', i);
629
+ if (buttonMode === 'simple') {
630
+ const buttons = this.getNodeParameter('buttons', i);
631
+ const keyboard = [];
632
+ if (buttons.row && buttons.row.length > 0) {
633
+ for (const row of buttons.row) {
634
+ const buttonRow = [];
635
+ if (row.buttonsInRow && row.buttonsInRow.button) {
636
+ for (const btn of row.buttonsInRow.button) {
637
+ const button = { text: btn.text };
638
+ if (btn.type === 'callback') {
639
+ button.callback = btn.callback;
640
+ }
641
+ else if (btn.type === 'link') {
642
+ button.link = btn.link;
643
+ }
644
+ buttonRow.push(button);
645
+ }
646
+ }
647
+ if (buttonRow.length > 0) {
648
+ keyboard.push(buttonRow);
649
+ }
650
+ }
651
+ }
652
+ if (keyboard.length > 0) {
653
+ body.inline_keyboard = keyboard;
654
+ }
655
+ }
656
+ else {
657
+ const inlineKeyboard = this.getNodeParameter('inlineKeyboard', i);
658
+ if (inlineKeyboard) {
659
+ body.inline_keyboard = JSON.parse(inlineKeyboard);
660
+ }
661
+ }
619
662
  }
620
- if (additionalFields.attachments) {
621
- body.attachments = additionalFields.attachments;
663
+ const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
664
+ method: 'POST',
665
+ url: `https://platform-api.max.ru/messages?user_id=${userId}`,
666
+ body,
667
+ json: true,
668
+ });
669
+ returnData.push({ json: responseData });
670
+ }
671
+ if (operation === 'sendFile') {
672
+ const userId = this.getNodeParameter('userId', i);
673
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
674
+ const caption = this.getNodeParameter('caption', i);
675
+ const addButtons = this.getNodeParameter('addButtons', i);
676
+ const additionalOptions = this.getNodeParameter('additionalOptions', i);
677
+ const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
678
+ const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
679
+ let fileType = 'file';
680
+ if (binaryData.mimeType) {
681
+ if (binaryData.mimeType.startsWith('image/'))
682
+ fileType = 'image';
683
+ else if (binaryData.mimeType.startsWith('video/'))
684
+ fileType = 'video';
685
+ else if (binaryData.mimeType.startsWith('audio/'))
686
+ fileType = 'audio';
687
+ }
688
+ const uploadResponse = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
689
+ method: 'POST',
690
+ url: `https://platform-api.max.ru/uploads?type=${fileType}`,
691
+ body: buffer,
692
+ headers: {
693
+ 'Content-Type': binaryData.mimeType || 'application/octet-stream',
694
+ },
695
+ json: false,
696
+ });
697
+ const uploadData = typeof uploadResponse === 'string' ? JSON.parse(uploadResponse) : uploadResponse;
698
+ const body = {
699
+ text: caption || '',
700
+ attachments: [{
701
+ type: fileType,
702
+ file_id: uploadData.file_id,
703
+ }],
704
+ };
705
+ if (additionalOptions.format) {
706
+ body.format = additionalOptions.format;
707
+ }
708
+ if (additionalOptions.replyToMessageId) {
709
+ body.reply_to_message_id = additionalOptions.replyToMessageId;
710
+ }
711
+ if (additionalOptions.silentMessage !== undefined) {
712
+ body.notify = !additionalOptions.silentMessage;
713
+ }
714
+ if (addButtons) {
715
+ const buttonMode = this.getNodeParameter('buttonMode', i);
716
+ if (buttonMode === 'simple') {
717
+ const buttons = this.getNodeParameter('buttons', i);
718
+ const keyboard = [];
719
+ if (buttons.row && buttons.row.length > 0) {
720
+ for (const row of buttons.row) {
721
+ const buttonRow = [];
722
+ if (row.buttonsInRow && row.buttonsInRow.button) {
723
+ for (const btn of row.buttonsInRow.button) {
724
+ const button = { text: btn.text };
725
+ if (btn.type === 'callback') {
726
+ button.callback = btn.callback;
727
+ }
728
+ else if (btn.type === 'link') {
729
+ button.link = btn.link;
730
+ }
731
+ buttonRow.push(button);
732
+ }
733
+ }
734
+ if (buttonRow.length > 0) {
735
+ keyboard.push(buttonRow);
736
+ }
737
+ }
738
+ }
739
+ if (keyboard.length > 0) {
740
+ body.inline_keyboard = keyboard;
741
+ }
742
+ }
743
+ else {
744
+ const inlineKeyboard = this.getNodeParameter('inlineKeyboard', i);
745
+ if (inlineKeyboard) {
746
+ body.inline_keyboard = JSON.parse(inlineKeyboard);
747
+ }
748
+ }
622
749
  }
623
750
  const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
624
751
  method: 'POST',
@@ -640,17 +767,10 @@ class Max {
640
767
  if (operation === 'edit') {
641
768
  const messageId = this.getNodeParameter('messageIdEdit', i);
642
769
  const newText = this.getNodeParameter('newText', i);
643
- const editFields = this.getNodeParameter('editFields', i);
644
770
  const body = {
645
771
  message_id: messageId,
646
772
  text: newText,
647
773
  };
648
- if (editFields.format) {
649
- body.format = editFields.format;
650
- }
651
- if (editFields.inlineKeyboard) {
652
- body.inline_keyboard = editFields.inlineKeyboard;
653
- }
654
774
  const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
655
775
  method: 'PUT',
656
776
  url: 'https://platform-api.max.ru/messages',
@@ -677,23 +797,6 @@ class Max {
677
797
  returnData.push({ json: responseData });
678
798
  }
679
799
  }
680
- if (resource === 'file' && operation === 'upload') {
681
- const fileType = this.getNodeParameter('fileType', i);
682
- const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
683
- const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
684
- const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
685
- const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
686
- method: 'POST',
687
- url: `https://platform-api.max.ru/uploads?type=${fileType}`,
688
- body: buffer,
689
- headers: {
690
- 'Content-Type': binaryData.mimeType || 'application/octet-stream',
691
- },
692
- json: false,
693
- returnFullResponse: false,
694
- });
695
- returnData.push({ json: typeof responseData === 'string' ? JSON.parse(responseData) : responseData });
696
- }
697
800
  if (resource === 'bot' && operation === 'getInfo') {
698
801
  const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
699
802
  method: 'GET',
@@ -704,54 +807,75 @@ class Max {
704
807
  }
705
808
  if (resource === 'chat' && operation === 'update') {
706
809
  const chatId = this.getNodeParameter('chatId', i);
707
- const updateFields = this.getNodeParameter('updateFields', i);
810
+ const chatTitle = this.getNodeParameter('chatTitle', i);
811
+ const chatDescription = this.getNodeParameter('chatDescription', i);
812
+ const body = {};
813
+ if (chatTitle)
814
+ body.title = chatTitle;
815
+ if (chatDescription)
816
+ body.description = chatDescription;
708
817
  const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
709
818
  method: 'PATCH',
710
819
  url: `https://platform-api.max.ru/chats/${chatId}`,
711
- body: updateFields,
712
- json: true,
713
- });
714
- returnData.push({ json: responseData });
715
- }
716
- if (resource === 'callback' && operation === 'answer') {
717
- const callbackQueryId = this.getNodeParameter('callbackQueryId', i);
718
- const callbackText = this.getNodeParameter('callbackText', i);
719
- const showAlert = this.getNodeParameter('showAlert', i);
720
- const body = {
721
- callback_query_id: callbackQueryId,
722
- };
723
- if (callbackText) {
724
- body.text = callbackText;
725
- }
726
- if (showAlert) {
727
- body.show_alert = true;
728
- }
729
- const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
730
- method: 'POST',
731
- url: 'https://platform-api.max.ru/answers',
732
820
  body,
733
821
  json: true,
734
822
  });
735
823
  returnData.push({ json: responseData });
736
824
  }
737
- if (resource === 'subscription' && operation === 'create') {
738
- const webhookUrl = this.getNodeParameter('webhookUrl', i);
739
- const updateTypes = this.getNodeParameter('updateTypes', i);
740
- const secret = this.getNodeParameter('secret', i);
741
- const body = {
742
- url: webhookUrl,
743
- update_types: updateTypes,
744
- };
745
- if (secret) {
746
- body.secret = secret;
825
+ if (resource === 'callback') {
826
+ if (operation === 'answer') {
827
+ const callbackQueryId = this.getNodeParameter('callbackQueryId', i);
828
+ const callbackText = this.getNodeParameter('callbackText', i);
829
+ const showAlert = this.getNodeParameter('showAlert', i);
830
+ const body = {
831
+ callback_query_id: callbackQueryId,
832
+ };
833
+ if (callbackText) {
834
+ body.text = callbackText;
835
+ }
836
+ if (showAlert) {
837
+ body.show_alert = true;
838
+ }
839
+ const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
840
+ method: 'POST',
841
+ url: 'https://platform-api.max.ru/answers',
842
+ body,
843
+ json: true,
844
+ });
845
+ returnData.push({ json: responseData });
846
+ }
847
+ if (operation === 'answerAndSend') {
848
+ const callbackQueryId = this.getNodeParameter('callbackQueryId', i);
849
+ const callbackText = this.getNodeParameter('callbackText', i);
850
+ const showAlert = this.getNodeParameter('showAlert', i);
851
+ const userId = this.getNodeParameter('callbackUserId', i);
852
+ const messageText = this.getNodeParameter('callbackMessageText', i);
853
+ const answerBody = {
854
+ callback_query_id: callbackQueryId,
855
+ };
856
+ if (callbackText) {
857
+ answerBody.text = callbackText;
858
+ }
859
+ if (showAlert) {
860
+ answerBody.show_alert = true;
861
+ }
862
+ await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
863
+ method: 'POST',
864
+ url: 'https://platform-api.max.ru/answers',
865
+ body: answerBody,
866
+ json: true,
867
+ });
868
+ const messageBody = {
869
+ text: messageText,
870
+ };
871
+ const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
872
+ method: 'POST',
873
+ url: `https://platform-api.max.ru/messages?user_id=${userId}`,
874
+ body: messageBody,
875
+ json: true,
876
+ });
877
+ returnData.push({ json: responseData });
747
878
  }
748
- const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
749
- method: 'POST',
750
- url: 'https://platform-api.max.ru/subscriptions',
751
- body,
752
- json: true,
753
- });
754
- returnData.push({ json: responseData });
755
879
  }
756
880
  }
757
881
  catch (error) {