n8n-nodes-signal-cli-rest-api 0.2.2 → 0.2.3

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Signal = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  const messages_1 = require("./messages");
5
6
  const groups_1 = require("./groups");
6
7
  const contacts_1 = require("./contacts");
@@ -276,6 +277,7 @@ class Signal {
276
277
  const apiUrl = credentials.apiUrl;
277
278
  const apiToken = credentials.apiToken;
278
279
  const phoneNumber = credentials.phoneNumber;
280
+ this.logger.debug(`Signal: Starting execute for operation ${operation}, apiUrl: ${apiUrl}, items length: ${items.length}`);
279
281
  for (let i = 0; i < items.length; i++) {
280
282
  const timeout = this.getNodeParameter('timeout', i, operation === 'getGroups' ? 300 : 60) * 1000;
281
283
  const params = {
@@ -294,23 +296,28 @@ class Signal {
294
296
  phoneNumber,
295
297
  };
296
298
  try {
299
+ let result;
297
300
  if (['sendMessage', 'sendAttachment', 'sendReaction', 'removeReaction'].includes(operation)) {
298
- const result = await messages_1.executeMessagesOperation.call(this, operation, i, params);
299
- returnData.push(result);
301
+ result = await messages_1.executeMessagesOperation.call(this, operation, i, params);
300
302
  }
301
303
  else if (['getGroups', 'createGroup', 'updateGroup'].includes(operation)) {
302
- const result = await groups_1.executeGroupsOperation.call(this, operation, i, params);
303
- returnData.push(result);
304
+ result = await groups_1.executeGroupsOperation.call(this, operation, i, params);
304
305
  }
305
306
  else if (operation === 'getContacts') {
306
- const result = await contacts_1.executeContactsOperation.call(this, operation, i, params);
307
- returnData.push(result);
307
+ result = await contacts_1.executeContactsOperation.call(this, operation, i, params);
308
308
  }
309
+ else {
310
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: 'Unknown operation' });
311
+ }
312
+ this.logger.info(`Signal: Operation ${operation} result for item ${i}: ${JSON.stringify(result.json, null, 2)}`);
313
+ returnData.push(result);
309
314
  }
310
315
  catch (error) {
316
+ this.logger.error(`Signal: Error in operation ${operation} for item ${i}`, { error });
311
317
  throw error;
312
318
  }
313
319
  }
320
+ this.logger.debug(`Signal: Returning data length: ${returnData.length}`);
314
321
  return [returnData];
315
322
  }
316
323
  }
@@ -26,34 +26,38 @@ async function executeMessagesOperation(operation, itemIndex, params) {
26
26
  }
27
27
  };
