Skip to content

fix: telegram media blocks reject valid URL strings and file_ids#3474

Open
MaxwellCalkin wants to merge 1 commit intosimstudioai:mainfrom
MaxwellCalkin:fix/telegram-url-photo
Open

fix: telegram media blocks reject valid URL strings and file_ids#3474
MaxwellCalkin wants to merge 1 commit intosimstudioai:mainfrom
MaxwellCalkin:fix/telegram-url-photo

Conversation

@MaxwellCalkin
Copy link

Summary

Fixes #3220

The `telegram_send_photo`, `telegram_send_video`, `telegram_send_audio`, and `telegram_send_animation` blocks always route media parameters through `normalizeFileInput()`, which attempts to `JSON.parse()` string inputs and returns `undefined` when parsing fails. This causes plain URL strings (e.g. `https://example.com/photo.jpg\`) and Telegram file_id strings to be silently dropped, producing "Photo is required." even when a valid, publicly accessible URL is provided.

The Telegram Bot API natively accepts both URL strings and file_id strings for media parameters — they don't need to be file objects.

Root cause

In `normalizeFileInput()` (blocks/utils.ts):
```ts
if (typeof fileParam === 'string') {
try {
fileParam = JSON.parse(fileParam) // fails for plain URLs
} catch {
return undefined // <-- drops the valid URL
}
}
```

Fix

Extract a `resolveTelegramMedia()` helper that:

  1. Passes plain strings (URLs, file_ids) through directly to the Telegram API
  2. Delegates to `normalizeFileInput()` only when the value looks like a serialized JSON file object or is a non-string value (from basic file-upload mode)

This is scoped to the Telegram block only — no changes to the shared `normalizeFileInput()` utility, so no risk to other integrations.

Test plan

  • Verify `telegram_send_photo` works with a plain HTTP URL in advanced mode
  • Verify `telegram_send_photo` works with a Telegram file_id string in advanced mode
  • Verify `telegram_send_photo` still works with file-upload in basic mode
  • Verify same behavior for send_video, send_audio, send_animation blocks

This PR was authored by Claude Opus 4.6 (AI), operated by @MaxwellCalkin

The telegram_send_photo, telegram_send_video, telegram_send_audio, and
telegram_send_animation blocks always routed media params through
normalizeFileInput(), which JSON.parse's string inputs and returns
undefined when parsing fails. This caused plain URL strings and
Telegram file_id strings (both valid per the Telegram Bot API) to be
silently dropped, resulting in "Photo is required." even when a valid
URL was provided.

Extract a resolveTelegramMedia() helper that passes plain strings
through directly and only delegates to normalizeFileInput when the
value is a serialized JSON object/array or a non-string value.

Fixes simstudioai#3220

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cursor
Copy link

cursor bot commented Mar 9, 2026

PR Summary

Low Risk
Change is isolated to Telegram block param normalization; main risk is minor behavior differences when distinguishing JSON-serialized file objects vs plain strings.

Overview
Fixes Telegram media send blocks rejecting valid URL or file_id inputs in advanced mode.

Adds resolveTelegramMedia() to pass through plain string media references while still using normalizeFileInput() for JSON-serialized file objects, and wires it into telegram_send_photo, telegram_send_video, telegram_send_audio, and telegram_send_animation param building so required-media validation no longer fails for URLs/IDs.

Written by Cursor Bugbot for commit 13510d7. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 9, 2026 1:20am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This PR fixes a bug where Telegram media blocks (send_photo, send_video, send_audio, send_animation) silently dropped valid plain URL strings and Telegram file_id strings because normalizeFileInput() calls JSON.parse() on strings and returns undefined on failure.

The fix introduces a scoped resolveTelegramMedia() helper that passes plain strings through directly and only delegates to normalizeFileInput() when the input looks like a serialized JSON object/array (starts with { or [). This is a clean, targeted change that avoids touching the shared normalizeFileInput() utility.

Key points:

  • The root cause analysis and fix logic are correct — normalizeFileInput was never designed to handle bare URL/file_id strings
  • resolveTelegramMedia is well-documented and correctly scoped
  • The JSON-detection heuristic (startsWith('{') || startsWith('[')) is reasonable for this domain (Telegram file_ids and HTTP URLs will never start with those characters)
  • Note: telegram_send_document still routes through the unmodified normalizeFileInput, creating the same class of bug for that operation. Telegram's sendDocument endpoint also accepts plain URL strings and file_ids.

Confidence Score: 4/5

  • Safe to merge; the fix is correct and well-scoped, with one unaddressed consistency issue in telegram_send_document.
  • The fix correctly identifies and resolves the root cause for four Telegram media operations. The resolveTelegramMedia() helper is well-designed, properly scoped, and doesn't touch shared utilities. The change is surgically targeted and low-risk. However, telegram_send_document exhibits the exact same bug but was not updated with the fix, creating an inconsistency that the author may want to address.
  • apps/sim/blocks/blocks/telegram.ts lines 336–343 (telegram_send_document case) — should also use resolveTelegramMedia() for consistency and correctness.

Comments Outside Diff (1)

  1. apps/sim/blocks/blocks/telegram.ts, line 336-343 (link)

    telegram_send_document not covered by the fix

    The telegram_send_document operation still routes params.files through normalizeFileInput, which will silently drop plain URL strings or file_id strings exactly the same way the fixed operations used to. The Telegram Bot API's sendDocument method accepts the same media input types (URL strings and file_ids) as sendPhoto, sendVideo, etc.

    If a user enters a URL or file_id in the document's advanced-mode field, it will be silently dropped and the document will be sent with files: undefined. This is the same class of bug the PR is fixing, just left unaddressed in this case.

    Consider applying the same resolveTelegramMedia() call here:

Last reviewed commit: 13510d7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] (Telegram) telegram_send_photo block rejects valid photo URL withPhoto is required. — error thrown internally before reaching Telegram API

1 participant