Skip to content

Commit 97ed7f6

Browse files
committed
revert fallback and message normalization in Find Message action
1 parent cfeb6ed commit 97ed7f6

File tree

1 file changed

+2
-132
lines changed

1 file changed

+2
-132
lines changed

components/slack_v2/actions/find-message/find-message.mjs

Lines changed: 2 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -48,65 +48,6 @@ export default {
4848
},
4949
},
5050
methods: {
51-
normalizeAssistantMatch(match) {
52-
if (!match || typeof match !== "object") {
53-
return match;
54-
}
55-
const {
56-
author_user_id: authorUserId,
57-
team_id: teamId,
58-
channel_id: channelId,
59-
message_ts: messageTs,
60-
content,
61-
permalink,
62-
is_author_bot: isAuthorBot,
63-
message,
64-
channel,
65-
...rest
66-
} = match;
67-
const baseMessage = typeof message === "object"
68-
? message
69-
: {};
70-
const channelInfo = channel && typeof channel === "object"
71-
? {
72-
...channel,
73-
id: channel.id || channelId,
74-
}
75-
: channelId
76-
? {
77-
id: channelId,
78-
}
79-
: undefined;
80-
const normalized = {
81-
type: "message",
82-
user: authorUserId,
83-
team: teamId,
84-
ts: messageTs,
85-
text: content,
86-
permalink,
87-
channel: channelInfo,
88-
...baseMessage,
89-
...rest,
90-
};
91-
if (isAuthorBot !== undefined && normalized.is_author_bot === undefined) {
92-
normalized.is_author_bot = isAuthorBot;
93-
}
94-
if (normalized.text == null) {
95-
normalized.text = baseMessage.text || content;
96-
}
97-
if (normalized.ts == null) {
98-
normalized.ts = baseMessage.ts || messageTs;
99-
}
100-
if (!normalized.channel && baseMessage.channel) {
101-
normalized.channel = baseMessage.channel;
102-
} else if (normalized.channel && baseMessage.channel && typeof baseMessage.channel === "object") {
103-
normalized.channel = {
104-
...normalized.channel,
105-
...baseMessage.channel,
106-
};
107-
}
108-
return normalized;
109-
},
11051
async searchWithAssistant(baseParams, maxResults) {
11152
const matches = [];
11253
let cursor;
@@ -117,73 +58,12 @@ export default {
11758
channel_types: "public_channel,private_channel",
11859
cursor,
11960
});
120-
const messages = (response.results?.messages || [])
121-
.map((item) => this.normalizeAssistantMatch(item));
122-
matches.push(...messages);
61+
matches.push(...response.results?.messages || []);
12362
cursor = response.response_metadata?.next_cursor;
12463
} while (cursor && matches.length < maxResults);
12564

12665
return matches.slice(0, maxResults);
12766
},
128-
async searchWithSearchMessages(baseParams, maxResults) {
129-
const matches = [];
130-
let page = 1;
131-
const count = Math.min(Math.max(maxResults, 1), 100);
132-
133-
while (matches.length < maxResults) {
134-
const response = await this.slack.searchMessages({
135-
...baseParams,
136-
count,
137-
page,
138-
});
139-
const pageMatches = response.messages?.matches || [];
140-
matches.push(...pageMatches);
141-
142-
if (matches.length >= maxResults) {
143-
break;
144-
}
145-
146-
const pagination = response.messages?.pagination;
147-
const paging = response.messages?.paging;
148-
const hasMore = pagination
149-
? pagination.page < pagination.page_count
150-
: paging
151-
? paging.page < paging.pages
152-
: false;
153-
154-
if (!hasMore) {
155-
break;
156-
}
157-
158-
page += 1;
159-
}
160-
161-
return matches.slice(0, maxResults);
162-
},
163-
shouldFallbackToSearchMessages(error) {
164-
const errorCode = typeof error === "string"
165-
? error
166-
: error?.data?.error || error?.message;
167-
168-
if (!errorCode?.includes("missing_scope")) {
169-
return false;
170-
}
171-
172-
const providedSources = [
173-
error?.data?.provided,
174-
error?.provided,
175-
error?.original?.data?.provided,
176-
].filter(Boolean);
177-
178-
const providedScopes = providedSources
179-
.flatMap((value) => Array.isArray(value)
180-
? value
181-
: String(value).split(","))
182-
.map((scope) => scope.trim())
183-
.filter(Boolean);
184-
185-
return providedScopes.includes("search:read");
186-
},
18767
},
18868
async run({ $ }) {
18969
const maxResults = Math.max(this.maxResults ?? 20, 1);
@@ -192,17 +72,7 @@ export default {
19272
sort: this.sort,
19373
sort_dir: this.sortDirection,
19474
};
195-
let matches;
196-
197-
try {
198-
matches = await this.searchWithAssistant(baseParams, maxResults);
199-
} catch (error) {
200-
if (this.shouldFallbackToSearchMessages(error)) {
201-
matches = await this.searchWithSearchMessages(baseParams, maxResults);
202-
} else {
203-
throw error;
204-
}
205-
}
75+
const matches = await this.searchWithAssistant(baseParams, maxResults);
20676

20777
$.export("$summary", `Found ${matches.length} matching message${matches.length === 1
20878
? ""

0 commit comments

Comments
 (0)