Nadia.InputFile (nadia v1.6.1)

View Source

Explicitly identifies a Telegram file ID, URL, local path, in-memory upload, or known-size stream.

Bare binary arguments accepted by existing Nadia wrappers remain supported. Use this module when path intent, an upload filename, or nested attach:// composition must be unambiguous.

Nadia.send_document(chat_id, Nadia.InputFile.file_id(file_id))
Nadia.send_document(chat_id, Nadia.InputFile.url("https://example.com/file.pdf"))
Nadia.send_document(chat_id, Nadia.InputFile.path("/srv/files/report.pdf"))

Nadia.send_document(
  chat_id,
  Nadia.InputFile.bytes(pdf_iodata, "report.pdf", max_bytes: 5_000_000)
)

stream/3 requires an exact byte size. The stream is consumed once and is never buffered or retried by Nadia. See the Media And Files guide for lifecycle and ambiguous-failure caveats.

Summary

Functions

Returns an in-memory iodata upload without flattening or copying its data.

Returns an explicit Telegram file ID reference.

Returns an explicit local-path upload. The path is checked before the request.

Returns a single-use streaming upload.

Returns an explicit HTTP or HTTPS URL reference.

Types

option()

@type option() ::
  {:filename, binary()}
  | {:content_type, binary()}
  | {:max_bytes, non_neg_integer()}
  | {:attach_name, binary()}

source()

@type source() ::
  {:file_id, term()}
  | {:url, term()}
  | {:path, term()}
  | {:bytes, term()}
  | {:stream, term()}

stream_option()

@type stream_option() :: option() | {:size, non_neg_integer()}

t()

@type t() :: %Nadia.InputFile{
  attach_name: binary() | nil,
  content_type: binary() | nil,
  filename: binary() | nil,
  max_bytes: non_neg_integer() | nil,
  size: non_neg_integer() | nil,
  source: source()
}

Functions

bytes(bytes, filename, options \\ [])

@spec bytes(iodata(), binary(), [option()]) :: t()

Returns an in-memory iodata upload without flattening or copying its data.

Set :max_bytes to enforce an application limit before the request starts.

file_id(file_id)

@spec file_id(binary()) :: t()

Returns an explicit Telegram file ID reference.

path(path, options \\ [])

@spec path(Path.t(), [option()]) :: t()

Returns an explicit local-path upload. The path is checked before the request.

stream(stream, filename, options)

@spec stream(Enumerable.t(), binary(), [stream_option()]) :: t()

Returns a single-use streaming upload.

:size is required and must be the exact number of bytes yielded as iodata. Nadia does not retry, rewind, or take ownership of caller-managed resources.

url(url)

@spec url(binary()) :: t()

Returns an explicit HTTP or HTTPS URL reference.