LemonChannels.Adapters.Telegram.Transport.FileOperations (lemon_channels v0.1.0)

View Source

File upload/download operations for the Telegram transport.

Handles /file put, /file get, auto-put for bare document uploads, and media-group file batching. Functions here perform I/O (Telegram API calls, filesystem writes) but do not directly mutate GenServer state.

Summary

Functions

Extract the file_id from whichever media type is present.

Extract the first present media attachment from the inbound message. Returns {media_type, media_map} or nil.

Process a media group of document uploads via auto-put behavior.

Handle the /file command dispatch (put / get / usage).

Process a media group where one item carries a /file put caption.

Handle a single bare media upload via auto-put.

Returns true when the inbound message has any downloadable media attachment.

Generate a filename for the media. Uses the Telegram-provided filename when available, otherwise generates {type}_{YYYYMMDD_HHMMSS}{ext}.

Returns true when the inbound has any media attachment that should be auto-saved according to the files configuration.

Functions

auto_put_destination(cfg, inbound)

download_media_bytes(state, inbound)

enforce_bytes_limit(bytes, cfg, key, default_max)

enforce_path_size(path, cfg, key, default_max)

ensure_files_enabled(cfg)

ensure_not_denied(root, rel, cfg)

ensure_project_root(root)

extract_file_id(inbound)

Extract the file_id from whichever media type is present.

extract_media(inbound)

Extract the first present media attachment from the inbound message. Returns {media_type, media_map} or nil.

file_usage()

files_cfg(state)

files_project_root(inbound, chat_id, thread_id)

files_sender_allowed?(state, inbound, chat_id)

format_upload_results(results)

handle_auto_put_media_group(state, items, chat_id, thread_id, user_msg_id)

Process a media group of document uploads via auto-put behavior.

Downloads each document and writes it to the configured uploads directory. Sends a summary system message.

handle_file_command(state, inbound)

Handle the /file command dispatch (put / get / usage).

Returns the updated state.

handle_file_get(state, inbound, cfg, chat_id, thread_id, user_msg_id, root, rest)

handle_file_put(state, inbound, cfg, chat_id, thread_id, user_msg_id, root, rest)

handle_file_put_media_group(state, file_put_inbound, items, chat_id, thread_id, user_msg_id)

Process a media group where one item carries a /file put caption.

handle_media_auto_put(state, inbound)

Handle a single bare media upload via auto-put.

Returns {:ok, final_rel} or {:error, reason}.

has_media?(inbound)

Returns true when the inbound message has any downloadable media attachment.

media_filename(media_type, media)

Generate a filename for the media. Uses the Telegram-provided filename when available, otherwise generates {type}_{YYYYMMDD_HHMMSS}{ext}.

parse_file_get_args(rest)

parse_file_put_args(cfg, inbound, rest)

prepare_file_get(abs)

resolve_dest_abs(root, rel)

send_document_reply(state, chat_id, thread_id, reply_to_id, path, filename)

should_auto_put_media?(state, inbound)

Returns true when the inbound has any media attachment that should be auto-saved according to the files configuration.

upload_media_group_items(state, items, root, dest_rel, cfg, force)

validate_multi_file_dest(items, dest_rel)

within_root?(root, abs)

write_document(rel, abs, bytes, opts)