n8n-nodes-pilot-status 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -68,7 +68,7 @@ Webhook payload notes:
68
68
  The **Pilot Status** node provides several resources and operations to manage your account and send messages.
69
69
 
70
70
  ### 1. Message
71
- - **Send:** Send a template message (OTP, Utility, or Marketing). You can provide variables dynamically via JSON and even schedule the message (`deliverAt`).
71
+ - **Send:** Send a template message (OTP, Utility, or Marketing). Choose **Phone Number** or **WhatsApp Group**; for groups use `groupId` (JID ending in `@g.us`) instead of `destinationNumber`. Optional dropdown loads groups from `GET /v1/groups` when the WhatsApp session is connected. Variables can be provided via JSON or the UI collection (including placeholders used in button labels).
72
72
  - **Get Status:** Retrieve the current status of a specific message using either its Pilot Status message id or WhatsApp provider id.
73
73
  - **Check Opt-In:** Check if a specific destination number has opted in to receive messages from your project (required for LIVE environments when using the Pilot Status shared number).
74
74
 
@@ -4,6 +4,8 @@ export declare class PilotStatus implements INodeType {
4
4
  loadOptions: {
5
5
  getTemplates(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
6
6
  getTemplateVariables(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
7
+ getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
8
+ getNewsletters(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
7
9
  };
8
10
  };
9
11
  description: INodeTypeDescription;
@@ -37,6 +37,42 @@ class PilotStatus {
37
37
  const vars = (_b = (_a = response === null || response === void 0 ? void 0 : response.latestVersion) === null || _a === void 0 ? void 0 : _a.variables) !== null && _b !== void 0 ? _b : [];
38
38
  return Array.isArray(vars) ? vars.map((v) => ({ name: v, value: v })) : [];
39
39
  },
40
+ async getGroups() {
41
+ try {
42
+ const response = (await this.helpers.requestWithAuthentication.call(this, 'pilotStatusApi', {
43
+ method: 'GET',
44
+ baseURL: 'https://pilotstatus.online/v1',
45
+ url: '/groups',
46
+ json: true,
47
+ }));
48
+ const groups = Array.isArray(response === null || response === void 0 ? void 0 : response.groups) ? response.groups : [];
49
+ return groups.map((g) => ({
50
+ name: g.name ? `${g.name} (${g.id})` : g.id,
51
+ value: g.id,
52
+ }));
53
+ }
54
+ catch {
55
+ return [];
56
+ }
57
+ },
58
+ async getNewsletters() {
59
+ try {
60
+ const response = (await this.helpers.requestWithAuthentication.call(this, 'pilotStatusApi', {
61
+ method: 'GET',
62
+ baseURL: 'https://pilotstatus.online/v1',
63
+ url: '/newsletters',
64
+ json: true,
65
+ }));
66
+ const newsletters = Array.isArray(response === null || response === void 0 ? void 0 : response.newsletters) ? response.newsletters : [];
67
+ return newsletters.map((n) => ({
68
+ name: n.name ? `${n.name} (${n.id})` : n.id,
69
+ value: n.id,
70
+ }));
71
+ }
72
+ catch {
73
+ return [];
74
+ }
75
+ },
40
76
  },
41
77
  };
42
78
  this.description = {
@@ -101,7 +137,39 @@ class PilotStatus {
101
137
  send: {
102
138
  preSend: [
103
139
  async function (requestOptions) {
104
- var _a;
140
+ var _a, _b;
141
+ const destinationType = this.getNodeParameter('sendDestinationType') || 'phone';
142
+ if (!requestOptions.body || typeof requestOptions.body !== 'object') {
143
+ requestOptions.body = {};
144
+ }
145
+ const body = requestOptions.body;
146
+ if (destinationType === 'group') {
147
+ delete body.destinationNumber;
148
+ delete body.newsletterId;
149
+ const gid = body.groupId;
150
+ const gidStr = typeof gid === 'string' ? gid.trim() : '';
151
+ if (!gidStr || !gidStr.endsWith('@g.us')) {
152
+ throw new Error('Pilot Status: informe um Group ID válido (JID terminando em @g.us) ao enviar para grupo.');
153
+ }
154
+ }
155
+ else if (destinationType === 'newsletter') {
156
+ delete body.destinationNumber;
157
+ delete body.groupId;
158
+ const nid = body.newsletterId;
159
+ const nidStr = typeof nid === 'string' ? nid.trim() : '';
160
+ if (!nidStr || !nidStr.toLowerCase().endsWith('@newsletter')) {
161
+ throw new Error('Pilot Status: informe um Newsletter ID válido (JID terminando em @newsletter) ao enviar para canal.');
162
+ }
163
+ }
164
+ else {
165
+ delete body.groupId;
166
+ delete body.newsletterId;
167
+ const dest = body.destinationNumber;
168
+ const destStr = typeof dest === 'string' ? dest.trim() : '';
169
+ if (!destStr) {
170
+ throw new Error('Pilot Status: informe destinationNumber (E.164) ao enviar para telefone.');
171
+ }
172
+ }
105
173
  const mode = this.getNodeParameter('variablesMode');
106
174
  let variables = {};
107
175
  if (mode === 'json') {
@@ -109,7 +177,10 @@ class PilotStatus {
109
177
  try {
110
178
  const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw;
111
179
  if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
112
- variables = parsed;
180
+ // ✅ API exige que todos os valores sejam strings
181
+ for (const [k, v] of Object.entries(parsed)) {
182
+ variables[k] = String(v !== null && v !== void 0 ? v : '');
183
+ }
113
184
  }
114
185
  }
115
186
  catch {
@@ -119,7 +190,8 @@ class PilotStatus {
119
190
  else {
120
191
  const ui = this.getNodeParameter('variablesUi');
121
192
  for (const entry of (_a = ui === null || ui === void 0 ? void 0 : ui.values) !== null && _a !== void 0 ? _a : []) {
122
- variables[entry.name] = entry.value;
193
+ // ✅ API exige que todos os valores sejam strings
194
+ variables[entry.name] = String((_b = entry.value) !== null && _b !== void 0 ? _b : '');
123
195
  }
124
196
  }
125
197
  // Garante que o body é um objeto e injeta "variables" como objeto
@@ -169,16 +241,61 @@ class PilotStatus {
169
241
  required: true,
170
242
  routing: { send: { type: 'body', property: 'templateId' } },
171
243
  },
244
+ {
245
+ displayName: 'Send To',
246
+ name: 'sendDestinationType',
247
+ type: 'options',
248
+ noDataExpression: true,
249
+ options: [
250
+ { name: 'Phone Number (E.164)', value: 'phone' },
251
+ { name: 'WhatsApp Group', value: 'group' },
252
+ { name: 'Newsletter (channel)', value: 'newsletter' },
253
+ ],
254
+ default: 'phone',
255
+ displayOptions: { show: { resource: ['message'], operation: ['send'] } },
256
+ },
172
257
  {
173
258
  displayName: 'Destination Number',
174
259
  name: 'destinationNumber',
175
260
  type: 'string',
176
261
  description: 'E.164 format (e.g. +5511999999999)',
177
- displayOptions: { show: { resource: ['message'], operation: ['send', 'checkOptIn'] } },
262
+ displayOptions: {
263
+ show: { resource: ['message'], operation: ['send', 'checkOptIn'] },
264
+ hide: {
265
+ operation: ['send'],
266
+ sendDestinationType: ['group', 'newsletter'],
267
+ },
268
+ },
178
269
  default: '',
179
270
  required: true,
180
271
  routing: { send: { type: 'body', property: 'destinationNumber' } },
181
272
  },
273
+ {
274
+ displayName: 'Group ID',
275
+ name: 'groupId',
276
+ type: 'options',
277
+ typeOptions: { loadOptionsMethod: 'getGroups' },
278
+ displayOptions: {
279
+ show: { resource: ['message'], operation: ['send'], sendDestinationType: ['group'] },
280
+ },
281
+ default: '',
282
+ required: true,
283
+ description: 'JID do grupo (@g.us). Lista via GET /v1/groups; também pode usar expressão n8n.',
284
+ routing: { send: { type: 'body', property: 'groupId' } },
285
+ },
286
+ {
287
+ displayName: 'Newsletter ID',
288
+ name: 'newsletterId',
289
+ type: 'options',
290
+ typeOptions: { loadOptionsMethod: 'getNewsletters' },
291
+ displayOptions: {
292
+ show: { resource: ['message'], operation: ['send'], sendDestinationType: ['newsletter'] },
293
+ },
294
+ default: '',
295
+ required: true,
296
+ description: 'JID do canal (@newsletter). Lista via GET /v1/newsletters; também pode usar expressão n8n.',
297
+ routing: { send: { type: 'body', property: 'newsletterId' } },
298
+ },
182
299
  {
183
300
  displayName: 'Variables Mode',
184
301
  name: 'variablesMode',
@@ -61,6 +61,10 @@ class PilotStatusTrigger {
61
61
  name: 'Group Message',
62
62
  value: 'message.group',
63
63
  },
64
+ {
65
+ name: 'Newsletter Message',
66
+ value: 'message.newsletter',
67
+ },
64
68
  {
65
69
  name: 'Opt-in Created',
66
70
  value: 'optin.created',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-pilot-status",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "n8n node for Pilot Status API",
5
5
  "keywords": [
6
6
  "n8ncommunity",