n8n-nodes-chatflow 1.1.2 → 1.1.5

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/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
- // Точка входа: экспортируем классы, а не пути. Относительные пути
2
- // будут корректно работать как из исходников, так и после сборки в dist.
3
1
  const { ChatflowMessage } = require('./nodes/ChatflowMessage.node.js');
2
+ const { ChatflowTrigger } = require('./nodes/ChatflowTrigger.node.js');
4
3
  const { ChatflowApi } = require('./credentials/ChatflowApi.credentials.js');
5
- exports.nodes = [ChatflowMessage];
4
+ exports.nodes = [ChatflowMessage, ChatflowTrigger];
6
5
  exports.credentials = [ChatflowApi];
7
6
  module.exports = { nodes: exports.nodes, credentials: exports.credentials };
@@ -3,37 +3,6 @@ class ChatflowMessage {
3
3
  this.description = ChatflowMessage.description;
4
4
  }
5
5
 
6
- methods = {
7
- loadOptions: {
8
- async getPlatform() {
9
- try {
10
- const credentials = await this.getCredentials('chatflowApi');
11
- const serverUrl = (credentials.serverUrl || 'https://app.chatflow.kz').replace(/\/+$/, '');
12
- if (!credentials.flowId) return [];
13
-
14
- const response = await this.helpers.httpRequest({
15
- method: 'GET',
16
- url: `${serverUrl}/api/v1/n8n/flow-info/${credentials.flowId}`,
17
- qs: { token: credentials.token },
18
- json: true,
19
- });
20
-
21
- if (response && response.platform) {
22
- const platName = response.platform === 'telegram' ? 'Telegram' : 'WhatsApp';
23
- return [{ name: platName, value: response.platform }];
24
- }
25
- } catch(e) {
26
- console.error('Failed to load platform:', e);
27
- }
28
-
29
- return [
30
- { name: 'WhatsApp', value: 'whatsapp' },
31
- { name: 'Telegram', value: 'telegram' }
32
- ];
33
- }
34
- }
35
- };
36
-
37
6
  async execute() {
38
7
  const items = this.getInputData();
39
8
  const out = [];
@@ -41,26 +10,38 @@ class ChatflowMessage {
41
10
  const token = credentials.token;
42
11
  const flowId = credentials.flowId;
43
12
  const serverUrl = 'https://lk.chatflow.kz';
44
- const platform = this.getNodeParameter('platform', 0, 'whatsapp');
45
13
 
46
14
  const operation = this.getNodeParameter('operation', 0);
47
15
  const continueOnFail = this.getNodeParameter('continueOnFail', 0);
48
16
 
17
+ // Fetch platform automatically from server
18
+ let platform = 'whatsapp';
19
+ try {
20
+ const infoResp = await this.helpers.httpRequest({
21
+ method: 'GET',
22
+ url: `${serverUrl}/api/v1/n8n/flow-info/${flowId}`,
23
+ qs: { token },
24
+ json: true,
25
+ });
26
+ if (infoResp && infoResp.platform) {
27
+ platform = infoResp.platform;
28
+ }
29
+ } catch(e) {
30
+ // fallback to whatsapp
31
+ }
32
+
49
33
  for (let i = 0; i < items.length; i++) {
50
34
  try {
51
35
  const recipient = this.getNodeParameter('recipient', i);
52
36
 
53
- // Build query string params
54
37
  const qs = { token, flow_id: flowId };
55
38
 
56
- // Set recipient field based on platform
57
39
  if (platform === 'telegram') {
58
40
  qs.chat_id = recipient;
59
41
  } else {
60
42
  qs.jid = recipient;
61
43
  }
62
44
 
63
- // Operation-specific params
64
45
  if (operation === 'text') {
65
46
  qs.msg = this.getNodeParameter('msg', i);
66
47
  }
@@ -119,7 +100,7 @@ ChatflowMessage.description = {
119
100
  },
120
101
  group: ['output'],
121
102
  version: 2,
122
- subtitle: '={{$parameter["operation"]}} ({{$parameter["platform"]}})',
103
+ subtitle: '={{$parameter["operation"]}}',
123
104
  description: 'Send WhatsApp & Telegram messages via Chatflow API',
124
105
  defaults: { name: 'Chatflow' },
125
106
  inputs: [{ type: 'main' }],
@@ -128,15 +109,6 @@ ChatflowMessage.description = {
128
109
  { name: 'chatflowApi', required: true },
129
110
  ],
130
111
  properties: [
131
- {
132
- displayName: 'Messaging Platform',
133
- name: 'platform',
134
- type: 'options',
135
- typeOptions: { loadOptionsMethod: 'getPlatform' },
136
- default: '',
137
- required: true,
138
- description: 'Automatically determined from your Chatflow credentials (Flow ID)',
139
- },
140
112
  {
141
113
  displayName: 'Operation',
142
114
  name: 'operation',
@@ -152,23 +124,13 @@ ChatflowMessage.description = {
152
124
  default: 'text',
153
125
  },
154
126
  {
155
- displayName: 'Recipient Number (WhatsApp)',
156
- name: 'recipient',
157
- type: 'string',
158
- default: '',
159
- required: true,
160
- displayOptions: { show: { platform: ['whatsapp'] } },
161
- description: 'WhatsApp phone number (e.g. 77001234567)',
162
- placeholder: '77001234567',
163
- },
164
- {
165
- displayName: 'Chat ID (Telegram)',
127
+ displayName: 'Recipient',
166
128
  name: 'recipient',
167
129
  type: 'string',
168
130
  default: '',
169
131
  required: true,
170
- displayOptions: { show: { platform: ['telegram'] } },
171
- description: 'Telegram numeric Chat ID',
132
+ description: 'WhatsApp number (e.g. 77001234567) or Telegram Chat ID — determined automatically from Flow',
133
+ placeholder: '77001234567 or -100123456789',
172
134
  },
173
135
  // --- Text ---
174
136
  {
@@ -179,25 +141,15 @@ ChatflowMessage.description = {
179
141
  default: '',
180
142
  required: true,
181
143
  displayOptions: { show: { operation: ['text'] } },
182
- description: 'Text of the message to send',
183
144
  },
184
- // --- Image ---
145
+ // --- Audio ---
185
146
  {
186
- displayName: 'Image URL',
187
- name: 'imageurl',
147
+ displayName: 'Audio URL',
148
+ name: 'audiourl',
188
149
  type: 'string',
189
150
  default: '',
190
151
  required: true,
191
- displayOptions: { show: { operation: ['image'] } },
192
- description: 'Public URL of the image file',
193
- },
194
- {
195
- displayName: 'Caption',
196
- name: 'captionImg',
197
- type: 'string',
198
- default: '',
199
- displayOptions: { show: { operation: ['image'] } },
200
- description: 'Optional caption for the image',
152
+ displayOptions: { show: { operation: ['audio'] } },
201
153
  },
202
154
  // --- Video ---
203
155
  {
@@ -207,7 +159,6 @@ ChatflowMessage.description = {
207
159
  default: '',
208
160
  required: true,
209
161
  displayOptions: { show: { operation: ['video'] } },
210
- description: 'Public URL of the video file',
211
162
  },
212
163
  {
213
164
  displayName: 'Caption',
@@ -215,17 +166,6 @@ ChatflowMessage.description = {
215
166
  type: 'string',
216
167
  default: '',
217
168
  displayOptions: { show: { operation: ['video'] } },
218
- description: 'Optional caption for the video',
219
- },
220
- // --- Audio ---
221
- {
222
- displayName: 'Audio URL',
223
- name: 'audiourl',
224
- type: 'string',
225
- default: '',
226
- required: true,
227
- displayOptions: { show: { operation: ['audio'] } },
228
- description: 'Public URL of the audio file',
229
169
  },
230
170
  // --- Document ---
231
171
  {
@@ -235,7 +175,6 @@ ChatflowMessage.description = {
235
175
  default: '',
236
176
  required: true,
237
177
  displayOptions: { show: { operation: ['document'] } },
238
- description: 'Public URL of the document file',
239
178
  },
240
179
  {
241
180
  displayName: 'Caption',
@@ -243,15 +182,29 @@ ChatflowMessage.description = {
243
182
  type: 'string',
244
183
  default: '',
245
184
  displayOptions: { show: { operation: ['document'] } },
246
- description: 'Optional caption for the document',
247
185
  },
248
- // --- Options ---
186
+ // --- Image ---
187
+ {
188
+ displayName: 'Image URL',
189
+ name: 'imageurl',
190
+ type: 'string',
191
+ default: '',
192
+ required: true,
193
+ displayOptions: { show: { operation: ['image'] } },
194
+ },
195
+ {
196
+ displayName: 'Caption',
197
+ name: 'captionImg',
198
+ type: 'string',
199
+ default: '',
200
+ displayOptions: { show: { operation: ['image'] } },
201
+ },
202
+ // Continue on fail
249
203
  {
250
204
  displayName: 'Continue On Fail',
251
205
  name: 'continueOnFail',
252
206
  type: 'boolean',
253
- default: true,
254
- description: 'Whether to continue workflow execution on send failure',
207
+ default: false,
255
208
  },
256
209
  ],
257
210
  };
@@ -3,45 +3,12 @@ class ChatflowTrigger {
3
3
  this.description = ChatflowTrigger.description;
4
4
  }
5
5
 
6
- methods = {
7
- loadOptions: {
8
- async getPlatform() {
9
- try {
10
- const credentials = await this.getCredentials('chatflowApi');
11
- const serverUrl = 'https://lk.chatflow.kz';
12
- if (!credentials.flowId) return [];
13
-
14
- const response = await this.helpers.httpRequest({
15
- method: 'GET',
16
- url: `${serverUrl}/api/v1/n8n/flow-info/${credentials.flowId}`,
17
- qs: { token: credentials.token },
18
- json: true,
19
- });
20
-
21
- if (response && response.platform) {
22
- const platName = response.platform === 'telegram' ? 'Telegram' : 'WhatsApp';
23
- return [{ name: platName, value: response.platform }];
24
- }
25
- } catch(e) {
26
- console.error('Failed to load platform:', e);
27
- }
28
-
29
- return [
30
- { name: 'WhatsApp', value: 'whatsapp' },
31
- { name: 'Telegram', value: 'telegram' }
32
- ];
33
- }
34
- }
35
- };
36
-
37
6
  webhookMethods = {
38
7
  default: {
39
8
  async checkExists() {
40
9
  const webhookData = this.getWorkflowStaticData('node');
41
- const webhookUrl = this.getNodeWebhookUrl('default');
42
10
 
43
11
  if (webhookData.webhookId) {
44
- // Check if webhook is still registered on the server
45
12
  try {
46
13
  const credentials = await this.getCredentials('chatflowApi');
47
14
  const serverUrl = 'https://lk.chatflow.kz';
@@ -71,7 +38,6 @@ class ChatflowTrigger {
71
38
  const flowId = credentials.flowId;
72
39
  const token = credentials.token;
73
40
 
74
- // Get event filters from node parameters
75
41
  const events = this.getNodeParameter('events', {});
76
42
 
77
43
  const body = {
@@ -130,36 +96,26 @@ class ChatflowTrigger {
130
96
 
131
97
  async webhook() {
132
98
  const bodyData = this.getBodyData();
133
- const headerData = this.getHeaderData();
134
-
135
- // Verify the source (optional: check token header)
136
- // const credentials = await this.getCredentials('chatflowApi');
137
99
 
138
- // Normalize: Chatflow sends { messages: [...] }
139
100
  const messages = bodyData.messages || [bodyData];
140
101
  const returnData = [];
141
102
 
142
103
  for (const message of messages) {
143
104
  returnData.push({
144
105
  json: {
145
- // Core message fields
146
106
  platform: message.platform || 'whatsapp',
147
107
  event_type: message.wh_type || 'incoming_message',
148
- // Sender info
149
108
  from: message.chat_id || message.from || '',
150
109
  sender_name: message.contact?.FullName || message.contact?.FirstName || message.pushName || '',
151
- // Message content
152
110
  message_id: message.id || message.task_id || '',
153
111
  text: message.body || message.text || '',
154
112
  type: message.type || 'text',
155
- // Media (if any)
156
113
  media_url: message.media_url || message.body_file || '',
157
114
  caption: message.caption || '',
158
- // Metadata
159
115
  timestamp: message.time || Date.now(),
160
116
  profile_id: message.profile_id || '',
161
117
  instance_id: message.instance_id || '',
162
- // Full raw payload for advanced use
118
+ flow_id: message.flow_id || '',
163
119
  _raw: message,
164
120
  },
165
121
  });
@@ -172,7 +128,7 @@ class ChatflowTrigger {
172
128
  }
173
129
 
174
130
  ChatflowTrigger.description = {
175
- displayName: 'Chatflow Trigger',
131
+ displayName: 'Chatflow',
176
132
  name: 'chatflowTrigger',
177
133
  icon: {
178
134
  light: 'file:black.svg',
@@ -180,7 +136,7 @@ ChatflowTrigger.description = {
180
136
  },
181
137
  group: ['trigger'],
182
138
  version: 1,
183
- subtitle: '={{$parameter["platform"]}}',
139
+ subtitle: 'On incoming message',
184
140
  description: 'Triggers workflow on incoming messages via Chatflow',
185
141
  defaults: { name: 'Chatflow Trigger' },
186
142
  inputs: [],
@@ -197,15 +153,6 @@ ChatflowTrigger.description = {
197
153
  },
198
154
  ],
199
155
  properties: [
200
- {
201
- displayName: 'Messaging Platform',
202
- name: 'platform',
203
- type: 'options',
204
- typeOptions: { loadOptionsMethod: 'getPlatform' },
205
- default: '',
206
- required: true,
207
- description: 'Automatically determined from your Chatflow credentials (Flow ID)',
208
- },
209
156
  {
210
157
  displayName: 'Events',
211
158
  name: 'events',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-chatflow",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "n8n community nodes for Chatflow — send WhatsApp & Telegram messages and receive triggers",
5
5
  "author": "Chatflow",
6
6
  "license": "MIT",