piece-signal-cli-rest-api 0.2.19 → 0.2.20
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 +1 -1
- package/src/lib/actions/receive-messages.js +0 -39
- package/src/lib/actions/request-approval-message.js +0 -28
- package/src/lib/actions/resume-approval-flow.js +1 -36
- package/src/lib/common/message-utils.js +1 -160
- package/src/lib/triggers/new-group-member.js +0 -1
- package/src/lib/triggers/new-message-received.js +1 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piece-signal-cli-rest-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "echo \"piece-signal-cli-rest-api: kein zusätzlicher Build-Schritt erforderlich (bereits als JS ausgeliefert)\"",
|
|
6
6
|
"publish:npm": "npm publish --access public"
|
|
@@ -81,51 +81,12 @@ exports.receiveMessages = (0, pieces_framework_1.createAction)({
|
|
|
81
81
|
// Use HTTP GET for normal/native mode
|
|
82
82
|
messages = yield (0, message_utils_1.tryHttpReceive)(httpUrl, headers);
|
|
83
83
|
}
|
|
84
|
-
// #region agent log
|
|
85
|
-
for (const raw of messages) {
|
|
86
|
-
const env = (raw && raw.envelope) || {};
|
|
87
|
-
const dm = env.dataMessage || {};
|
|
88
|
-
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7', {
|
|
89
|
-
method: 'POST',
|
|
90
|
-
headers: { 'Content-Type': 'application/json' },
|
|
91
|
-
body: JSON.stringify({
|
|
92
|
-
location: 'receive-messages.js:raw',
|
|
93
|
-
message: 'Raw received Signal message',
|
|
94
|
-
data: {
|
|
95
|
-
source: env.source,
|
|
96
|
-
sourceNumber: env.sourceNumber,
|
|
97
|
-
sourceUuid: env.sourceUuid,
|
|
98
|
-
hasDataMessage: !!env.dataMessage,
|
|
99
|
-
messageText: (dm.message || '').substring(0, 100),
|
|
100
|
-
hasQuote: !!dm.quote,
|
|
101
|
-
quote: dm.quote ? {
|
|
102
|
-
id: dm.quote.id,
|
|
103
|
-
author: dm.quote.author,
|
|
104
|
-
timestamp: dm.quote.timestamp,
|
|
105
|
-
} : null,
|
|
106
|
-
hasReaction: !!dm.reaction,
|
|
107
|
-
reaction: dm.reaction ? {
|
|
108
|
-
emoji: dm.reaction.emoji,
|
|
109
|
-
targetTimestamp: dm.reaction.targetTimestamp,
|
|
110
|
-
targetSentTimestamp: dm.reaction.targetSentTimestamp,
|
|
111
|
-
} : null,
|
|
112
|
-
isGroupMessage: !!dm.groupInfo,
|
|
113
|
-
groupId: dm.groupInfo ? dm.groupInfo.groupId : null,
|
|
114
|
-
},
|
|
115
|
-
timestamp: Date.now(),
|
|
116
|
-
hypothesisId: 'RAW',
|
|
117
|
-
}),
|
|
118
|
-
}).catch(() => { });
|
|
119
|
-
}
|
|
120
|
-
// #endregion
|
|
121
84
|
// Cleanup expired approvals (also when no messages)
|
|
122
85
|
yield (0, message_utils_1.cleanupExpiredApprovals)(context.store);
|
|
123
86
|
// Process each message: try to resume approval flows if applicable
|
|
124
87
|
// Messages are still returned regardless of whether they triggered a resume
|
|
125
|
-
// Debug information is output via console.log (visible in Docker logs)
|
|
126
88
|
const apiUrl = ((_a = context.server) === null || _a === void 0 ? void 0 : _a.apiUrl) || '';
|
|
127
89
|
for (const message of messages) {
|
|
128
|
-
// This will output debug info via console.log
|
|
129
90
|
yield (0, message_utils_1.tryResumeApprovalFlow)(message, context.store, apiUrl);
|
|
130
91
|
}
|
|
131
92
|
// Return messages
|
|
@@ -85,24 +85,7 @@ exports.requestApprovalMessage = (0, pieces_framework_1.createAction)({
|
|
|
85
85
|
// Create store key using milliseconds for precise matching
|
|
86
86
|
// Store-Key mit Timestamp + eindeutiger Flow-Run-ID
|
|
87
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
88
|
const storeKey = `approval:${messageTimestampMs}:${context.run.id}`;
|
|
92
|
-
// DEBUG: Log storing approval mapping
|
|
93
|
-
console.log('[RequestApprovalMessage] DEBUG - Storing approval mapping:', {
|
|
94
|
-
storeKey,
|
|
95
|
-
timestampSeconds,
|
|
96
|
-
messageTimestampMs,
|
|
97
|
-
messageTimestamp,
|
|
98
|
-
targetAuthor,
|
|
99
|
-
formattedNumber,
|
|
100
|
-
flowRunId: context.run.id,
|
|
101
|
-
requestId,
|
|
102
|
-
responseTimestamp: response.timestamp,
|
|
103
|
-
responseTimestampType: typeof response.timestamp,
|
|
104
|
-
acceptReactionModes: accept_reaction_modes
|
|
105
|
-
});
|
|
106
89
|
// Create mapping value
|
|
107
90
|
const mapping = {
|
|
108
91
|
flowRunId: context.run.id,
|
|
@@ -115,22 +98,11 @@ exports.requestApprovalMessage = (0, pieces_framework_1.createAction)({
|
|
|
115
98
|
timeoutSeconds: timeout_seconds,
|
|
116
99
|
createdAt: createdAt,
|
|
117
100
|
};
|
|
118
|
-
// DEBUG: Log full mapping
|
|
119
|
-
console.log('[RequestApprovalMessage] DEBUG - Full mapping object:', mapping);
|
|
120
101
|
// Save mapping in Store (PROJECT-scoped)
|
|
121
102
|
yield context.store.put(storeKey, mapping, pieces_framework_1.StoreScope.PROJECT);
|
|
122
|
-
// DEBUG: Verify it was stored
|
|
123
|
-
const verifyMapping = yield context.store.get(storeKey, pieces_framework_1.StoreScope.PROJECT);
|
|
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
|
|
128
103
|
// Add key to approval keys list
|
|
129
104
|
const keysListKey = 'approval:keys';
|
|
130
105
|
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
|
|
134
106
|
if (!existingKeys.includes(storeKey)) {
|
|
135
107
|
existingKeys.push(storeKey);
|
|
136
108
|
yield context.store.put(keysListKey, existingKeys, pieces_framework_1.StoreScope.PROJECT);
|
|
@@ -39,27 +39,12 @@ exports.resumeApprovalFlow = (0, pieces_framework_1.createAction)({
|
|
|
39
39
|
const targetTimestamp = reaction.targetSentTimestamp;
|
|
40
40
|
const targetAuthor = reaction.targetAuthor;
|
|
41
41
|
const reactionEmoji = reaction.emoji;
|
|
42
|
-
// DEBUG: Log reaction data
|
|
43
|
-
console.log('[ResumeApprovalFlow] DEBUG - Reaction data:', {
|
|
44
|
-
targetTimestamp,
|
|
45
|
-
targetAuthor,
|
|
46
|
-
reactionEmoji,
|
|
47
|
-
fullReaction: reaction,
|
|
48
|
-
messageEnvelope: message.envelope
|
|
49
|
-
});
|
|
50
42
|
// Cleanup expired approvals
|
|
51
43
|
const keysListKey = 'approval:keys';
|
|
52
44
|
const existingKeys = (yield context.store.get(keysListKey, pieces_framework_1.StoreScope.PROJECT)) || [];
|
|
53
45
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
54
46
|
const validKeys = [];
|
|
55
47
|
const keysToDelete = [];
|
|
56
|
-
// DEBUG: Check all existing keys
|
|
57
|
-
console.log('[ResumeApprovalFlow] DEBUG - All approval keys in store:', existingKeys);
|
|
58
|
-
// DEBUG: Try to read each key to see what's stored
|
|
59
|
-
for (const key of existingKeys) {
|
|
60
|
-
const storedMapping = yield context.store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
61
|
-
console.log(`[ResumeApprovalFlow] DEBUG - Key "${key}" contains:`, storedMapping);
|
|
62
|
-
}
|
|
63
48
|
for (const key of existingKeys) {
|
|
64
49
|
const mapping = yield context.store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
65
50
|
if (mapping) {
|
|
@@ -86,22 +71,11 @@ exports.resumeApprovalFlow = (0, pieces_framework_1.createAction)({
|
|
|
86
71
|
}
|
|
87
72
|
// Look up the specific approval mapping
|
|
88
73
|
const storeKey = `approval:${targetTimestamp}:${targetAuthor}`;
|
|
89
|
-
// DEBUG: Log store key being searched
|
|
90
|
-
console.log('[ResumeApprovalFlow] DEBUG - Store key to search:', storeKey);
|
|
91
74
|
const mapping = yield context.store.get(storeKey, pieces_framework_1.StoreScope.PROJECT);
|
|
92
|
-
// DEBUG: Log mapping found
|
|
93
|
-
console.log('[ResumeApprovalFlow] DEBUG - Mapping found:', mapping);
|
|
94
75
|
if (!mapping) {
|
|
95
|
-
console.log('[ResumeApprovalFlow] DEBUG - No mapping found for key:', storeKey);
|
|
96
76
|
return {
|
|
97
77
|
success: false,
|
|
98
78
|
reason: 'not_an_approval_message',
|
|
99
|
-
debug: {
|
|
100
|
-
searchedKey: storeKey,
|
|
101
|
-
existingKeys: existingKeys,
|
|
102
|
-
targetTimestamp,
|
|
103
|
-
targetAuthor
|
|
104
|
-
}
|
|
105
79
|
};
|
|
106
80
|
}
|
|
107
81
|
// Check if expired
|
|
@@ -136,25 +110,16 @@ exports.resumeApprovalFlow = (0, pieces_framework_1.createAction)({
|
|
|
136
110
|
}
|
|
137
111
|
// Make HTTP request to resume the flow
|
|
138
112
|
const resumeUrl = `${apiUrl}v1/flow-runs/${mapping.flowRunId}/requests/${mapping.requestId}?action=${action}`;
|
|
139
|
-
// DEBUG: Log resume URL
|
|
140
|
-
console.log('[ResumeApprovalFlow] DEBUG - Resume URL:', resumeUrl);
|
|
141
113
|
try {
|
|
142
|
-
|
|
114
|
+
yield pieces_common_1.httpClient.sendRequest({
|
|
143
115
|
method: pieces_common_1.HttpMethod.POST,
|
|
144
116
|
url: resumeUrl,
|
|
145
117
|
headers: {
|
|
146
118
|
'Content-Type': 'application/json',
|
|
147
119
|
},
|
|
148
120
|
});
|
|
149
|
-
// DEBUG: Log resume response
|
|
150
|
-
console.log('[ResumeApprovalFlow] DEBUG - Resume response:', {
|
|
151
|
-
status: response.status,
|
|
152
|
-
body: response.body
|
|
153
|
-
});
|
|
154
121
|
}
|
|
155
122
|
catch (error) {
|
|
156
|
-
// DEBUG: Log error
|
|
157
|
-
console.error('[ResumeApprovalFlow] DEBUG - Resume error:', error);
|
|
158
123
|
// If resume fails, don't delete the mapping (might be retried)
|
|
159
124
|
return {
|
|
160
125
|
success: false,
|
|
@@ -18,18 +18,12 @@ function cleanupExpiredApprovals(store) {
|
|
|
18
18
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
19
19
|
const validKeys = [];
|
|
20
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
|
|
24
21
|
for (const key of existingKeys) {
|
|
25
22
|
const mapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
26
23
|
if (mapping) {
|
|
27
24
|
// Check if expired
|
|
28
25
|
const ageInSeconds = currentTimestamp - mapping.createdAt;
|
|
29
26
|
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
27
|
if (isExpired) {
|
|
34
28
|
// Expired - delete it and flowRunId mapping
|
|
35
29
|
yield store.delete(key, pieces_framework_1.StoreScope.PROJECT);
|
|
@@ -50,9 +44,6 @@ function cleanupExpiredApprovals(store) {
|
|
|
50
44
|
if (keysToDelete.length > 0) {
|
|
51
45
|
yield store.put(keysListKey, validKeys, pieces_framework_1.StoreScope.PROJECT);
|
|
52
46
|
}
|
|
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
|
|
56
47
|
});
|
|
57
48
|
}
|
|
58
49
|
// Function to automatically resume approval flows
|
|
@@ -63,9 +54,6 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
63
54
|
if (!dataMessage) {
|
|
64
55
|
return { resumed: false };
|
|
65
56
|
}
|
|
66
|
-
// #region agent log
|
|
67
|
-
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:62',message:'Incoming dataMessage details',data:{hasReaction:!!dataMessage.reaction,hasQuote:!!dataMessage.quote,isGroupMessage:!!dataMessage.groupInfo,text:(dataMessage.message||'').substring(0,100),source:message.envelope?.source,quoteSummary:dataMessage.quote?{id:dataMessage.quote.id,author:dataMessage.quote.author,timestamp:dataMessage.quote.timestamp}:null,reactionSummary:dataMessage.reaction?{emoji:dataMessage.reaction.emoji,targetTimestamp:dataMessage.reaction.targetTimestamp,targetSentTimestamp:dataMessage.reaction.targetSentTimestamp}:null},timestamp:Date.now(),hypothesisId:'ENTRY'})}).catch(()=>{});
|
|
68
|
-
// #endregion
|
|
69
57
|
// Check if it's a group message
|
|
70
58
|
const isGroupMessage = !!dataMessage.groupInfo;
|
|
71
59
|
|
|
@@ -77,11 +65,6 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
77
65
|
if (!isReaction && !isTextReply && isGroupMessage) {
|
|
78
66
|
return { resumed: false };
|
|
79
67
|
}
|
|
80
|
-
console.log('[ReceiveMessages] DEBUG - Processing message:', {
|
|
81
|
-
hasReaction: isReaction,
|
|
82
|
-
hasQuote: isTextReply,
|
|
83
|
-
isGroupMessage: isGroupMessage,
|
|
84
|
-
});
|
|
85
68
|
// Cleanup expired approvals
|
|
86
69
|
// WICHTIG: cleanupExpiredApprovals ist die EINZIGE Stelle für Timeout-Entscheidungen.
|
|
87
70
|
// Alle nachfolgenden Matching-Schritte arbeiten nur auf bereits gefilterten (nicht abgelaufenen) Approvals.
|
|
@@ -89,9 +72,6 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
89
72
|
const keysListKey = 'approval:keys';
|
|
90
73
|
const existingKeys = (yield store.get(keysListKey, pieces_framework_1.StoreScope.PROJECT)) || [];
|
|
91
74
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
92
|
-
// #region agent log
|
|
93
|
-
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(()=>{});
|
|
94
|
-
// #endregion
|
|
95
75
|
// Try to find matching approval
|
|
96
76
|
let mapping = null;
|
|
97
77
|
let storeKey = null;
|
|
@@ -107,62 +87,25 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
107
87
|
const reactionEmoji = reaction.emoji;
|
|
108
88
|
const messageSource = message.envelope.source;
|
|
109
89
|
|
|
110
|
-
console.log('[ReceiveMessages] DEBUG - Processing emoji reaction:', {
|
|
111
|
-
targetTimestampMs,
|
|
112
|
-
targetTimestampSeconds,
|
|
113
|
-
reactionEmoji,
|
|
114
|
-
messageSource,
|
|
115
|
-
isGroupMessage,
|
|
116
|
-
});
|
|
117
|
-
// #region agent log
|
|
118
|
-
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(()=>{});
|
|
119
|
-
// #endregion
|
|
120
|
-
|
|
121
90
|
// Alle Approvals durchsuchen: Exakter Timestamp-Match + Empfänger-Validierung
|
|
122
91
|
for (const key of existingKeys) {
|
|
123
92
|
const candidateMapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
124
93
|
if (!candidateMapping) continue;
|
|
125
94
|
|
|
126
95
|
// Exakter Timestamp-Match (beide vom Signal-Netzwerk, müssen identisch sein)
|
|
127
|
-
// #region agent log
|
|
128
|
-
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(()=>{});
|
|
129
|
-
// #endregion
|
|
130
96
|
if (candidateMapping.messageTimestampMs !== targetTimestampMs) continue;
|
|
131
97
|
|
|
132
|
-
console.log('[ReceiveMessages] DEBUG - Timestamp match found, checking recipient:', {
|
|
133
|
-
key,
|
|
134
|
-
candidateTimestampMs: candidateMapping.messageTimestampMs,
|
|
135
|
-
recipients: candidateMapping.recipients,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
98
|
// Empfänger-Validierung (1:1 vs. Gruppe)
|
|
139
99
|
const recipients = candidateMapping.recipients || [];
|
|
140
100
|
let isValidRecipient = false;
|
|
141
|
-
// #region agent log
|
|
142
|
-
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(()=>{});
|
|
143
|
-
// #endregion
|
|
144
101
|
|
|
145
102
|
if (isGroupMessage) {
|
|
146
103
|
// Bei Gruppen: Prüfe Gruppen-ID
|
|
147
104
|
const groupId = dataMessage.groupInfo.groupId;
|
|
148
105
|
isValidRecipient = Array.isArray(recipients) && recipients.includes(groupId);
|
|
149
|
-
console.log('[ReceiveMessages] DEBUG - Group recipient check:', {
|
|
150
|
-
groupId,
|
|
151
|
-
isValidRecipient,
|
|
152
|
-
});
|
|
153
|
-
// #region agent log
|
|
154
|
-
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(()=>{});
|
|
155
|
-
// #endregion
|
|
156
106
|
} else {
|
|
157
107
|
// Bei 1:1: Prüfe, ob Absender in recipients-Liste steht
|
|
158
108
|
isValidRecipient = Array.isArray(recipients) && recipients.includes(messageSource);
|
|
159
|
-
console.log('[ReceiveMessages] DEBUG - 1:1 recipient check:', {
|
|
160
|
-
messageSource,
|
|
161
|
-
isValidRecipient,
|
|
162
|
-
});
|
|
163
|
-
// #region agent log
|
|
164
|
-
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(()=>{});
|
|
165
|
-
// #endregion
|
|
166
109
|
}
|
|
167
110
|
|
|
168
111
|
if (!isValidRecipient) continue;
|
|
@@ -174,17 +117,7 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
174
117
|
storeKey = key;
|
|
175
118
|
responseContent = reactionEmoji;
|
|
176
119
|
reactionType = 'emoji';
|
|
177
|
-
console.log('[ReceiveMessages] DEBUG - Emoji reaction match found:', {
|
|
178
|
-
key,
|
|
179
|
-
flowRunId: mapping.flowRunId,
|
|
180
|
-
reactionEmoji,
|
|
181
|
-
});
|
|
182
120
|
break; // Gefunden, Suche beenden
|
|
183
|
-
} else {
|
|
184
|
-
console.log('[ReceiveMessages] DEBUG - Emoji mode not allowed for this approval:', {
|
|
185
|
-
key,
|
|
186
|
-
acceptModes,
|
|
187
|
-
});
|
|
188
121
|
}
|
|
189
122
|
}
|
|
190
123
|
}
|
|
@@ -197,62 +130,25 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
197
130
|
const replyText = dataMessage.message || '';
|
|
198
131
|
const messageSource = message.envelope.source;
|
|
199
132
|
|
|
200
|
-
console.log('[ReceiveMessages] DEBUG - Processing text reply (quote):', {
|
|
201
|
-
quoteTimestampMs,
|
|
202
|
-
quoteTimestampSeconds,
|
|
203
|
-
replyText: replyText.substring(0, 50), // First 50 chars for logging
|
|
204
|
-
messageSource,
|
|
205
|
-
isGroupMessage,
|
|
206
|
-
});
|
|
207
|
-
// #region agent log
|
|
208
|
-
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(()=>{});
|
|
209
|
-
// #endregion
|
|
210
|
-
|
|
211
133
|
// Alle Approvals durchsuchen: Exakter Timestamp-Match + Empfänger-Validierung
|
|
212
134
|
for (const key of existingKeys) {
|
|
213
135
|
const candidateMapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
|
|
214
136
|
if (!candidateMapping) continue;
|
|
215
137
|
|
|
216
138
|
// Exakter Timestamp-Match (beide vom Signal-Netzwerk, müssen identisch sein)
|
|
217
|
-
// #region agent log
|
|
218
|
-
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(()=>{});
|
|
219
|
-
// #endregion
|
|
220
139
|
if (candidateMapping.messageTimestampMs !== quoteTimestampMs) continue;
|
|
221
140
|
|
|
222
|
-
console.log('[ReceiveMessages] DEBUG - Timestamp match found, checking recipient:', {
|
|
223
|
-
key,
|
|
224
|
-
candidateTimestampMs: candidateMapping.messageTimestampMs,
|
|
225
|
-
recipients: candidateMapping.recipients,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
141
|
// Empfänger-Validierung (1:1 vs. Gruppe)
|
|
229
142
|
const recipients = candidateMapping.recipients || [];
|
|
230
143
|
let isValidRecipient = false;
|
|
231
|
-
// #region agent log
|
|
232
|
-
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(()=>{});
|
|
233
|
-
// #endregion
|
|
234
144
|
|
|
235
145
|
if (isGroupMessage) {
|
|
236
146
|
// Bei Gruppen: Prüfe Gruppen-ID
|
|
237
147
|
const groupId = dataMessage.groupInfo.groupId;
|
|
238
148
|
isValidRecipient = Array.isArray(recipients) && recipients.includes(groupId);
|
|
239
|
-
console.log('[ReceiveMessages] DEBUG - Group recipient check:', {
|
|
240
|
-
groupId,
|
|
241
|
-
isValidRecipient,
|
|
242
|
-
});
|
|
243
|
-
// #region agent log
|
|
244
|
-
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(()=>{});
|
|
245
|
-
// #endregion
|
|
246
149
|
} else {
|
|
247
150
|
// Bei 1:1: Prüfe, ob Absender in recipients-Liste steht
|
|
248
151
|
isValidRecipient = Array.isArray(recipients) && recipients.includes(messageSource);
|
|
249
|
-
console.log('[ReceiveMessages] DEBUG - 1:1 recipient check:', {
|
|
250
|
-
messageSource,
|
|
251
|
-
isValidRecipient,
|
|
252
|
-
});
|
|
253
|
-
// #region agent log
|
|
254
|
-
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(()=>{});
|
|
255
|
-
// #endregion
|
|
256
152
|
}
|
|
257
153
|
|
|
258
154
|
if (!isValidRecipient) continue;
|
|
@@ -264,17 +160,7 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
264
160
|
storeKey = key;
|
|
265
161
|
responseContent = replyText;
|
|
266
162
|
reactionType = 'text';
|
|
267
|
-
console.log('[ReceiveMessages] DEBUG - Text reply match found:', {
|
|
268
|
-
key,
|
|
269
|
-
flowRunId: mapping.flowRunId,
|
|
270
|
-
replyText: replyText.substring(0, 50),
|
|
271
|
-
});
|
|
272
163
|
break; // Gefunden, Suche beenden
|
|
273
|
-
} else {
|
|
274
|
-
console.log('[ReceiveMessages] DEBUG - Text mode not allowed for this approval:', {
|
|
275
|
-
key,
|
|
276
|
-
acceptModes,
|
|
277
|
-
});
|
|
278
164
|
}
|
|
279
165
|
}
|
|
280
166
|
}
|
|
@@ -283,11 +169,6 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
283
169
|
const messageText = dataMessage.message || '';
|
|
284
170
|
const messageSource = message.envelope.source;
|
|
285
171
|
|
|
286
|
-
console.log('[ReceiveMessages] DEBUG - Processing direct message:', {
|
|
287
|
-
messageText: messageText.substring(0, 50), // First 50 chars for logging
|
|
288
|
-
messageSource,
|
|
289
|
-
});
|
|
290
|
-
|
|
291
172
|
// Iterate through all approval keys to find a match
|
|
292
173
|
// Keine Timeout-Prüfung mehr - cleanupExpiredApprovals hat bereits alle abgelaufenen entfernt
|
|
293
174
|
for (const key of existingKeys) {
|
|
@@ -308,42 +189,17 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
308
189
|
storeKey = key;
|
|
309
190
|
responseContent = messageText; // Use the message text as response
|
|
310
191
|
reactionType = 'direct';
|
|
311
|
-
console.log('[ReceiveMessages] DEBUG - Direct message match found:', {
|
|
312
|
-
key,
|
|
313
|
-
flowRunId: mapping.flowRunId,
|
|
314
|
-
messageText: messageText.substring(0, 50),
|
|
315
|
-
});
|
|
316
192
|
break; // Found a match, stop searching
|
|
317
193
|
}
|
|
318
194
|
}
|
|
319
195
|
}
|
|
320
196
|
// If no matching approval found, return
|
|
321
|
-
// #region agent log
|
|
322
|
-
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(()=>{});
|
|
323
|
-
// #endregion
|
|
324
197
|
if (!mapping || !responseContent) {
|
|
325
198
|
return { resumed: false };
|
|
326
199
|
}
|
|
327
|
-
console.log('[ReceiveMessages] DEBUG - Mapping found:', {
|
|
328
|
-
flowRunId: mapping.flowRunId,
|
|
329
|
-
requestId: mapping.requestId,
|
|
330
|
-
messageTimestampMs: mapping.messageTimestampMs,
|
|
331
|
-
acceptReactionModes: mapping.acceptReactionModes,
|
|
332
|
-
reactionType,
|
|
333
|
-
responseContent,
|
|
334
|
-
});
|
|
335
200
|
// Keine Timeout-Prüfung mehr - cleanupExpiredApprovals hat bereits alle abgelaufenen entfernt
|
|
336
201
|
// Resume the flow with responseContent
|
|
337
202
|
const resumeUrl = `${apiUrl}v1/flow-runs/${mapping.flowRunId}/requests/${mapping.requestId}?responseContent=${encodeURIComponent(responseContent)}&reactionType=${reactionType}&responder=${encodeURIComponent(responder || '')}`;
|
|
338
|
-
console.log('[ReceiveMessages] DEBUG - Attempting resume:', {
|
|
339
|
-
resumeUrl,
|
|
340
|
-
apiUrl,
|
|
341
|
-
flowRunId: mapping.flowRunId,
|
|
342
|
-
requestId: mapping.requestId,
|
|
343
|
-
responseContent,
|
|
344
|
-
reactionType,
|
|
345
|
-
responder,
|
|
346
|
-
});
|
|
347
203
|
try {
|
|
348
204
|
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
349
205
|
method: pieces_common_1.HttpMethod.POST,
|
|
@@ -353,13 +209,6 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
353
209
|
},
|
|
354
210
|
body: {},
|
|
355
211
|
});
|
|
356
|
-
console.log('[ReceiveMessages] DEBUG - Resume successful:', {
|
|
357
|
-
flowRunId: mapping.flowRunId,
|
|
358
|
-
responseContent,
|
|
359
|
-
reactionType,
|
|
360
|
-
responseStatus: response.status,
|
|
361
|
-
responseBody: response.body,
|
|
362
|
-
});
|
|
363
212
|
// Delete mapping from Store (cleanup) - only first reaction
|
|
364
213
|
yield store.delete(storeKey, pieces_framework_1.StoreScope.PROJECT);
|
|
365
214
|
// Delete flowRunId mapping
|
|
@@ -368,19 +217,11 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
|
|
|
368
217
|
// Remove key from approval keys list
|
|
369
218
|
const finalKeys = existingKeys.filter(key => key !== storeKey);
|
|
370
219
|
yield store.put(keysListKey, finalKeys, pieces_framework_1.StoreScope.PROJECT);
|
|
371
|
-
console.log('[ReceiveMessages] DEBUG - Cleanup completed');
|
|
372
220
|
return { resumed: true, responseContent, reactionType };
|
|
373
221
|
}
|
|
374
222
|
catch (error) {
|
|
375
|
-
// If resume fails,
|
|
223
|
+
// If resume fails, don't throw - message will still be returned
|
|
376
224
|
// Mapping remains for retry (will be cleaned up by cleanupExpiredApprovals after timeout)
|
|
377
|
-
console.error('[ReceiveMessages] DEBUG - Resume failed:', {
|
|
378
|
-
error: error instanceof Error ? error.message : String(error),
|
|
379
|
-
errorStack: error instanceof Error ? error.stack : undefined,
|
|
380
|
-
resumeUrl,
|
|
381
|
-
flowRunId: mapping.flowRunId,
|
|
382
|
-
reason: 'resume_failed',
|
|
383
|
-
});
|
|
384
225
|
return { resumed: false };
|
|
385
226
|
}
|
|
386
227
|
});
|
|
@@ -276,53 +276,15 @@ exports.newMessageReceived = (0, pieces_framework_1.createTrigger)({
|
|
|
276
276
|
// Get messages from polling
|
|
277
277
|
const messages = yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
278
278
|
const apiUrl = ((_a = context.server) === null || _a === void 0 ? void 0 : _a.apiUrl) || '';
|
|
279
|
-
// #region agent log
|
|
280
|
-
for (const raw of messages) {
|
|
281
|
-
const env = (raw && raw.envelope) || {};
|
|
282
|
-
const dm = env.dataMessage || {};
|
|
283
|
-
fetch('http://10.3.0.249:7243/ingest/103f08fb-273f-440d-bbe5-4f1e30168ab7', {
|
|
284
|
-
method: 'POST',
|
|
285
|
-
headers: { 'Content-Type': 'application/json' },
|
|
286
|
-
body: JSON.stringify({
|
|
287
|
-
location: 'new-message-received.js:raw',
|
|
288
|
-
message: 'Trigger raw Signal message',
|
|
289
|
-
data: {
|
|
290
|
-
source: env.source,
|
|
291
|
-
sourceNumber: env.sourceNumber,
|
|
292
|
-
sourceUuid: env.sourceUuid,
|
|
293
|
-
messageText: (dm.message || '').substring(0, 100),
|
|
294
|
-
hasQuote: !!dm.quote,
|
|
295
|
-
quote: dm.quote ? {
|
|
296
|
-
id: dm.quote.id,
|
|
297
|
-
author: dm.quote.author,
|
|
298
|
-
timestamp: dm.quote.timestamp,
|
|
299
|
-
} : null,
|
|
300
|
-
hasReaction: !!dm.reaction,
|
|
301
|
-
reaction: dm.reaction ? {
|
|
302
|
-
emoji: dm.reaction.emoji,
|
|
303
|
-
targetTimestamp: dm.reaction.targetTimestamp,
|
|
304
|
-
targetSentTimestamp: dm.reaction.targetSentTimestamp,
|
|
305
|
-
} : null,
|
|
306
|
-
isGroupMessage: !!dm.groupInfo,
|
|
307
|
-
groupId: dm.groupInfo ? dm.groupInfo.groupId : null,
|
|
308
|
-
},
|
|
309
|
-
timestamp: Date.now(),
|
|
310
|
-
hypothesisId: 'RAW_TRIGGER',
|
|
311
|
-
}),
|
|
312
|
-
}).catch(() => { });
|
|
313
|
-
}
|
|
314
|
-
// #endregion
|
|
315
279
|
// Cleanup expired approvals (also when no messages)
|
|
316
280
|
yield message_utils_1.cleanupExpiredApprovals(context.store);
|
|
317
281
|
// Process each message: try to resume approval flows if applicable
|
|
318
282
|
// Messages are still returned regardless of whether they triggered a resume
|
|
319
|
-
// Debug information is output via console.log (visible in Docker logs)
|
|
320
283
|
for (const message of messages) {
|
|
321
284
|
const signalMessage = message;
|
|
322
|
-
// This will output debug info via console.log
|
|
323
285
|
yield message_utils_1.tryResumeApprovalFlow(signalMessage, context.store, apiUrl);
|
|
324
286
|
}
|
|
325
|
-
// Return messages
|
|
287
|
+
// Return messages
|
|
326
288
|
return messages;
|
|
327
289
|
});
|
|
328
290
|
},
|