Inbound:
- tg-ingest detects document/photo/audio/video/voice attachments
- Downloads files via Telegram Bot API (getFile + download)
- Inlines small text files (<50KB) directly in the prompt
- Stores binary/large files to S3 (attachments/{chat_id}/{update_id}/{filename})
- agent-runner appends file context to the AgentCore prompt
Outbound:
- New send_file tool for the agent to send documents back to users
- TelegramAdapter.send_document uses multipart/form-data POST
- CDK grants tg-ingest S3 write access and passes bucket name env var
21 lines
860 B
Python
21 lines
860 B
Python
"""Send file tool — sends documents to the user via Telegram."""
|
|
from tools import messaging
|
|
|
|
|
|
def send_file(file_content: str, filename: str, caption: str = '') -> str:
|
|
"""Send a file to the user as a Telegram document attachment.
|
|
|
|
Args:
|
|
file_content: The text content of the file to send.
|
|
filename: The filename (e.g. 'report.txt', 'data.csv').
|
|
caption: Optional caption to display with the file.
|
|
"""
|
|
adapter = messaging._adapter
|
|
if adapter is None:
|
|
return 'No channel adapter configured.'
|
|
if not hasattr(adapter, 'send_document'):
|
|
return 'Channel adapter does not support file sending.'
|
|
file_bytes = file_content.encode('utf-8')
|
|
msg_id = adapter.send_document(file_bytes, filename, caption)
|
|
return f'File "{filename}" sent (id={msg_id})' if msg_id else f'File "{filename}" sent'
|