n8n-nodes-signal-cli-rest-api 0.4.0 → 0.5.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.
@@ -55,6 +55,13 @@ class SignalTrigger {
55
55
  default: false,
56
56
  description: 'Enable to ignore messages with reactions',
57
57
  },
58
+ {
59
+ displayName: 'Mark Messages as Read',
60
+ name: 'markAsRead',
61
+ type: 'boolean',
62
+ default: false,
63
+ description: 'Automatically mark processed incoming messages as read',
64
+ },
58
65
  ],
59
66
  };
60
67
  }
@@ -67,10 +74,39 @@ class SignalTrigger {
67
74
  const ignoreMessages = this.getNodeParameter('ignoreMessages', 0);
68
75
  const ignoreAttachments = this.getNodeParameter('ignoreAttachments', 0);
69
76
  const ignoreReactions = this.getNodeParameter('ignoreReactions', 0);
77
+ const markAsRead = this.getNodeParameter('markAsRead', 0);
70
78
  const wsUrl = `${apiUrl.replace('http', 'ws')}/v1/receive/${phoneNumber}`;
71
79
  this.logger.debug(`SignalTrigger: Attempting to connect to WS URL: ${wsUrl}`);
72
80
  const processedMessages = new Set();
73
81
  const maxMessages = 1000;
82
+ // Функція для позначення повідомлення як прочитаного
83
+ const markMessageAsRead = async (sourceNumber, sourceUuid, timestamp) => {
84
+ try {
85
+ const readReceiptUrl = `${apiUrl}/v1/read-receipt/${phoneNumber}`;
86
+ const requestBody = {
87
+ recipient: sourceUuid || sourceNumber,
88
+ timestamps: [timestamp]
89
+ };
90
+ const response = await fetch(readReceiptUrl, {
91
+ method: 'POST',
92
+ headers: {
93
+ 'Content-Type': 'application/json',
94
+ ...(apiToken && { Authorization: `Bearer ${apiToken}` }),
95
+ },
96
+ body: JSON.stringify(requestBody),
97
+ });
98
+ if (response.ok) {
99
+ this.logger.debug(`SignalTrigger: Successfully marked message as read for ${sourceNumber} (${sourceUuid}), timestamp: ${timestamp}`);
100
+ }
101
+ else {
102
+ const errorText = await response.text();
103
+ this.logger.warn(`SignalTrigger: Failed to mark message as read: ${response.status} ${errorText}`);
104
+ }
105
+ }
106
+ catch (error) {
107
+ this.logger.error(`SignalTrigger: Error marking message as read`, { error });
108
+ }
109
+ };
74
110
  const connectWebSocket = () => {
75
111
  const ws = new ws_1.WebSocket(wsUrl, {
76
112
  headers: apiToken ? { Authorization: `Bearer ${apiToken}` } : {},
@@ -78,7 +114,7 @@ class SignalTrigger {
78
114
  ws.on('open', () => {
79
115
  this.logger.debug(`SignalTrigger: Successfully connected to ${wsUrl}`);
80
116
  });
81
- ws.on('message', (data) => {
117
+ ws.on('message', async (data) => {
82
118
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
83
119
  try {
84
120
  const message = JSON.parse(data.toString());
@@ -93,6 +129,7 @@ class SignalTrigger {
93
129
  }
94
130
  processedMessages.add(timestamp);
95
131
  const dataMsg = ((_b = message.envelope) === null || _b === void 0 ? void 0 : _b.dataMessage) || ((_d = (_c = message.envelope) === null || _c === void 0 ? void 0 : _c.syncMessage) === null || _d === void 0 ? void 0 : _d.sentMessage) || {};
132
+ // Визначаємо тип повідомлення на основі структури envelope
96
133
  const hasDataMessage = !!((_e = message.envelope) === null || _e === void 0 ? void 0 : _e.dataMessage);
97
134
  const hasSyncMessage = !!((_f = message.envelope) === null || _f === void 0 ? void 0 : _f.syncMessage);
98
135
  let shouldProcess = false;
@@ -141,12 +178,14 @@ class SignalTrigger {
141
178
  envelope: message.envelope || {},
142
179
  };
143
180
  this.logger.debug(`SignalTrigger: Processed message content: ${JSON.stringify(processedMessage, null, 2)}`);
181
+ // Ігнорувати події без вмісту
144
182
  if (!processedMessage.messageText &&
145
183
  processedMessage.attachments.length === 0 &&
146
184
  processedMessage.reactions.length === 0) {
147
185
  this.logger.debug(`SignalTrigger: Skipping empty message with timestamp ${timestamp}`);
148
186
  return;
149
187
  }
188
+ // Фільтрація: ігнорувати, якщо увімкнено ignore і відповідний вміст присутній
150
189
  if ((ignoreMessages && processedMessage.messageText) ||
151
190
  (ignoreAttachments && processedMessage.attachments.length > 0) ||
152
191
  (ignoreReactions && processedMessage.reactions.length > 0)) {
@@ -158,6 +197,10 @@ class SignalTrigger {
158
197
  };
159
198
  this.emit([this.helpers.returnJsonArray([returnData])]);
160
199
  this.logger.debug(`SignalTrigger: Emitted message with timestamp ${timestamp}`);
200
+ // Позначити повідомлення як прочитане, якщо це вхідне повідомлення і увімкнено опцію
201
+ if (markAsRead && messageType === 'incoming') {
202
+ await markMessageAsRead(processedMessage.sourceNumber, processedMessage.sourceUuid, timestamp);
203
+ }
161
204
  }
162
205
  catch (error) {
163
206
  this.logger.error('SignalTrigger: Error parsing message', { error });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-signal-cli-rest-api",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Signal Node for n8n using signal-cli-rest-api",
5
5
  "repository": {
6
6
  "type": "git",