piece-signal-cli-rest-api 0.2.14 → 0.2.16
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/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piece-signal-cli-rest-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "echo \"piece-signal-cli-rest-api: kein zusätzlicher Build-Schritt erforderlich (bereits als JS ausgeliefert)\"",
|
|
6
|
+
"publish:npm": "npm publish --access public"
|
|
7
|
+
},
|
|
4
8
|
"dependencies": {
|
|
5
9
|
"@sinclair/typebox": "0.34.11",
|
|
6
10
|
"ai": "5.0.104",
|
|
@@ -26,4 +30,4 @@
|
|
|
26
30
|
"types": "./src/index.d.ts",
|
|
27
31
|
"main": "./src/index.js",
|
|
28
32
|
"type": "commonjs"
|
|
29
|
-
}
|
|
33
|
+
}
|
|
@@ -83,7 +83,12 @@ exports.requestApprovalMessage = (0, pieces_framework_1.createAction)({
|
|
|
83
83
|
const targetAuthor = formattedNumber;
|
|
84
84
|
const createdAt = Math.floor(Date.now() / 1000); // Unix timestamp in seconds
|
|
85
85
|
// Create store key using milliseconds for precise matching
|
|
86
|
-
|
|
86
|
+
// Store-Key mit Timestamp + eindeutiger Flow-Run-ID
|
|
87
|
+
// flowRunId ist pro Flow-Ausführung eindeutig, verhindert Kollisionen
|
|
88
|
+
// #region agent log
|
|
89
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'request-approval-message.js:88',message:'Store-Key creation - checking context.run.id',data:{flowRunId:context.run.id,flowRunIdType:typeof context.run.id,messageTimestampMs,timestampSeconds,recipients:Array.isArray(recipients)?recipients.length:'not-array',recipientsType:typeof recipients},timestamp:Date.now(),hypothesisId:'A'})}).catch(()=>{});
|
|
90
|
+
// #endregion
|
|
91
|
+
const storeKey = `approval:${messageTimestampMs}:${context.run.id}`;
|
|
87
92
|
// DEBUG: Log storing approval mapping
|
|
88
93
|
console.log('[RequestApprovalMessage] DEBUG - Storing approval mapping:', {
|
|
89
94
|
storeKey,
|
|
@@ -117,9 +122,15 @@ exports.requestApprovalMessage = (0, pieces_framework_1.createAction)({
|
|
|
117
122
|
// DEBUG: Verify it was stored
|
|
118
123
|
const verifyMapping = yield context.store.get(storeKey, pieces_framework_1.StoreScope.PROJECT);
|
|
119
124
|
console.log('[RequestApprovalMessage] DEBUG - Verified stored mapping:', verifyMapping);
|
|
125
|
+
// #region agent log
|
|
126
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'request-approval-message.js:118',message:'Mapping stored - verifying recipients format',data:{storeKey,recipients:verifyMapping?.recipients,recipientsType:typeof verifyMapping?.recipients,recipientsIsArray:Array.isArray(verifyMapping?.recipients),messageTimestampMs:verifyMapping?.messageTimestampMs},timestamp:Date.now(),hypothesisId:'C'})}).catch(()=>{});
|
|
127
|
+
// #endregion
|
|
120
128
|
// Add key to approval keys list
|
|
121
129
|
const keysListKey = 'approval:keys';
|
|
122
130
|
const existingKeys = (yield context.store.get(keysListKey, pieces_framework_1.StoreScope.PROJECT)) || [];
|
|
131
|
+
// #region agent log
|
|
132
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'request-approval-message.js:123',message:'Adding key to approval keys list',data:{storeKey,existingKeysCount:existingKeys.length,keyAlreadyExists:existingKeys.includes(storeKey)},timestamp:Date.now(),hypothesisId:'D'})}).catch(()=>{});
|
|
133
|
+
// #endregion
|
|
123
134
|
if (!existingKeys.includes(storeKey)) {
|
|
124
135
|
existingKeys.push(storeKey);
|
|
125
136
|
yield context.store.put(keysListKey, existingKeys, pieces_framework_1.StoreScope.PROJECT);
|
|
@@ -9,6 +9,8 @@ const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
|
9
9
|
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
10
|
const ws_1 = tslib_1.__importDefault(require("ws"));
|
|
11
11
|
// Function to cleanup expired approval mappings
|
|
12
|
+
// Diese Funktion ist die EINZIGE Stelle, an der entschieden wird, ob ein Approval abgelaufen ist.
|
|
13
|
+
// Alle abgelaufenen Approvals werden hier gelöscht, bevor das Matching stattfindet.
|
|
12
14
|
function cleanupExpiredApprovals(store) {
|
|
13
15
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
16
|
const keysListKey = 'approval:keys';
|
|
@@ -16,11 +18,19 @@ function cleanupExpiredApprovals(store) {
|
|
|
16
18
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
17
19
|
const validKeys = [];
|
|
18
20
|
const keysToDelete = [];
|
|
21
|
+
// #region agent log
|
|
22
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:19',message:'Cleanup started',data:{existingKeysCount:existingKeys.length,currentTimestamp},timestamp:Date.now(),hypothesisId:'E'})}).catch(()=>{});
|
|
23
|
+
// #endregion
|
|
19
24
|
for (const key of existingKeys) {
|
|
20
25
|
const mapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
21
26
|
if (mapping) {
|
|
22
27
|
// Check if expired
|
|
23
|
-
|
|
28
|
+
const ageInSeconds = currentTimestamp - mapping.createdAt;
|
|
29
|
+
const isExpired = ageInSeconds > mapping.timeoutSeconds;
|
|
30
|
+
// #region agent log
|
|
31
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:26',message:'Checking expiration',data:{key,ageInSeconds,timeoutSeconds:mapping.timeoutSeconds,isExpired,createdAt:mapping.createdAt},timestamp:Date.now(),hypothesisId:'E'})}).catch(()=>{});
|
|
32
|
+
// #endregion
|
|
33
|
+
if (isExpired) {
|
|
24
34
|
// Expired - delete it and flowRunId mapping
|
|
25
35
|
yield store.delete(key, pieces_framework_1.StoreScope.PROJECT);
|
|
26
36
|
const flowRunMappingKey = `approval:flowRun:${mapping.flowRunId}`;
|
|
@@ -40,6 +50,9 @@ function cleanupExpiredApprovals(store) {
|
|
|
40
50
|
if (keysToDelete.length > 0) {
|
|
41
51
|
yield store.put(keysListKey, validKeys, pieces_framework_1.StoreScope.PROJECT);
|
|
42
52
|
}
|
|
53
|
+
// #region agent log
|
|
54
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:42',message:'Cleanup completed',data:{validKeysCount:validKeys.length,deletedKeysCount:keysToDelete.length},timestamp:Date.now(),hypothesisId:'E'})}).catch(()=>{});
|
|
55
|
+
// #endregion
|
|
43
56
|
});
|
|
44
57
|
}
|
|
45
58
|
// Function to automatically resume approval flows
|
|
@@ -67,10 +80,15 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
67
80
|
isGroupMessage: isGroupMessage,
|
|
68
81
|
});
|
|
69
82
|
// Cleanup expired approvals
|
|
83
|
+
// WICHTIG: cleanupExpiredApprovals ist die EINZIGE Stelle für Timeout-Entscheidungen.
|
|
84
|
+
// Alle nachfolgenden Matching-Schritte arbeiten nur auf bereits gefilterten (nicht abgelaufenen) Approvals.
|
|
70
85
|
yield cleanupExpiredApprovals(store);
|
|
71
86
|
const keysListKey = 'approval:keys';
|
|
72
87
|
const existingKeys = (yield store.get(keysListKey, pieces_framework_1.StoreScope.PROJECT)) || [];
|
|
73
88
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
89
|
+
// #region agent log
|
|
90
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:76',message:'After cleanup - checking available keys',data:{existingKeysCount:existingKeys.length,existingKeys:existingKeys.slice(0,5),isReaction,isTextReply,isGroupMessage},timestamp:Date.now(),hypothesisId:'D'})}).catch(()=>{});
|
|
91
|
+
// #endregion
|
|
74
92
|
// Try to find matching approval
|
|
75
93
|
let mapping = null;
|
|
76
94
|
let storeKey = null;
|
|
@@ -83,19 +101,87 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
83
101
|
// signal-cli returns timestamps in SECONDS, convert to milliseconds for matching
|
|
84
102
|
const targetTimestampSeconds = reaction.targetSentTimestamp || reaction.targetTimestamp;
|
|
85
103
|
const targetTimestampMs = targetTimestampSeconds * 1000;
|
|
86
|
-
const targetAuthor = reaction.targetAuthor;
|
|
87
104
|
const reactionEmoji = reaction.emoji;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
105
|
+
const messageSource = message.envelope.source;
|
|
106
|
+
|
|
107
|
+
console.log('[ReceiveMessages] DEBUG - Processing emoji reaction:', {
|
|
108
|
+
targetTimestampMs,
|
|
109
|
+
targetTimestampSeconds,
|
|
110
|
+
reactionEmoji,
|
|
111
|
+
messageSource,
|
|
112
|
+
isGroupMessage,
|
|
113
|
+
});
|
|
114
|
+
// #region agent log
|
|
115
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:93',message:'Emoji reaction - starting matching loop',data:{targetTimestampMs,targetTimestampSeconds,existingKeysCount:existingKeys.length,messageSource,isGroupMessage},timestamp:Date.now(),hypothesisId:'B'})}).catch(()=>{});
|
|
116
|
+
// #endregion
|
|
117
|
+
|
|
118
|
+
// Alle Approvals durchsuchen: Exakter Timestamp-Match + Empfänger-Validierung
|
|
119
|
+
for (const key of existingKeys) {
|
|
120
|
+
const candidateMapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
121
|
+
if (!candidateMapping) continue;
|
|
122
|
+
|
|
123
|
+
// Exakter Timestamp-Match (beide vom Signal-Netzwerk, müssen identisch sein)
|
|
124
|
+
// #region agent log
|
|
125
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:102',message:'Checking timestamp match',data:{key,candidateTimestampMs:candidateMapping.messageTimestampMs,targetTimestampMs,timestampMatch:candidateMapping.messageTimestampMs===targetTimestampMs},timestamp:Date.now(),hypothesisId:'B'})}).catch(()=>{});
|
|
126
|
+
// #endregion
|
|
127
|
+
if (candidateMapping.messageTimestampMs !== targetTimestampMs) continue;
|
|
128
|
+
|
|
129
|
+
console.log('[ReceiveMessages] DEBUG - Timestamp match found, checking recipient:', {
|
|
130
|
+
key,
|
|
131
|
+
candidateTimestampMs: candidateMapping.messageTimestampMs,
|
|
132
|
+
recipients: candidateMapping.recipients,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Empfänger-Validierung (1:1 vs. Gruppe)
|
|
136
|
+
const recipients = candidateMapping.recipients || [];
|
|
137
|
+
let isValidRecipient = false;
|
|
138
|
+
// #region agent log
|
|
139
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:110',message:'Checking recipient validation',data:{key,recipients,recipientsType:typeof recipients,recipientsIsArray:Array.isArray(recipients),isGroupMessage,messageSource},timestamp:Date.now(),hypothesisId:'C'})}).catch(()=>{});
|
|
140
|
+
// #endregion
|
|
141
|
+
|
|
142
|
+
if (isGroupMessage) {
|
|
143
|
+
// Bei Gruppen: Prüfe Gruppen-ID
|
|
144
|
+
const groupId = dataMessage.groupInfo.groupId;
|
|
145
|
+
isValidRecipient = Array.isArray(recipients) && recipients.includes(groupId);
|
|
146
|
+
console.log('[ReceiveMessages] DEBUG - Group recipient check:', {
|
|
147
|
+
groupId,
|
|
148
|
+
isValidRecipient,
|
|
149
|
+
});
|
|
150
|
+
// #region agent log
|
|
151
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:117',message:'Group recipient validation result',data:{key,groupId,recipients,isValidRecipient},timestamp:Date.now(),hypothesisId:'C'})}).catch(()=>{});
|
|
152
|
+
// #endregion
|
|
153
|
+
} else {
|
|
154
|
+
// Bei 1:1: Prüfe, ob Absender in recipients-Liste steht
|
|
155
|
+
isValidRecipient = Array.isArray(recipients) && recipients.includes(messageSource);
|
|
156
|
+
console.log('[ReceiveMessages] DEBUG - 1:1 recipient check:', {
|
|
157
|
+
messageSource,
|
|
158
|
+
isValidRecipient,
|
|
159
|
+
});
|
|
160
|
+
// #region agent log
|
|
161
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:125',message:'1:1 recipient validation result',data:{key,messageSource,recipients,isValidRecipient},timestamp:Date.now(),hypothesisId:'C'})}).catch(()=>{});
|
|
162
|
+
// #endregion
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (!isValidRecipient) continue;
|
|
166
|
+
|
|
167
|
+
// Prüfe, ob Emoji-Modus erlaubt ist
|
|
168
|
+
const acceptModes = candidateMapping.acceptReactionModes || [];
|
|
92
169
|
if (acceptModes.includes('emoji')) {
|
|
93
|
-
|
|
170
|
+
mapping = candidateMapping;
|
|
171
|
+
storeKey = key;
|
|
172
|
+
responseContent = reactionEmoji;
|
|
94
173
|
reactionType = 'emoji';
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
174
|
+
console.log('[ReceiveMessages] DEBUG - Emoji reaction match found:', {
|
|
175
|
+
key,
|
|
176
|
+
flowRunId: mapping.flowRunId,
|
|
177
|
+
reactionEmoji,
|
|
178
|
+
});
|
|
179
|
+
break; // Gefunden, Suche beenden
|
|
180
|
+
} else {
|
|
181
|
+
console.log('[ReceiveMessages] DEBUG - Emoji mode not allowed for this approval:', {
|
|
182
|
+
key,
|
|
183
|
+
acceptModes,
|
|
184
|
+
});
|
|
99
185
|
}
|
|
100
186
|
}
|
|
101
187
|
}
|
|
@@ -105,20 +191,87 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
105
191
|
// signal-cli returns timestamps in SECONDS, convert to milliseconds for matching
|
|
106
192
|
const quoteTimestampSeconds = quote.id || quote.timestamp;
|
|
107
193
|
const quoteTimestampMs = quoteTimestampSeconds * 1000;
|
|
108
|
-
const quoteAuthor = quote.author;
|
|
109
194
|
const replyText = dataMessage.message || '';
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
195
|
+
const messageSource = message.envelope.source;
|
|
196
|
+
|
|
197
|
+
console.log('[ReceiveMessages] DEBUG - Processing text reply (quote):', {
|
|
198
|
+
quoteTimestampMs,
|
|
199
|
+
quoteTimestampSeconds,
|
|
200
|
+
replyText: replyText.substring(0, 50), // First 50 chars for logging
|
|
201
|
+
messageSource,
|
|
202
|
+
isGroupMessage,
|
|
203
|
+
});
|
|
204
|
+
// #region agent log
|
|
205
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:145',message:'Text reply - starting matching loop',data:{quoteTimestampMs,quoteTimestampSeconds,existingKeysCount:existingKeys.length,messageSource,isGroupMessage},timestamp:Date.now(),hypothesisId:'B'})}).catch(()=>{});
|
|
206
|
+
// #endregion
|
|
207
|
+
|
|
208
|
+
// Alle Approvals durchsuchen: Exakter Timestamp-Match + Empfänger-Validierung
|
|
209
|
+
for (const key of existingKeys) {
|
|
210
|
+
const candidateMapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
211
|
+
if (!candidateMapping) continue;
|
|
212
|
+
|
|
213
|
+
// Exakter Timestamp-Match (beide vom Signal-Netzwerk, müssen identisch sein)
|
|
214
|
+
// #region agent log
|
|
215
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:154',message:'Checking timestamp match (quote)',data:{key,candidateTimestampMs:candidateMapping.messageTimestampMs,quoteTimestampMs,timestampMatch:candidateMapping.messageTimestampMs===quoteTimestampMs},timestamp:Date.now(),hypothesisId:'B'})}).catch(()=>{});
|
|
216
|
+
// #endregion
|
|
217
|
+
if (candidateMapping.messageTimestampMs !== quoteTimestampMs) continue;
|
|
218
|
+
|
|
219
|
+
console.log('[ReceiveMessages] DEBUG - Timestamp match found, checking recipient:', {
|
|
220
|
+
key,
|
|
221
|
+
candidateTimestampMs: candidateMapping.messageTimestampMs,
|
|
222
|
+
recipients: candidateMapping.recipients,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Empfänger-Validierung (1:1 vs. Gruppe)
|
|
226
|
+
const recipients = candidateMapping.recipients || [];
|
|
227
|
+
let isValidRecipient = false;
|
|
228
|
+
// #region agent log
|
|
229
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:162',message:'Checking recipient validation (quote)',data:{key,recipients,recipientsType:typeof recipients,recipientsIsArray:Array.isArray(recipients),isGroupMessage,messageSource},timestamp:Date.now(),hypothesisId:'C'})}).catch(()=>{});
|
|
230
|
+
// #endregion
|
|
231
|
+
|
|
232
|
+
if (isGroupMessage) {
|
|
233
|
+
// Bei Gruppen: Prüfe Gruppen-ID
|
|
234
|
+
const groupId = dataMessage.groupInfo.groupId;
|
|
235
|
+
isValidRecipient = Array.isArray(recipients) && recipients.includes(groupId);
|
|
236
|
+
console.log('[ReceiveMessages] DEBUG - Group recipient check:', {
|
|
237
|
+
groupId,
|
|
238
|
+
isValidRecipient,
|
|
239
|
+
});
|
|
240
|
+
// #region agent log
|
|
241
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:169',message:'Group recipient validation result (quote)',data:{key,groupId,recipients,isValidRecipient},timestamp:Date.now(),hypothesisId:'C'})}).catch(()=>{});
|
|
242
|
+
// #endregion
|
|
243
|
+
} else {
|
|
244
|
+
// Bei 1:1: Prüfe, ob Absender in recipients-Liste steht
|
|
245
|
+
isValidRecipient = Array.isArray(recipients) && recipients.includes(messageSource);
|
|
246
|
+
console.log('[ReceiveMessages] DEBUG - 1:1 recipient check:', {
|
|
247
|
+
messageSource,
|
|
248
|
+
isValidRecipient,
|
|
249
|
+
});
|
|
250
|
+
// #region agent log
|
|
251
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:177',message:'1:1 recipient validation result (quote)',data:{key,messageSource,recipients,isValidRecipient},timestamp:Date.now(),hypothesisId:'C'})}).catch(()=>{});
|
|
252
|
+
// #endregion
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!isValidRecipient) continue;
|
|
256
|
+
|
|
257
|
+
// Prüfe, ob Text-Modus erlaubt ist
|
|
258
|
+
const acceptModes = candidateMapping.acceptReactionModes || [];
|
|
115
259
|
if (acceptModes.includes('text')) {
|
|
116
|
-
|
|
260
|
+
mapping = candidateMapping;
|
|
261
|
+
storeKey = key;
|
|
262
|
+
responseContent = replyText;
|
|
117
263
|
reactionType = 'text';
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
264
|
+
console.log('[ReceiveMessages] DEBUG - Text reply match found:', {
|
|
265
|
+
key,
|
|
266
|
+
flowRunId: mapping.flowRunId,
|
|
267
|
+
replyText: replyText.substring(0, 50),
|
|
268
|
+
});
|
|
269
|
+
break; // Gefunden, Suche beenden
|
|
270
|
+
} else {
|
|
271
|
+
console.log('[ReceiveMessages] DEBUG - Text mode not allowed for this approval:', {
|
|
272
|
+
key,
|
|
273
|
+
acceptModes,
|
|
274
|
+
});
|
|
122
275
|
}
|
|
123
276
|
}
|
|
124
277
|
}
|
|
@@ -127,17 +280,17 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
127
280
|
const messageText = dataMessage.message || '';
|
|
128
281
|
const messageSource = message.envelope.source;
|
|
129
282
|
|
|
283
|
+
console.log('[ReceiveMessages] DEBUG - Processing direct message:', {
|
|
284
|
+
messageText: messageText.substring(0, 50), // First 50 chars for logging
|
|
285
|
+
messageSource,
|
|
286
|
+
});
|
|
287
|
+
|
|
130
288
|
// Iterate through all approval keys to find a match
|
|
289
|
+
// Keine Timeout-Prüfung mehr - cleanupExpiredApprovals hat bereits alle abgelaufenen entfernt
|
|
131
290
|
for (const key of existingKeys) {
|
|
132
291
|
const candidateMapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
133
292
|
if (!candidateMapping) continue;
|
|
134
293
|
|
|
135
|
-
// Check if expired
|
|
136
|
-
const ageInSeconds = currentTimestamp - candidateMapping.createdAt;
|
|
137
|
-
if (ageInSeconds > candidateMapping.timeoutSeconds) {
|
|
138
|
-
continue; // Skip expired mappings
|
|
139
|
-
}
|
|
140
|
-
|
|
141
294
|
// Check if direct mode is enabled
|
|
142
295
|
const acceptModes = candidateMapping.acceptReactionModes || [];
|
|
143
296
|
if (!acceptModes.includes('direct')) {
|
|
@@ -152,11 +305,19 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
152
305
|
storeKey = key;
|
|
153
306
|
responseContent = messageText; // Use the message text as response
|
|
154
307
|
reactionType = 'direct';
|
|
308
|
+
console.log('[ReceiveMessages] DEBUG - Direct message match found:', {
|
|
309
|
+
key,
|
|
310
|
+
flowRunId: mapping.flowRunId,
|
|
311
|
+
messageText: messageText.substring(0, 50),
|
|
312
|
+
});
|
|
155
313
|
break; // Found a match, stop searching
|
|
156
314
|
}
|
|
157
315
|
}
|
|
158
316
|
}
|
|
159
317
|
// If no matching approval found, return
|
|
318
|
+
// #region agent log
|
|
319
|
+
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'message-utils.js:200',message:'Matching result check',data:{mappingFound:!!mapping,responseContent:!!responseContent,reactionType,existingKeysCount:existingKeys.length},timestamp:Date.now(),hypothesisId:'D'})}).catch(()=>{});
|
|
320
|
+
// #endregion
|
|
160
321
|
if (!mapping || !responseContent) {
|
|
161
322
|
return { resumed: false };
|
|
162
323
|
}
|
|
@@ -168,19 +329,7 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
168
329
|
reactionType,
|
|
169
330
|
responseContent,
|
|
170
331
|
});
|
|
171
|
-
//
|
|
172
|
-
const ageInSeconds = currentTimestamp - mapping.createdAt;
|
|
173
|
-
const isExpired = ageInSeconds > mapping.timeoutSeconds;
|
|
174
|
-
if (isExpired) {
|
|
175
|
-
// Expired - delete and return
|
|
176
|
-
yield store.delete(storeKey, pieces_framework_1.StoreScope.PROJECT);
|
|
177
|
-
const flowRunMappingKey = `approval:flowRun:${mapping.flowRunId}`;
|
|
178
|
-
yield store.delete(flowRunMappingKey, pieces_framework_1.StoreScope.PROJECT);
|
|
179
|
-
const updatedKeys = existingKeys.filter(key => key !== storeKey);
|
|
180
|
-
yield store.put(keysListKey, updatedKeys, pieces_framework_1.StoreScope.PROJECT);
|
|
181
|
-
console.log('[ReceiveMessages] DEBUG - Approval expired');
|
|
182
|
-
return { resumed: false };
|
|
183
|
-
}
|
|
332
|
+
// Keine Timeout-Prüfung mehr - cleanupExpiredApprovals hat bereits alle abgelaufenen entfernt
|
|
184
333
|
// Resume the flow with responseContent
|
|
185
334
|
const resumeUrl = `${apiUrl}v1/flow-runs/${mapping.flowRunId}/requests/${mapping.requestId}?responseContent=${encodeURIComponent(responseContent)}&reactionType=${reactionType}&responder=${encodeURIComponent(responder || '')}`;
|
|
186
335
|
console.log('[ReceiveMessages] DEBUG - Attempting resume:', {
|