@alex_rexby/n8n-nodes-max 0.2.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.
@@ -6,11 +6,11 @@ class Max {
6
6
  this.description = {
7
7
  displayName: 'MAX',
8
8
  name: 'max',
9
- icon: 'file:max.png',
9
+ icon: 'file:max.svg',
10
10
  group: ['transform'],
11
11
  version: 1,
12
12
  subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
13
- description: 'Send messages and interact with MAX messenger API',
13
+ description: 'Send messages, manage files, and interact with MAX messenger API',
14
14
  defaults: {
15
15
  name: 'MAX',
16
16
  },
@@ -49,8 +49,8 @@ class Max {
49
49
  value: 'chat',
50
50
  },
51
51
  {
52
- name: 'Subscription',
53
- value: 'subscription',
52
+ name: 'Callback',
53
+ value: 'callback',
54
54
  },
55
55
  ],
56
56
  default: 'message',
@@ -67,16 +67,34 @@ class Max {
67
67
  },
68
68
  options: [
69
69
  {
70
- name: 'Send',
70
+ name: 'Send Text',
71
71
  value: 'send',
72
- description: 'Send a message',
73
- 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',
74
80
  },
75
81
  {
76
82
  name: 'Get',
77
83
  value: 'get',
78
84
  description: 'Get a message by ID',
79
- action: 'Get a message',
85
+ action: 'Get message',
86
+ },
87
+ {
88
+ name: 'Edit',
89
+ value: 'edit',
90
+ description: 'Edit a message',
91
+ action: 'Edit message',
92
+ },
93
+ {
94
+ name: 'Delete',
95
+ value: 'delete',
96
+ description: 'Delete a message',
97
+ action: 'Delete message',
80
98
  },
81
99
  ],
82
100
  default: 'send',
@@ -89,11 +107,12 @@ class Max {
89
107
  displayOptions: {
90
108
  show: {
91
109
  resource: ['message'],
92
- operation: ['send'],
110
+ operation: ['send', 'sendFile'],
93
111
  },
94
112
  },
95
113
  default: '',
96
114
  description: 'The ID of the user to send the message to',
115
+ placeholder: '12345',
97
116
  },
98
117
  {
99
118
  displayName: 'Text',
@@ -113,14 +132,187 @@ class Max {
113
132
  description: 'The text of the message to send',
114
133
  },
115
134
  {
116
- displayName: 'Additional Fields',
117
- 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',
118
310
  type: 'collection',
119
- placeholder: 'Add Field',
311
+ placeholder: 'Add Option',
120
312
  displayOptions: {
121
313
  show: {
122
314
  resource: ['message'],
123
- operation: ['send'],
315
+ operation: ['send', 'sendFile'],
124
316
  },
125
317
  },
126
318
  default: {},
@@ -142,14 +334,6 @@ class Max {
142
334
  default: 'markdown',
143
335
  description: 'Text formatting style',
144
336
  },
145
- {
146
- displayName: 'Inline Keyboard (JSON)',
147
- name: 'inlineKeyboard',
148
- type: 'json',
149
- default: '[[{"text": "Button 1", "callback": "btn1"}, {"text": "Button 2", "callback": "btn2"}]]',
150
- description: 'Inline keyboard buttons as JSON array',
151
- placeholder: '[[{"text": "Button", "callback": "data"}]]',
152
- },
153
337
  {
154
338
  displayName: 'Reply To Message ID',
155
339
  name: 'replyToMessageId',
@@ -157,6 +341,20 @@ class Max {
157
341
  default: '',
158
342
  description: 'Message ID to reply to',
159
343
  },
344
+ {
345
+ displayName: 'Disable Link Preview',
346
+ name: 'disableLinkPreview',
347
+ type: 'boolean',
348
+ default: false,
349
+ description: 'Whether to disable link previews',
350
+ },
351
+ {
352
+ displayName: 'Silent Message',
353
+ name: 'silentMessage',
354
+ type: 'boolean',
355
+ default: false,
356
+ description: 'Send message without notification',
357
+ },
160
358
  ],
161
359
  },
162
360
  {
@@ -167,11 +365,55 @@ class Max {
167
365
  displayOptions: {
168
366
  show: {
169
367
  resource: ['message'],
170
- operation: ['get'],
368
+ operation: ['get', 'delete'],
369
+ },
370
+ },
371
+ default: '',
372
+ description: 'The ID of the message',
373
+ },
374
+ {
375
+ displayName: 'Message ID',
376
+ name: 'messageIdEdit',
377
+ type: 'string',
378
+ required: true,
379
+ displayOptions: {
380
+ show: {
381
+ resource: ['message'],
382
+ operation: ['edit'],
383
+ },
384
+ },
385
+ default: '',
386
+ description: 'The ID of the message to edit',
387
+ },
388
+ {
389
+ displayName: 'New Text',
390
+ name: 'newText',
391
+ type: 'string',
392
+ required: true,
393
+ typeOptions: {
394
+ rows: 4,
395
+ },
396
+ displayOptions: {
397
+ show: {
398
+ resource: ['message'],
399
+ operation: ['edit'],
171
400
  },
172
401
  },
173
402
  default: '',
174
- description: 'The ID of the message to retrieve',
403
+ description: 'New text for the message',
404
+ },
405
+ {
406
+ displayName: 'Delete For All',
407
+ name: 'deleteForAll',
408
+ type: 'boolean',
409
+ displayOptions: {
410
+ show: {
411
+ resource: ['message'],
412
+ operation: ['delete'],
413
+ },
414
+ },
415
+ default: false,
416
+ description: 'Whether to delete for all users (requires admin rights)',
175
417
  },
176
418
  {
177
419
  displayName: 'Operation',
@@ -228,36 +470,33 @@ class Max {
228
470
  description: 'The ID of the chat to update',
229
471
  },
230
472
  {
231
- displayName: 'Update Fields',
232
- name: 'updateFields',
233
- type: 'collection',
234
- placeholder: 'Add Field',
473
+ displayName: 'Title',
474
+ name: 'chatTitle',
475
+ type: 'string',
235
476
  displayOptions: {
236
477
  show: {
237
478
  resource: ['chat'],
238
479
  operation: ['update'],
239
480
  },
240
481
  },
241
- default: {},
242
- options: [
243
- {
244
- displayName: 'Title',
245
- name: 'title',
246
- type: 'string',
247
- default: '',
248
- description: 'New chat title',
249
- },
250
- {
251
- displayName: 'Description',
252
- name: 'description',
253
- type: 'string',
254
- typeOptions: {
255
- rows: 3,
256
- },
257
- default: '',
258
- 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'],
259
496
  },
260
- ],
497
+ },
498
+ default: '',
499
+ description: 'New chat description',
261
500
  },
262
501
  {
263
502
  displayName: 'Operation',
@@ -266,74 +505,95 @@ class Max {
266
505
  noDataExpression: true,
267
506
  displayOptions: {
268
507
  show: {
269
- resource: ['subscription'],
508
+ resource: ['callback'],
270
509
  },
271
510
  },
272
511
  options: [
273
512
  {
274
- name: 'Create',
275
- value: 'create',
276
- description: 'Create webhook subscription',
277
- action: 'Create webhook subscription',
513
+ name: 'Answer',
514
+ value: 'answer',
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',
278
523
  },
279
524
  ],
280
- default: 'create',
525
+ default: 'answer',
281
526
  },
282
527
  {
283
- displayName: 'Webhook URL',
284
- name: 'webhookUrl',
528
+ displayName: 'Callback Query ID',
529
+ name: 'callbackQueryId',
285
530
  type: 'string',
286
531
  required: true,
287
532
  displayOptions: {
288
533
  show: {
289
- resource: ['subscription'],
290
- operation: ['create'],
534
+ resource: ['callback'],
535
+ operation: ['answer', 'answerAndSend'],
291
536
  },
292
537
  },
293
- default: '',
294
- description: 'The HTTPS URL where MAX will send updates',
295
- placeholder: 'https://your-domain.com/webhook',
538
+ default: '={{ $json.event.callback_query_id }}',
539
+ description: 'ID of the callback query',
296
540
  },
297
541
  {
298
- displayName: 'Update Types',
299
- name: 'updateTypes',
300
- type: 'multiOptions',
301
- required: true,
542
+ displayName: 'Notification Text',
543
+ name: 'callbackText',
544
+ type: 'string',
302
545
  displayOptions: {
303
546
  show: {
304
- resource: ['subscription'],
305
- operation: ['create'],
547
+ resource: ['callback'],
548
+ operation: ['answer', 'answerAndSend'],
306
549
  },
307
550
  },
308
- options: [
309
- {
310
- name: 'Message Created',
311
- value: 'message_created',
312
- },
313
- {
314
- name: 'Message Callback',
315
- value: 'message_callback',
551
+ default: '',
552
+ description: 'Text to show in notification',
553
+ },
554
+ {
555
+ displayName: 'Show Alert',
556
+ name: 'showAlert',
557
+ type: 'boolean',
558
+ displayOptions: {
559
+ show: {
560
+ resource: ['callback'],
561
+ operation: ['answer', 'answerAndSend'],
316
562
  },
317
- {
318
- name: 'Bot Started',
319
- value: 'bot_started',
563
+ },
564
+ default: false,
565
+ description: 'Whether to show alert instead of notification',
566
+ },
567
+ {
568
+ displayName: 'User ID',
569
+ name: 'callbackUserId',
570
+ type: 'string',
571
+ required: true,
572
+ displayOptions: {
573
+ show: {
574
+ resource: ['callback'],
575
+ operation: ['answerAndSend'],
320
576
  },
321
- ],
322
- default: ['message_created'],
323
- description: 'Types of updates to receive',
577
+ },
578
+ default: '={{ $json.event.user_id }}',
579
+ description: 'User ID to send message to',
324
580
  },
325
581
  {
326
- displayName: 'Secret',
327
- name: 'secret',
582
+ displayName: 'Message Text',
583
+ name: 'callbackMessageText',
328
584
  type: 'string',
585
+ required: true,
586
+ typeOptions: {
587
+ rows: 4,
588
+ },
329
589
  displayOptions: {
330
590
  show: {
331
- resource: ['subscription'],
332
- operation: ['create'],
591
+ resource: ['callback'],
592
+ operation: ['answerAndSend'],
333
593
  },
334
594
  },
335
595
  default: '',
336
- description: 'Optional secret for webhook verification',
596
+ description: 'Text of the message to send',
337
597
  },
338
598
  ],
339
599
  };
@@ -349,16 +609,143 @@ class Max {
349
609
  if (operation === 'send') {
350
610
  const userId = this.getNodeParameter('userId', i);
351
611
  const text = this.getNodeParameter('text', i);
352
- const additionalFields = this.getNodeParameter('additionalFields', i);
612
+ const addButtons = this.getNodeParameter('addButtons', i);
613
+ const additionalOptions = this.getNodeParameter('additionalOptions', i);
353
614
  const body = { text };
354
- if (additionalFields.format) {
355
- body.format = additionalFields.format;
615
+ if (additionalOptions.format) {
616
+ body.format = additionalOptions.format;
617
+ }
618
+ if (additionalOptions.replyToMessageId) {
619
+ body.reply_to_message_id = additionalOptions.replyToMessageId;
356
620
  }
357
- if (additionalFields.inlineKeyboard) {
358
- body.inline_keyboard = additionalFields.inlineKeyboard;
621
+ if (additionalOptions.disableLinkPreview !== undefined) {
622
+ body.disable_link_preview = additionalOptions.disableLinkPreview;
359
623
  }
360
- if (additionalFields.replyToMessageId) {
361
- body.reply_to_message_id = additionalFields.replyToMessageId;
624
+ if (additionalOptions.silentMessage !== undefined) {
625
+ body.notify = !additionalOptions.silentMessage;
626
+ }
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
+ }
662
+ }
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
+ }
362
749
  }
363
750
  const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
364
751
  method: 'POST',
@@ -377,6 +764,38 @@ class Max {
377
764
  });
378
765
  returnData.push({ json: responseData });
379
766
  }
767
+ if (operation === 'edit') {
768
+ const messageId = this.getNodeParameter('messageIdEdit', i);
769
+ const newText = this.getNodeParameter('newText', i);
770
+ const body = {
771
+ message_id: messageId,
772
+ text: newText,
773
+ };
774
+ const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
775
+ method: 'PUT',
776
+ url: 'https://platform-api.max.ru/messages',
777
+ body,
778
+ json: true,
779
+ });
780
+ returnData.push({ json: responseData });
781
+ }
782
+ if (operation === 'delete') {
783
+ const messageId = this.getNodeParameter('messageId', i);
784
+ const deleteForAll = this.getNodeParameter('deleteForAll', i);
785
+ const body = {
786
+ message_id: messageId,
787
+ };
788
+ if (deleteForAll) {
789
+ body.for_all = true;
790
+ }
791
+ const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
792
+ method: 'DELETE',
793
+ url: 'https://platform-api.max.ru/messages',
794
+ body,
795
+ json: true,
796
+ });
797
+ returnData.push({ json: responseData });
798
+ }
380
799
  }
