From 044e034719161ddbbff213b15c69f741e3e2f978 Mon Sep 17 00:00:00 2001 From: Waleed Date: Thu, 14 May 2026 11:33:16 -0700 Subject: [PATCH] fix(integrations): gdrive trashed search, slack blocks-with-file, slack get_message ts (#4600) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(integrations): gdrive trashed search, slack blocks-with-file, slack get_message ts - Google Drive search/list: skip default `trashed = false` when user query already specifies a `trashed = ...` predicate, so trashed-file searches work. - Slack send-message with files: forward `blocks` through to `files.completeUploadExternal` so Block Kit renders when files are attached. - Slack get_message: switch from `conversations.history` (oldest lower-bound returned the next message after) to `conversations.replies` with `ts=` for exact-match lookup, plus a defensive ts-equality guard and clearer error. * fix(google_drive): revert list.ts trashed guard — query is plain text, not gdrive syntax * fix(slack): omit initial_comment when blocks present so Block Kit actually renders on file uploads --- apps/sim/app/api/tools/slack/utils.ts | 17 ++++++++++++++--- apps/sim/tools/google_drive/list.ts | 7 +++++-- apps/sim/tools/google_drive/search.ts | 11 ++++++++--- apps/sim/tools/slack/get_message.ts | 23 ++++++++++++++++++----- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/apps/sim/app/api/tools/slack/utils.ts b/apps/sim/app/api/tools/slack/utils.ts index d74b078595..aebd295c30 100644 --- a/apps/sim/app/api/tools/slack/utils.ts +++ b/apps/sim/app/api/tools/slack/utils.ts @@ -141,7 +141,8 @@ async function completeSlackFileUpload( channel: string, text: string, accessToken: string, - threadTs?: string | null + threadTs?: string | null, + blocks?: unknown[] | null ): Promise<{ ok: boolean; files?: any[]; error?: string }> { const response = await fetch('https://slack.com/api/files.completeUploadExternal', { method: 'POST', @@ -152,7 +153,10 @@ async function completeSlackFileUpload( body: JSON.stringify({ files: uploadedFileIds.map((id) => ({ id })), channel_id: channel, - initial_comment: text, + // Per Slack docs for files.completeUploadExternal: if `initial_comment` + // is provided, `blocks` is silently ignored. So when blocks are present + // we omit initial_comment and let blocks render instead. + ...(blocks && blocks.length > 0 ? { blocks } : { initial_comment: text }), ...(threadTs && { thread_ts: threadTs }), }), }) @@ -295,7 +299,14 @@ export async function sendSlackMessage( } // Complete file upload with thread support - const completeData = await completeSlackFileUpload(fileIds, channel, text, accessToken, threadTs) + const completeData = await completeSlackFileUpload( + fileIds, + channel, + text, + accessToken, + threadTs, + blocks + ) if (!completeData.ok) { logger.error(`[${requestId}] Failed to complete upload:`, completeData.error) diff --git a/apps/sim/tools/google_drive/list.ts b/apps/sim/tools/google_drive/list.ts index afc4ee2c7c..52bc22b80e 100644 --- a/apps/sim/tools/google_drive/list.ts +++ b/apps/sim/tools/google_drive/list.ts @@ -66,8 +66,11 @@ export const listTool: ToolConfig value.replace(/\\/g, '\\\\').replace(/'/g, "\\'") - // Build the query conditions - const conditions = ['trashed = false'] // Always exclude trashed files + // Build the query conditions. `params.query` here is a plain-text name + // search term (wrapped in `name contains '...'` below), not Google Drive + // query syntax — so there's no caller-supplied `trashed` predicate to + // honour. Always exclude trashed files. + const conditions: string[] = ['trashed = false'] const folderId = (params.folderId || params.folderSelector)?.trim() if (folderId) { const escapedFolderId = escapeQueryValue(folderId) diff --git a/apps/sim/tools/google_drive/search.ts b/apps/sim/tools/google_drive/search.ts index 52eccb7ef6..33851c83ec 100644 --- a/apps/sim/tools/google_drive/search.ts +++ b/apps/sim/tools/google_drive/search.ts @@ -64,9 +64,14 @@ export const searchTool: ToolConfig = { id: 'slack_get_message', name: 'Slack Get Message', @@ -49,11 +52,10 @@ export const slackGetMessageTool: ToolConfig { - const url = new URL('https://slack.com/api/conversations.history') + const url = new URL('https://slack.com/api/conversations.replies') url.searchParams.append('channel', params.channel?.trim() ?? '') - url.searchParams.append('oldest', params.timestamp?.trim() ?? '') + url.searchParams.append('ts', params.timestamp?.trim() ?? '') url.searchParams.append('limit', '1') - url.searchParams.append('inclusive', 'true') return url.toString() }, method: 'GET', @@ -63,8 +65,9 @@ export const slackGetMessageTool: ToolConfig { + transformResponse: async (response: Response, params?: SlackGetMessageParams) => { const data = await response.json() + const requestedTs = params?.timestamp?.trim() ?? '' if (!data.ok) { if (data.error === 'missing_scope') { @@ -78,15 +81,25 @@ export const slackGetMessageTool: ToolConfig