fix: handle MEDIA tags in send_message tool for native file delivery

The send_message tool's _send_telegram() sent MEDIA:<path> tags as
literal text instead of delivering actual files. This fixes it by
extracting MEDIA tags via BasePlatformAdapter.extract_media() and
routing files to the appropriate Telegram Bot API method by extension.

Changes:
- send_message_tool: extract MEDIA tags and send files natively as
  photo/video/voice/audio/document based on file extension
- send_message_tool: add per-file error handling and missing-file logging
- send_message_tool: use cleaned text in fallback to avoid leaking tags
- base.py extract_media: handle optional space after MEDIA: colon
- base.py extract_media: strip surrounding backticks/quotes from paths

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
quabug 2026-03-11 11:39:07 -07:00 committed by teknium1
parent 9525db913f
commit 50d6659392
2 changed files with 63 additions and 9 deletions

View file

@ -618,16 +618,16 @@ class BasePlatformAdapter(ABC):
has_voice_tag = "[[audio_as_voice]]" in content
cleaned = cleaned.replace("[[audio_as_voice]]", "")
# Extract MEDIA:<path> tags (path may contain spaces)
media_pattern = r'MEDIA:(\S+)'
# Extract MEDIA:<path> tags
media_pattern = r'MEDIA:\s*(\S+)'
for match in re.finditer(media_pattern, content):
path = match.group(1).strip()
path = match.group(1).strip().rstrip('`"\',)}')
if path:
media.append((path, has_voice_tag))
# Remove MEDIA tags from content
# Remove MEDIA tags from content (including surrounding backticks/quotes)
if media:
cleaned = re.sub(media_pattern, '', cleaned)
cleaned = re.sub(r'[`"\']*MEDIA:\s*\S+[`"\']*', '', cleaned)
cleaned = re.sub(r'\n{3,}', '\n\n', cleaned).strip()
return media, cleaned