Skip to content

Fix #170: support .svelte and other code files with unrecognized MIME types#173

Merged
grinev merged 1 commit into
grinev:mainfrom
hbx12:fix-170-svelte-file-support
Jul 2, 2026
Merged

Fix #170: support .svelte and other code files with unrecognized MIME types#173
grinev merged 1 commit into
grinev:mainfrom
hbx12:fix-170-svelte-file-support

Conversation

@hbx12

@hbx12 hbx12 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Changes

🐛 #170 — Cannot send .svelte files (and other code files with unrecognized MIME types)

  • Problem: Telegram sends .svelte files without a recognized MIME type (often application/octet-stream), so the bot rejects them as unsupported
  • Fix: Added filename extension fallback in isTextMimeType() — when the MIME type is unknown, the function now checks the file extension against a list of 40+ common code file extensions (.svelte, .vue, .tsx, .py, .go, .rs, etc.)

Files changed

  • file-download-service.ts — added TEXT_FILE_EXTENSIONS set + filename parameter in isTextMimeType()
  • document-handler.ts — pass filename to isTextMimeType()
  • media-group-handler.ts — pass filename to isTextMimeType()
  • Added test cases for: known extension fallback, unknown extension, missing filename, multi-dot files, no extension

✅ TypeScript — zero errors
✅ Tests added for new behavior

Support .svelte, .vue, .tsx, .py, .go, and 40+ other code file extensions
when Telegram sends an unrecognized or generic MIME type (e.g.
application/octet-stream).

This fixes grinev#170 — .svelte files (and similar code files) are now
correctly identified as text content instead of being rejected as
unsupported.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
hbx12 added a commit to hbx12/opencode-telegram-bot that referenced this pull request Jul 1, 2026
…am's 4096-byte limit

Rework truncation to use Buffer.byteLength() instead of character count.
Telegram's editMessageText limit is 4096 bytes (not characters), so
non-ASCII prompts (Arabic, Cyrillic, CJK) still crashed with the
previous character-based fix.

Binary search approach finds the correct character offset efficiently.

Also removes the svelte MIME type fallback changes from this PR —
they now live in a separate PR (grinev#173).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@grinev

grinev commented Jul 2, 2026

Copy link
Copy Markdown
Owner

@hbx12 thanks for contribution!

@grinev grinev merged commit fa0c6c0 into grinev:main Jul 2, 2026
1 check passed
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.

2 participants