Skip to content

Commit 6e5e8de

Browse files
committed
fix
1 parent 66b954d commit 6e5e8de

File tree

6 files changed

+49
-28
lines changed

6 files changed

+49
-28
lines changed

apps/sim/blocks/blocks/discord.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DiscordIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { normalizeFileInput } from '@/blocks/utils'
45
import type { DiscordResponse } from '@/tools/discord/types'
56

67
export const DiscordBlock: BlockConfig<DiscordResponse> = {
@@ -579,17 +580,11 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
579580

580581
switch (params.operation) {
581582
case 'discord_send_message': {
582-
const fileParam = params.attachmentFiles || params.files
583-
const normalizedFiles = fileParam
584-
? Array.isArray(fileParam)
585-
? fileParam
586-
: [fileParam]
587-
: undefined
588583
return {
589584
...commonParams,
590585
channelId: params.channelId,
591586
content: params.content,
592-
files: normalizedFiles,
587+
files: normalizeFileInput(params.attachmentFiles || params.files),
593588
}
594589
}
595590
case 'discord_get_messages':

apps/sim/blocks/blocks/jira.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { JiraIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { normalizeFileInput } from '@/blocks/utils'
45
import type { JiraResponse } from '@/tools/jira/types'
56
import { getTrigger } from '@/triggers'
67

@@ -869,11 +870,10 @@ Return ONLY the comment text - no explanations.`,
869870
if (!effectiveIssueKey) {
870871
throw new Error('Issue Key is required to add attachments.')
871872
}
872-
const fileParam = params.attachmentFiles || params.files
873-
if (!fileParam || (Array.isArray(fileParam) && fileParam.length === 0)) {
873+
const normalizedFiles = normalizeFileInput(params.attachmentFiles || params.files)
874+
if (!normalizedFiles || normalizedFiles.length === 0) {
874875
throw new Error('At least one attachment file is required.')
875876
}
876-
const normalizedFiles = Array.isArray(fileParam) ? fileParam : [fileParam]
877877
return {
878878
...baseParams,
879879
issueKey: effectiveIssueKey,

apps/sim/blocks/blocks/microsoft_teams.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MicrosoftTeamsIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { normalizeFileInput } from '@/blocks/utils'
45
import type { MicrosoftTeamsResponse } from '@/tools/microsoft_teams/types'
56
import { getTrigger } from '@/triggers'
67

@@ -344,10 +345,9 @@ export const MicrosoftTeamsBlock: BlockConfig<MicrosoftTeamsResponse> = {
344345
}
345346

346347
// Add files if provided
347-
const fileParam = attachmentFiles || files
348-
if (fileParam && (operation === 'write_chat' || operation === 'write_channel')) {
349-
const normalizedFiles = Array.isArray(fileParam) ? fileParam : [fileParam]
350-
if (normalizedFiles.length > 0) {
348+
if (operation === 'write_chat' || operation === 'write_channel') {
349+
const normalizedFiles = normalizeFileInput(attachmentFiles || files)
350+
if (normalizedFiles) {
351351
baseParams.files = normalizedFiles
352352
}
353353
}

apps/sim/blocks/blocks/slack.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SlackIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { normalizeFileInput } from '@/blocks/utils'
45
import type { SlackResponse } from '@/tools/slack/types'
56
import { getTrigger } from '@/triggers'
67

@@ -620,12 +621,9 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
620621
if (threadTs) {
621622
baseParams.thread_ts = threadTs
622623
}
623-
const fileParam = attachmentFiles || files
624-
if (fileParam) {
625-
const normalizedFiles = Array.isArray(fileParam) ? fileParam : [fileParam]
626-
if (normalizedFiles.length > 0) {
627-
baseParams.files = normalizedFiles
628-
}
624+
const normalizedFiles = normalizeFileInput(attachmentFiles || files)
625+
if (normalizedFiles) {
626+
baseParams.files = normalizedFiles
629627
}
630628
break
631629
}

apps/sim/blocks/blocks/telegram.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TelegramIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { normalizeFileInput } from '@/blocks/utils'
45
import type { TelegramResponse } from '@/tools/telegram/types'
56
import { getTrigger } from '@/triggers'
67

@@ -312,16 +313,9 @@ export const TelegramBlock: BlockConfig<TelegramResponse> = {
312313
}
313314
}
314315
case 'telegram_send_document': {
315-
// Handle file upload
316-
const fileParam = params.attachmentFiles || params.files
317-
const normalizedFiles = fileParam
318-
? Array.isArray(fileParam)
319-
? fileParam
320-
: [fileParam]
321-
: undefined
322316
return {
323317
...commonParams,
324-
files: normalizedFiles,
318+
files: normalizeFileInput(params.attachmentFiles || params.files),
325319
caption: params.caption,
326320
}
327321
}

apps/sim/blocks/utils.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,37 @@ export function createVersionedToolSelector<TParams extends Record<string, any>>
249249
}
250250
}
251251
}
252+
253+
/**
254+
* Normalizes file input from block params.
255+
* Handles the case where template resolution JSON.stringify's arrays/objects
256+
* when they're placed in short-input fields (advanced mode).
257+
*
258+
* @param fileParam - The file parameter which could be:
259+
* - undefined/null (no files)
260+
* - An array of file objects (basic mode or properly resolved)
261+
* - A single file object
262+
* - A JSON string of file(s) (from advanced mode template resolution)
263+
* @returns Normalized array of file objects, or undefined if no files
264+
*/
265+
export function normalizeFileInput(fileParam: unknown): object[] | undefined {
266+
if (!fileParam) return undefined
267+
268+
if (typeof fileParam === 'string') {
269+
try {
270+
fileParam = JSON.parse(fileParam)
271+
} catch {
272+
return undefined
273+
}
274+
}
275+
276+
if (Array.isArray(fileParam)) {
277+
return fileParam.length > 0 ? fileParam : undefined
278+
}
279+
280+
if (typeof fileParam === 'object' && fileParam !== null) {
281+
return [fileParam]
282+
}
283+
284+
return undefined
285+
}

0 commit comments

Comments
 (0)