n8n-nodes-pragma-bitrix24 1.0.0
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.
- package/LICENSE +51 -0
- package/README.md +340 -0
- package/dist/credentials/Bitrix24Api.credentials.js +55 -0
- package/dist/nodes/Bitrix24/Bitrix24.node.js +1410 -0
- package/dist/nodes/Bitrix24/Company.js +17 -0
- package/dist/nodes/Bitrix24/Contact.js +31 -0
- package/dist/nodes/Bitrix24/Deal.js +17 -0
- package/dist/nodes/Bitrix24/Helpers.js +300 -0
- package/dist/nodes/Bitrix24/Lead.js +17 -0
- package/dist/nodes/Bitrix24/SmartProcess.js +1 -0
- package/dist/nodes/Bitrix24/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24/types.js +58 -0
- package/dist/nodes/Bitrix24AI/Bitrix24AI.node.js +205 -0
- package/dist/nodes/Bitrix24App/Bitrix24App.node.js +179 -0
- package/dist/nodes/Bitrix24Auxiliary/Bitrix24Auxiliary.node.js +566 -0
- package/dist/nodes/Bitrix24Booking/Bitrix24Booking.node.js +871 -0
- package/dist/nodes/Bitrix24Calendar/Bitrix24Calendar.node.js +471 -0
- package/dist/nodes/Bitrix24ChatBot/Bitrix24ChatBot.node.js +522 -0
- package/dist/nodes/Bitrix24Commerce/Bitrix24Commerce.node.js +431 -0
- package/dist/nodes/Bitrix24Department/Bitrix24Department.node.js +317 -0
- package/dist/nodes/Bitrix24Disk/Bitrix24Disk.node.js +334 -0
- package/dist/nodes/Bitrix24Document/Bitrix24Document.node.js +280 -0
- package/dist/nodes/Bitrix24Entity/Bitrix24Entity.node.js +263 -0
- package/dist/nodes/Bitrix24Group/Bitrix24Group.node.js +327 -0
- package/dist/nodes/Bitrix24Lists/Bitrix24Lists.node.js +406 -0
- package/dist/nodes/Bitrix24Log/Bitrix24Log.node.js +309 -0
- package/dist/nodes/Bitrix24Mail/Bitrix24Mail.node.js +109 -0
- package/dist/nodes/Bitrix24MessageService/Bitrix24MessageService.node.js +218 -0
- package/dist/nodes/Bitrix24OpenChannels/Bitrix24OpenChannels.node.js +379 -0
- package/dist/nodes/Bitrix24PaySystem/Bitrix24PaySystem.node.js +241 -0
- package/dist/nodes/Bitrix24Pipeline/Bitrix24Pipeline.node.js +553 -0
- package/dist/nodes/Bitrix24Pipeline/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24Sale/Bitrix24Sale.node.js +391 -0
- package/dist/nodes/Bitrix24Scrum/Bitrix24Scrum.node.js +555 -0
- package/dist/nodes/Bitrix24Scrum/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24Sign/Bitrix24Sign.node.js +132 -0
- package/dist/nodes/Bitrix24Social/Bitrix24Social.node.js +224 -0
- package/dist/nodes/Bitrix24Task/Bitrix24Task.node.js +444 -0
- package/dist/nodes/Bitrix24Telephony/Bitrix24Telephony.node.js +511 -0
- package/dist/nodes/Bitrix24Timeman/Bitrix24Timeman.node.js +196 -0
- package/dist/nodes/Bitrix24Tool/Bitrix24Tool.node.js +1035 -0
- package/dist/nodes/Bitrix24Tool/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24Trigger/Bitrix24Trigger.node.js +184 -0
- package/dist/nodes/Bitrix24User/Bitrix24User.node.js +351 -0
- package/dist/nodes/Bitrix24UserField/Bitrix24UserField.node.js +386 -0
- package/dist/nodes/Bitrix24UserField/bitrix24.svg +7 -0
- package/dist/nodes/shared/bitrix24.svg +7 -0
- package/dist/nodes/shared/localization.js +189 -0
- package/dist/nodes/shared/types.js +22 -0
- package/index.js +10 -0
- package/package.json +108 -0
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bitrix24 ChatBot — Нода управления чат-ботами
|
|
4
|
+
*
|
|
5
|
+
* Bitrix24 PRAGMA.by nodes for n8n
|
|
6
|
+
* Профессиональная интеграция с Битрикс24.
|
|
7
|
+
*
|
|
8
|
+
* @author PRAGMA & Азбука Решений
|
|
9
|
+
* @copyright 2026 PRAGMA (https://pragma.by/) & Азбука Решений (https://abc-solution.ru/)
|
|
10
|
+
*
|
|
11
|
+
* Контакты:
|
|
12
|
+
* 🇧🇾 PRAGMA: +375 (44) 702-70-90 | https://pragma.by/
|
|
13
|
+
* 🇷🇺 Азбука Решений: +7 (939) 555-19-60 | https://abc-solution.ru/
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.Bitrix24ChatBot = void 0;
|
|
17
|
+
const Helpers_1 = require("../Bitrix24/Helpers");
|
|
18
|
+
class Bitrix24ChatBot {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.description = {
|
|
21
|
+
displayName: 'Bitrix24 Чат-бот',
|
|
22
|
+
name: 'bitrix24ChatBot',
|
|
23
|
+
icon: 'file:bitrix24.svg',
|
|
24
|
+
group: ['transform'],
|
|
25
|
+
version: 1,
|
|
26
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
27
|
+
description: 'Управление чат-ботами, сообщениями и уведомлениями в Битрикс24',
|
|
28
|
+
defaults: {
|
|
29
|
+
name: 'Bitrix24 Чат-бот',
|
|
30
|
+
},
|
|
31
|
+
inputs: ['main'],
|
|
32
|
+
outputs: ['main'],
|
|
33
|
+
credentials: [
|
|
34
|
+
{
|
|
35
|
+
name: 'bitrix24Api',
|
|
36
|
+
required: false,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
properties: [
|
|
40
|
+
{
|
|
41
|
+
displayName: 'Authentication Method',
|
|
42
|
+
name: 'authMethod',
|
|
43
|
+
type: 'options',
|
|
44
|
+
options: [
|
|
45
|
+
{
|
|
46
|
+
name: 'Saved Credentials',
|
|
47
|
+
value: 'credentials',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'Access Token (Stateless)',
|
|
51
|
+
value: 'token',
|
|
52
|
+
description: 'Use token from an event (e.g. Bot Message) for quick reply without DB.',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
default: 'credentials',
|
|
56
|
+
description: 'Choose how to authenticate',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
displayName: 'Access Token',
|
|
60
|
+
name: 'accessToken',
|
|
61
|
+
type: 'string',
|
|
62
|
+
typeOptions: { password: true },
|
|
63
|
+
default: '',
|
|
64
|
+
displayOptions: { show: { authMethod: ['token'] } },
|
|
65
|
+
required: true,
|
|
66
|
+
description: 'Access Token (from Bitrix24 Trigger)',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
displayName: 'Domain',
|
|
70
|
+
name: 'domain',
|
|
71
|
+
type: 'string',
|
|
72
|
+
default: '',
|
|
73
|
+
displayOptions: { show: { authMethod: ['token'] } },
|
|
74
|
+
required: true,
|
|
75
|
+
description: 'Bitrix24 Domain (e.g. myportal.bitrix24.com)',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
displayName: 'Resource',
|
|
79
|
+
name: 'resource',
|
|
80
|
+
type: 'options',
|
|
81
|
+
noDataExpression: true,
|
|
82
|
+
options: [
|
|
83
|
+
{
|
|
84
|
+
name: 'Bot',
|
|
85
|
+
value: 'bot',
|
|
86
|
+
description: 'Manage Bots (Register/Update)',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'Message',
|
|
90
|
+
value: 'message',
|
|
91
|
+
description: 'Send messages (Bot)',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'Command',
|
|
95
|
+
value: 'command',
|
|
96
|
+
description: 'Manage commands (Slash commands)',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'Chat',
|
|
100
|
+
value: 'chat',
|
|
101
|
+
description: 'Manage chats (Create/Add Users)',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'Notification',
|
|
105
|
+
value: 'notification',
|
|
106
|
+
description: 'Send system notifications',
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
default: 'message',
|
|
110
|
+
required: true,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
displayName: 'Operation',
|
|
114
|
+
name: 'operation',
|
|
115
|
+
type: 'options',
|
|
116
|
+
noDataExpression: true,
|
|
117
|
+
options: [
|
|
118
|
+
// Bot
|
|
119
|
+
{
|
|
120
|
+
name: 'Register',
|
|
121
|
+
value: 'register',
|
|
122
|
+
action: 'Register a new bot',
|
|
123
|
+
displayOptions: { show: { resource: ['bot'] } },
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'Update',
|
|
127
|
+
value: 'update',
|
|
128
|
+
action: 'Update a bot',
|
|
129
|
+
displayOptions: { show: { resource: ['bot'] } },
|
|
130
|
+
},
|
|
131
|
+
// Message
|
|
132
|
+
{
|
|
133
|
+
name: 'Send',
|
|
134
|
+
value: 'send',
|
|
135
|
+
action: 'Send a message',
|
|
136
|
+
displayOptions: { show: { resource: ['message'] } },
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'Update',
|
|
140
|
+
value: 'update',
|
|
141
|
+
action: 'Update a message',
|
|
142
|
+
displayOptions: { show: { resource: ['message'] } },
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: 'Delete',
|
|
146
|
+
value: 'delete',
|
|
147
|
+
action: 'Delete a message',
|
|
148
|
+
displayOptions: { show: { resource: ['message'] } },
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: 'Typing',
|
|
152
|
+
value: 'typing',
|
|
153
|
+
action: 'Send typing notification',
|
|
154
|
+
displayOptions: { show: { resource: ['message'] } },
|
|
155
|
+
},
|
|
156
|
+
// Command
|
|
157
|
+
{
|
|
158
|
+
name: 'Register',
|
|
159
|
+
value: 'register',
|
|
160
|
+
action: 'Register a command',
|
|
161
|
+
displayOptions: { show: { resource: ['command'] } },
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'Delete',
|
|
165
|
+
value: 'delete',
|
|
166
|
+
action: 'Delete a command',
|
|
167
|
+
displayOptions: { show: { resource: ['command'] } },
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'Answer',
|
|
171
|
+
value: 'answer',
|
|
172
|
+
action: 'Answer a command',
|
|
173
|
+
displayOptions: { show: { resource: ['command'] } },
|
|
174
|
+
},
|
|
175
|
+
// Chat
|
|
176
|
+
{
|
|
177
|
+
name: 'Create',
|
|
178
|
+
value: 'create',
|
|
179
|
+
action: 'Create a chat',
|
|
180
|
+
displayOptions: { show: { resource: ['chat'] } },
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'Add User',
|
|
184
|
+
value: 'addUser',
|
|
185
|
+
action: 'Add user to chat',
|
|
186
|
+
displayOptions: { show: { resource: ['chat'] } },
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'Get Users',
|
|
190
|
+
value: 'getUsers', // im.chat.user.list
|
|
191
|
+
action: 'Get chat users',
|
|
192
|
+
displayOptions: { show: { resource: ['chat'] } },
|
|
193
|
+
},
|
|
194
|
+
// Notification
|
|
195
|
+
{
|
|
196
|
+
name: 'Send',
|
|
197
|
+
value: 'send',
|
|
198
|
+
action: 'Send notification',
|
|
199
|
+
displayOptions: { show: { resource: ['notification'] } },
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
default: 'send',
|
|
203
|
+
required: true,
|
|
204
|
+
},
|
|
205
|
+
// ----------------------------------
|
|
206
|
+
// Fields for Bot Register
|
|
207
|
+
// ----------------------------------
|
|
208
|
+
{
|
|
209
|
+
displayName: 'Code',
|
|
210
|
+
name: 'code',
|
|
211
|
+
type: 'string',
|
|
212
|
+
default: '',
|
|
213
|
+
required: true,
|
|
214
|
+
displayOptions: { show: { resource: ['bot'], operation: ['register'] } },
|
|
215
|
+
description: 'Unique code for the bot (e.g. "my_bot")',
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
displayName: 'Type',
|
|
219
|
+
name: 'type',
|
|
220
|
+
type: 'options',
|
|
221
|
+
options: [
|
|
222
|
+
{ name: 'Bot', value: 'B' },
|
|
223
|
+
{ name: 'Human', value: 'H' },
|
|
224
|
+
{ name: 'Openline', value: 'O' },
|
|
225
|
+
{ name: 'Supervisor', value: 'S' },
|
|
226
|
+
],
|
|
227
|
+
default: 'B',
|
|
228
|
+
displayOptions: { show: { resource: ['bot'], operation: ['register'] } },
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
displayName: 'Event Handler URL',
|
|
232
|
+
name: 'eventHandler',
|
|
233
|
+
type: 'string',
|
|
234
|
+
default: '',
|
|
235
|
+
displayOptions: { show: { resource: ['bot'], operation: ['register', 'update'] } }, // Update allows changing url
|
|
236
|
+
description: 'URL to handle bot events (Webhook)',
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
displayName: 'Bot Name',
|
|
240
|
+
name: 'name',
|
|
241
|
+
type: 'string',
|
|
242
|
+
default: '',
|
|
243
|
+
displayOptions: { show: { resource: ['bot', 'chat'], operation: ['register', 'update', 'create'] } },
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
displayName: 'Bot ID',
|
|
247
|
+
name: 'botId',
|
|
248
|
+
type: 'string',
|
|
249
|
+
default: '',
|
|
250
|
+
displayOptions: { show: { resource: ['bot'], operation: ['update'] } },
|
|
251
|
+
description: 'ID of the bot to update',
|
|
252
|
+
},
|
|
253
|
+
// ----------------------------------
|
|
254
|
+
// Fields for Message Send
|
|
255
|
+
// ----------------------------------
|
|
256
|
+
{
|
|
257
|
+
displayName: 'Bot ID (Sender)',
|
|
258
|
+
name: 'botId', // Reuse botId parameter name? Or senderId. imbot.message.add needs BOT_ID
|
|
259
|
+
type: 'string',
|
|
260
|
+
default: '',
|
|
261
|
+
displayOptions: { show: { resource: ['message'], operation: ['send'] } },
|
|
262
|
+
description: 'ID of the bot sending the message',
|
|
263
|
+
required: true,
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
displayName: 'Message ID',
|
|
267
|
+
name: 'messageId',
|
|
268
|
+
type: 'string',
|
|
269
|
+
default: '',
|
|
270
|
+
displayOptions: { show: { resource: ['message'], operation: ['update', 'delete'] } }, // For message manupulation
|
|
271
|
+
required: true,
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
displayName: 'Dialog ID',
|
|
275
|
+
name: 'dialogId',
|
|
276
|
+
type: 'string',
|
|
277
|
+
default: '',
|
|
278
|
+
displayOptions: { show: { resource: ['message'], operation: ['send', 'typing'] } },
|
|
279
|
+
description: 'Chat ID or User ID (e.g. 123 for user, chat123 for chat)',
|
|
280
|
+
required: true,
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
displayName: 'Message',
|
|
284
|
+
name: 'message',
|
|
285
|
+
type: 'string',
|
|
286
|
+
default: '',
|
|
287
|
+
displayOptions: { show: { resource: ['message', 'notification'], operation: ['send', 'update'] } },
|
|
288
|
+
description: 'Message text. Supports BB-codes.',
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
displayName: 'Keyboard (JSON)',
|
|
292
|
+
name: 'keyboard',
|
|
293
|
+
type: 'json',
|
|
294
|
+
default: '',
|
|
295
|
+
displayOptions: { show: { resource: ['message'], operation: ['send', 'update'] } },
|
|
296
|
+
description: 'Buttons. Example: {"BUTTONS": [{"TEXT": "Click Me", "COMMAND": "my_cmd"}]}',
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
displayName: 'Attach (JSON)',
|
|
300
|
+
name: 'vocab',
|
|
301
|
+
type: 'json',
|
|
302
|
+
default: '',
|
|
303
|
+
displayOptions: { show: { resource: ['message'], operation: ['send', 'update'] } },
|
|
304
|
+
description: 'Attachment definition in JSON format',
|
|
305
|
+
},
|
|
306
|
+
// ----------------------------------
|
|
307
|
+
// Fields for Command
|
|
308
|
+
// ----------------------------------
|
|
309
|
+
{
|
|
310
|
+
displayName: 'Command',
|
|
311
|
+
name: 'command',
|
|
312
|
+
type: 'string',
|
|
313
|
+
default: '',
|
|
314
|
+
displayOptions: { show: { resource: ['command'], operation: ['register', 'delete'] } },
|
|
315
|
+
description: 'Command text (e.g. "report")',
|
|
316
|
+
required: true,
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
displayName: 'Command ID',
|
|
320
|
+
name: 'commandId',
|
|
321
|
+
type: 'string',
|
|
322
|
+
default: '',
|
|
323
|
+
displayOptions: { show: { resource: ['command'], operation: ['delete', 'answer'] } },
|
|
324
|
+
required: true,
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
displayName: 'Message ID',
|
|
328
|
+
name: 'messageId',
|
|
329
|
+
type: 'string',
|
|
330
|
+
default: '',
|
|
331
|
+
displayOptions: { show: { resource: ['command'], operation: ['answer'] } },
|
|
332
|
+
description: 'ID of the message to answer to',
|
|
333
|
+
},
|
|
334
|
+
// ----------------------------------
|
|
335
|
+
// Fields for Chat
|
|
336
|
+
// ----------------------------------
|
|
337
|
+
{
|
|
338
|
+
displayName: 'Description',
|
|
339
|
+
name: 'description',
|
|
340
|
+
type: 'string',
|
|
341
|
+
default: '',
|
|
342
|
+
displayOptions: { show: { resource: ['chat', 'bot'], operation: ['create', 'register'] } }, // Bot register also has desc
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
displayName: 'Chat ID',
|
|
346
|
+
name: 'chatId',
|
|
347
|
+
type: 'string',
|
|
348
|
+
default: '',
|
|
349
|
+
displayOptions: { show: { resource: ['chat'], operation: ['addUser'] } },
|
|
350
|
+
required: true,
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
displayName: 'User ID',
|
|
354
|
+
name: 'userId', // Recipient for notification or user to add
|
|
355
|
+
type: 'string',
|
|
356
|
+
default: '',
|
|
357
|
+
displayOptions: { show: { resource: ['chat', 'notification'], operation: ['addUser', 'send'] } },
|
|
358
|
+
required: true,
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
async execute() {
|
|
364
|
+
const items = this.getInputData();
|
|
365
|
+
const returnData = [];
|
|
366
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
367
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
368
|
+
const authMethod = this.getNodeParameter('authMethod', 0);
|
|
369
|
+
for (let i = 0; i < items.length; i++) {
|
|
370
|
+
try {
|
|
371
|
+
let overrideAuth;
|
|
372
|
+
if (authMethod === 'token') {
|
|
373
|
+
overrideAuth = {
|
|
374
|
+
accessToken: this.getNodeParameter('accessToken', i),
|
|
375
|
+
domain: this.getNodeParameter('domain', i),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
let endpoint = '';
|
|
379
|
+
let body = {};
|
|
380
|
+
if (resource === 'bot') {
|
|
381
|
+
if (operation === 'register') {
|
|
382
|
+
endpoint = 'imbot.register';
|
|
383
|
+
body.CODE = this.getNodeParameter('code', i);
|
|
384
|
+
body.TYPE = this.getNodeParameter('type', i);
|
|
385
|
+
body.EVENT_HANDLER = this.getNodeParameter('eventHandler', i, '');
|
|
386
|
+
body.PROPERTIES = {
|
|
387
|
+
NAME: this.getNodeParameter('name', i, ''),
|
|
388
|
+
WORK_POSITION: this.getNodeParameter('description', i, ''),
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
else if (operation === 'update') {
|
|
392
|
+
endpoint = 'imbot.update';
|
|
393
|
+
body.BOT_ID = this.getNodeParameter('botId', i);
|
|
394
|
+
body.EVENT_HANDLER = this.getNodeParameter('eventHandler', i, '');
|
|
395
|
+
const name = this.getNodeParameter('name', i, '');
|
|
396
|
+
const desc = this.getNodeParameter('description', i, '');
|
|
397
|
+
if (name || desc) {
|
|
398
|
+
body.PROPERTIES = {};
|
|
399
|
+
if (name)
|
|
400
|
+
body.PROPERTIES.NAME = name;
|
|
401
|
+
if (desc)
|
|
402
|
+
body.PROPERTIES.WORK_POSITION = desc;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else if (resource === 'message') {
|
|
407
|
+
if (operation === 'send') {
|
|
408
|
+
endpoint = 'imbot.message.add';
|
|
409
|
+
body.BOT_ID = this.getNodeParameter('botId', i);
|
|
410
|
+
body.DIALOG_ID = this.getNodeParameter('dialogId', i);
|
|
411
|
+
body.MESSAGE = this.getNodeParameter('message', i);
|
|
412
|
+
const keyboard = this.getNodeParameter('keyboard', i, '');
|
|
413
|
+
if (keyboard) {
|
|
414
|
+
if (typeof keyboard === 'string')
|
|
415
|
+
body.KEYBOARD = JSON.parse(keyboard);
|
|
416
|
+
else
|
|
417
|
+
body.KEYBOARD = keyboard;
|
|
418
|
+
}
|
|
419
|
+
const attach = this.getNodeParameter('vocab', i, '');
|
|
420
|
+
if (attach) {
|
|
421
|
+
if (typeof attach === 'string')
|
|
422
|
+
body.ATTACH = JSON.parse(attach);
|
|
423
|
+
else
|
|
424
|
+
body.ATTACH = attach;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
else if (operation === 'update') {
|
|
428
|
+
endpoint = 'imbot.message.update';
|
|
429
|
+
body.BOT_ID = this.getNodeParameter('botId', i);
|
|
430
|
+
body.MESSAGE_ID = this.getNodeParameter('messageId', i);
|
|
431
|
+
body.MESSAGE = this.getNodeParameter('message', i);
|
|
432
|
+
const keyboard = this.getNodeParameter('keyboard', i, '');
|
|
433
|
+
if (keyboard) {
|
|
434
|
+
if (typeof keyboard === 'string')
|
|
435
|
+
body.KEYBOARD = JSON.parse(keyboard);
|
|
436
|
+
else
|
|
437
|
+
body.KEYBOARD = keyboard;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
else if (operation === 'delete') {
|
|
441
|
+
endpoint = 'imbot.message.delete';
|
|
442
|
+
body.BOT_ID = this.getNodeParameter('botId', i);
|
|
443
|
+
body.MESSAGE_ID = this.getNodeParameter('messageId', i);
|
|
444
|
+
}
|
|
445
|
+
else if (operation === 'typing') {
|
|
446
|
+
endpoint = 'imbot.chat.sendtyping'; // check docs. actually imbot.chat.sendtyping requires DIALOG_ID
|
|
447
|
+
body.BOT_ID = this.getNodeParameter('botId', i);
|
|
448
|
+
body.DIALOG_ID = this.getNodeParameter('dialogId', i);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else if (resource === 'command') {
|
|
452
|
+
if (operation === 'register') {
|
|
453
|
+
endpoint = 'imbot.command.register';
|
|
454
|
+
// We assume BOT_ID is derived from auth? No, user usually registers command for THEIR bot app.
|
|
455
|
+
// Actually imbot.command.register requires BOT_ID usually.
|
|
456
|
+
// NOTE: Standard OAuth app might restrict which bots it can manage.
|
|
457
|
+
// Let's assume we pass BOT_ID if needed, but often it's implicit for the client.
|
|
458
|
+
// Checking docs: imbot.command.register params: COMMAND, COMMON(Y/N), HIDDEN(Y/N), EXT_BLACKLIST, EXT_CONTEXT, LANG, EVENT_COMMAND_ADD
|
|
459
|
+
// It relates to the APP, but often tied to a bot logic.
|
|
460
|
+
// Wait, imbot.command.register registers a command for the current APPLICATION.
|
|
461
|
+
body.COMMAND = this.getNodeParameter('command', i);
|
|
462
|
+
body.LANG = Array.isArray(body.LANG) ? body.LANG : [{ LANGUAGE_ID: 'en', TITLE: 'Command' }]; // minimalist default
|
|
463
|
+
}
|
|
464
|
+
else if (operation === 'answer') {
|
|
465
|
+
endpoint = 'imbot.command.answer';
|
|
466
|
+
body.COMMAND_ID = this.getNodeParameter('commandId', i);
|
|
467
|
+
body.MESSAGE_ID = this.getNodeParameter('messageId', i);
|
|
468
|
+
body.MESSAGE = this.getNodeParameter('message', i, '');
|
|
469
|
+
}
|
|
470
|
+
else if (operation === 'delete') {
|
|
471
|
+
endpoint = 'imbot.command.unregister';
|
|
472
|
+
body.COMMAND_ID = this.getNodeParameter('commandId', i);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
else if (resource === 'chat') {
|
|
476
|
+
if (operation === 'create') {
|
|
477
|
+
endpoint = 'im.chat.add';
|
|
478
|
+
body.TITLE = this.getNodeParameter('name', i, '');
|
|
479
|
+
body.DESCRIPTION = this.getNodeParameter('description', i, '');
|
|
480
|
+
}
|
|
481
|
+
else if (operation === 'addUser') {
|
|
482
|
+
endpoint = 'im.chat.user.add';
|
|
483
|
+
body.CHAT_ID = this.getNodeParameter('chatId', i);
|
|
484
|
+
// bitrix expects USERS array
|
|
485
|
+
const userId = this.getNodeParameter('userId', i);
|
|
486
|
+
body.USERS = [userId];
|
|
487
|
+
}
|
|
488
|
+
else if (operation === 'getUsers') {
|
|
489
|
+
endpoint = 'im.chat.user.list';
|
|
490
|
+
body.CHAT_ID = this.getNodeParameter('chatId', i);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else if (resource === 'notification') {
|
|
494
|
+
if (operation === 'send') {
|
|
495
|
+
endpoint = 'im.notify.system.add';
|
|
496
|
+
body.USER_ID = this.getNodeParameter('userId', i);
|
|
497
|
+
body.MESSAGE = this.getNodeParameter('message', i);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', endpoint, body, {}, overrideAuth);
|
|
501
|
+
let result = response.result;
|
|
502
|
+
if (result === undefined)
|
|
503
|
+
result = { success: true }; // Sometimes void methods return nothing
|
|
504
|
+
if (Array.isArray(result)) {
|
|
505
|
+
result.forEach((item) => returnData.push({ json: item, pairedItem: { item: i } }));
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
returnData.push({ json: result, pairedItem: { item: i } });
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
if (this.continueOnFail()) {
|
|
513
|
+
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
throw error;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return [returnData];
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
exports.Bitrix24ChatBot = Bitrix24ChatBot;
|