381
800
  if (resource === 'bot' && operation === 'getInfo') {
382
801
  const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
@@ -388,33 +807,75 @@ class Max {
388
807
  }
389
808
  if (resource === 'chat' && operation === 'update') {
390
809
  const chatId = this.getNodeParameter('chatId', i);
391
- 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;
392
817
  const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
393
818
  method: 'PATCH',
394
819
  url: `https://platform-api.max.ru/chats/${chatId}`,
395
- body: updateFields,
820
+ body,
396
821
  json: true,
397
822
  });
398
823
  returnData.push({ json: responseData });
399
824
  }
400
- if (resource === 'subscription' && operation === 'create') {
401
- const webhookUrl = this.getNodeParameter('webhookUrl', i);
402
- const updateTypes = this.getNodeParameter('updateTypes', i);
403
- const secret = this.getNodeParameter('secret', i);
404
- const body = {
405
- url: webhookUrl,
406
- update_types: updateTypes,
407
- };
408
- if (secret) {
409
- 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 });
410
878
  }
411
- const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'maxApi', {
412
- method: 'POST',
413
- url: 'https://platform-api.max.ru/subscriptions',
414
- body,
415
- json: true,
416
- });
417
- returnData.push({ json: responseData });
418
879
  }
419
880
  }
420
881
  catch (error) {