28
28
  try {
29
+ let response;
29
30
  if (operation === 'sendMessage') {
30
- const response = await retryRequest(() => axios_1.default.post(`${apiUrl}/v1/send`, {
31
+ response = await retryRequest(() => axios_1.default.post(`${apiUrl}/v1/send`, {
31
32
  message,
32
33
  number: phoneNumber,
33
34
  recipients: [recipient],
34
35
  }, axiosConfig));
35
- return { json: response.data, pairedItem: { item: itemIndex } };
36
+ this.logger.debug(`Signal messages: sendMessage response: ${JSON.stringify(response.data, null, 2)}`);
37
+ return { json: response.data || { status: 'Message sent' }, pairedItem: { item: itemIndex } };
36
38
  }
37
39
  else if (operation === 'sendAttachment') {
38
- const response = await retryRequest(() => axios_1.default.post(`${apiUrl}/v1/send`, {
40
+ response = await retryRequest(() => axios_1.default.post(`${apiUrl}/v1/send`, {
39
41
  message,
40
42
  number: phoneNumber,
41
43
  recipients: [recipient],
42
44
  attachments: [attachmentUrl],
43
45
  }, axiosConfig));
44
- return { json: response.data, pairedItem: { item: itemIndex } };
46
+ this.logger.debug(`Signal messages: sendAttachment response: ${JSON.stringify(response.data, null, 2)}`);
47
+ return { json: response.data || { status: 'Attachment sent' }, pairedItem: { item: itemIndex } };
45
48
  }
46
49
  else if (operation === 'sendReaction') {
47
- const response = await retryRequest(() => axios_1.default.post(`${apiUrl}/v1/reactions/${phoneNumber}`, {
50
+ response = await retryRequest(() => axios_1.default.post(`${apiUrl}/v1/reactions/${phoneNumber}`, {
48
51
  reaction: emoji,
49
52
  recipient,
50
53
  target_author: targetAuthor,
51
54
  timestamp: targetSentTimestamp,
52
55
  }, axiosConfig));
53
- return { json: response.data, pairedItem: { item: itemIndex } };
56
+ this.logger.debug(`Signal messages: sendReaction response: ${JSON.stringify(response.data, null, 2)}`);
57
+ return { json: response.data || { status: 'Reaction sent' }, pairedItem: { item: itemIndex } };
54
58
  }
55
59
  else if (operation === 'removeReaction') {
56
- const response = await retryRequest(() => axios_1.default.delete(`${apiUrl}/v1/reactions/${phoneNumber}`, {
60
+ response = await retryRequest(() => axios_1.default.delete(`${apiUrl}/v1/reactions/${phoneNumber}`, {
57
61
  ...axiosConfig,
58
62
  data: {
59
63
  recipient,
@@ -61,6 +65,7 @@ async function executeMessagesOperation(operation, itemIndex, params) {
61
65
  timestamp: targetSentTimestamp,
62
66
  },
63
67
  }));
68
+ this.logger.debug(`Signal messages: removeReaction response: ${JSON.stringify(response.data, null, 2)}`);
64
69
  return { json: response.data || { status: 'Reaction removed' }, pairedItem: { item: itemIndex } };
65
70
  }
66
71
  throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: 'Unknown operation' });
@@ -0,0 +1,10 @@
1
+ import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
2
+ interface MessageHistoryParams {
3
+ timeout: number;
4
+ fullHistory: boolean;
5
+ apiUrl: string;
6
+ apiToken: string;
7
+ phoneNumber: string;
8
+ }
9
+ export declare function getMessageHistory(this: IExecuteFunctions, params: MessageHistoryParams): Promise<INodeExecutionData[]>;
10
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getMessageHistory = void 0;
7
+ const n8n_workflow_1 = require("n8n-workflow");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ async function getMessageHistory(params) {
10
+ var _a, _b, _c, _d;
11
+ const { timeout, fullHistory, apiUrl, apiToken, phoneNumber } = params;
12
+ const axiosConfig = {
13
+ headers: apiToken ? { Authorization: `Bearer ${apiToken}` } : {},
14
+ timeout,
15
+ };
16
+ const retryRequest = async (request, retries = 2, delay = 5000) => {
17
+ for (let attempt = 1; attempt <= retries; attempt++) {
18
+ try {
19
+ return await request();
20
+ }
21
+ catch (error) {
22
+ if (attempt === retries)
23
+ throw error;
24
+ await new Promise(resolve => setTimeout(resolve, delay));
25
+ }
26
+ }
27
+ };
28
+ try {
29
+ const url = fullHistory
30
+ ? `${apiUrl}/v1/receive/${phoneNumber}`
31
+ : `${apiUrl}/v1/receive/${phoneNumber}?timeout=${timeout / 1000}`;
32
+ const response = await retryRequest(() => axios_1.default.get(url, axiosConfig));
33
+ const messages = Array.isArray(response.data) ? response.data : [];
34
+ return messages.map((message, index) => {
35
+ var _a, _b, _c, _d, _e, _f, _g, _h;
36
+ return ({
37
+ json: {
38
+ messageText: ((_b = (_a = message.envelope) === null || _a === void 0 ? void 0 : _a.dataMessage) === null || _b === void 0 ? void 0 : _b.message) || '',
39
+ attachments: ((_d = (_c = message.envelope) === null || _c === void 0 ? void 0 : _c.dataMessage) === null || _d === void 0 ? void 0 : _d.attachments) || [],
40
+ reactions: ((_f = (_e = message.envelope) === null || _e === void 0 ? void 0 : _e.dataMessage) === null || _f === void 0 ? void 0 : _f.reactions) || [],
41
+ sourceNumber: ((_g = message.envelope) === null || _g === void 0 ? void 0 : _g.sourceNumber) || '',
42
+ timestamp: ((_h = message.envelope) === null || _h === void 0 ? void 0 : _h.timestamp) || 0,
43
+ account: message.account || '',
44
+ },
45
+ pairedItem: { item: index },
46
+ });
47
+ });
48
+ }
49
+ catch (error) {
50
+ const axiosError = error;
51
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), {
52
+ message: axiosError.message,
53
+ description: (((_b = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || axiosError.message),
54
+ httpCode: ((_d = (_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.status) === null || _d === void 0 ? void 0 : _d.toString()) || 'unknown',
55
+ });
56
+ }
57
+ }
58
+ exports.getMessageHistory = getMessageHistory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-signal-cli-rest-api",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Signal Node for n8n using signal-cli-rest-api",
5
5
  "repository": {
6
6
  "type": "git",