piece-signal-cli-rest-api 0.2.13 → 0.2.14

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,6 @@
1
1
  {
2
2
  "name": "piece-signal-cli-rest-api",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "dependencies": {
5
5
  "@sinclair/typebox": "0.34.11",
6
6
  "ai": "5.0.104",
@@ -28,11 +28,11 @@ exports.requestApprovalMessage = (0, pieces_framework_1.createAction)({
28
28
  options: {
29
29
  options: [
30
30
  { label: 'Emoji Reactions', value: 'emoji' },
31
- { label: 'Text Replies', value: 'text' },
32
- { label: 'Both', value: 'both' }
31
+ { label: 'Text Replies (Quote)', value: 'text' },
32
+ { label: 'Direct Messages (1:1 only)', value: 'direct' }
33
33
  ]
34
34
  },
35
- defaultValue: ['both']
35
+ defaultValue: ['text']
36
36
  }),
37
37
  timeout_seconds: pieces_framework_1.Property.Number({
38
38
  displayName: 'Timeout (seconds)',
@@ -44,7 +44,7 @@ exports.requestApprovalMessage = (0, pieces_framework_1.createAction)({
44
44
  run(context) {
45
45
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
46
46
  if (context.executionType === shared_1.ExecutionType.BEGIN) {
47
- const { number, recipients, message, accept_reaction_modes = ['both'], timeout_seconds = 86400 } = context.propsValue;
47
+ const { number, recipients, message, accept_reaction_modes = ['text'], timeout_seconds = 86400 } = context.propsValue;
48
48
  (0, shared_2.assertNotNullOrUndefined)(message, 'message');
49
49
  (0, shared_2.assertNotNullOrUndefined)(recipients, 'recipients');
50
50
  const apiClient = new api_client_1.SignalCliApiClient(context.auth.props);
@@ -105,6 +105,7 @@ exports.requestApprovalMessage = (0, pieces_framework_1.createAction)({
105
105
  messageTimestampMs: messageTimestampMs,
106
106
  messageTimestamp: messageTimestamp,
107
107
  targetAuthor: targetAuthor,
108
+ recipients: recipients,
108
109
  acceptReactionModes: accept_reaction_modes,
109
110
  timeoutSeconds: timeout_seconds,
110
111
  createdAt: createdAt,
@@ -50,15 +50,21 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
50
50
  if (!dataMessage) {
51
51
  return { resumed: false };
52
52
  }
53
+ // Check if it's a group message
54
+ const isGroupMessage = !!dataMessage.groupInfo;
55
+
53
56
  // Check if it's a reaction or a quote (text reply)
54
57
  const isReaction = !!dataMessage.reaction;
55
58
  const isTextReply = !!dataMessage.quote;
56
- if (!isReaction && !isTextReply) {
59
+
60
+ // If it's neither a reaction nor a quote, and it's a group message, ignore it
61
+ if (!isReaction && !isTextReply && isGroupMessage) {
57
62
  return { resumed: false };
58
63
  }
59
64
  console.log('[ReceiveMessages] DEBUG - Processing message:', {
60
65
  hasReaction: isReaction,
61
66
  hasQuote: isTextReply,
67
+ isGroupMessage: isGroupMessage,
62
68
  });
63
69
  // Cleanup expired approvals
64
70
  yield cleanupExpiredApprovals(store);
@@ -82,8 +88,8 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
82
88
  storeKey = `approval:${targetTimestampMs}:${targetAuthor}`;
83
89
  mapping = yield store.get(storeKey, pieces_framework_1.StoreScope.PROJECT);
84
90
  if (mapping) {
85
- const acceptModes = mapping.acceptReactionModes || ['both'];
86
- if (acceptModes.includes('emoji') || acceptModes.includes('both')) {
91
+ const acceptModes = mapping.acceptReactionModes || [];
92
+ if (acceptModes.includes('emoji')) {
87
93
  responseContent = reactionEmoji; // Return the emoji directly
88
94
  reactionType = 'emoji';
89
95
  }
@@ -105,8 +111,8 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
105
111
  storeKey = `approval:${quoteTimestampMs}:${quoteAuthor}`;
106
112
  mapping = yield store.get(storeKey, pieces_framework_1.StoreScope.PROJECT);
107
113
  if (mapping) {
108
- const acceptModes = mapping.acceptReactionModes || ['both'];
109
- if (acceptModes.includes('text') || acceptModes.includes('both')) {
114
+ const acceptModes = mapping.acceptReactionModes || [];
115
+ if (acceptModes.includes('text')) {
110
116
  responseContent = replyText; // Return the text directly
111
117
  reactionType = 'text';
112
118
  }
@@ -116,6 +122,40 @@ function tryResumeApprovalFlow(message, store, apiUrl) {
116
122
  }
117
123
  }
118
124
  }
125
+ // Handle Direct Messages (1:1 only) - if no reaction/quote found
126
+ if (!mapping && !isGroupMessage) {
127
+ const messageText = dataMessage.message || '';
128
+ const messageSource = message.envelope.source;
129
+
130
+ // Iterate through all approval keys to find a match
131
+ for (const key of existingKeys) {
132
+ const candidateMapping = yield store.get(key, pieces_framework_1.StoreScope.PROJECT);
133
+ if (!candidateMapping) continue;
134
+
135
+ // Check if expired
136
+ const ageInSeconds = currentTimestamp - candidateMapping.createdAt;
137
+ if (ageInSeconds > candidateMapping.timeoutSeconds) {
138
+ continue; // Skip expired mappings
139
+ }
140
+
141
+ // Check if direct mode is enabled
142
+ const acceptModes = candidateMapping.acceptReactionModes || [];
143
+ if (!acceptModes.includes('direct')) {
144
+ continue; // Direct mode not enabled for this approval
145
+ }
146
+
147
+ // Check if the message source is one of the recipients
148
+ const recipients = candidateMapping.recipients || [];
149
+ if (Array.isArray(recipients) && recipients.includes(messageSource)) {
150
+ // Found a match! This is a 1:1 conversation response
151
+ mapping = candidateMapping;
152
+ storeKey = key;
153
+ responseContent = messageText; // Use the message text as response
154
+ reactionType = 'direct';
155
+ break; // Found a match, stop searching
156
+ }
157
+ }
158
+ }
119
159
  // If no matching approval found, return
120
160
  if (!mapping || !responseContent) {
121
161
  return { resumed: false };