TelegramEx.Builder.Document (TelegramEx v1.2.1)

Copy Markdown View Source

Builder for document payloads.

This module provides a fluent API for sending documents (files) from URLs, file paths, or Telegram file IDs. Documents can include captions and parse modes.

Examples

# Send document from URL
ctx
|> Document.url("https://example.com/report.pdf")
|> Document.caption("Monthly Report")
|> Document.send(chat_id)

# Send document from local file
ctx
|> Document.path("/path/to/file.pdf")
|> Document.caption("Important document", "Markdown")
|> Document.send(chat_id)

# Send document silently
ctx
|> Document.path("/path/to/file.pdf")
|> Document.silent()
|> Document.send(chat_id)

Summary

Functions

Sets the document caption.

Sets the document caption with parse mode.

Sets the document from a local file path.

Sends the document to the specified chat.

Sends the document without notification sound.

Sets the document from a URL.

Functions

caption(ctx, caption)

@spec caption(map(), String.t()) :: map()

Sets the document caption.

Parameters

  • ctx - Context map
  • caption - Caption text

Returns

Updated context map with caption set.

caption(ctx, caption, parse_mode)

@spec caption(map(), String.t(), String.t()) :: map()

Sets the document caption with parse mode.

Parameters

  • ctx - Context map
  • caption - Caption text
  • parse_mode - Parse mode ("Markdown", "MarkdownV2", or "HTML")

Returns

Updated context map with caption and parse mode set.

path(ctx, path)

@spec path(map(), String.t()) :: map()

Sets the document from a local file path.

Parameters

  • ctx - Context map
  • path - Path to the document file

Returns

Updated context map with document file content set.

send(ctx, id)

@spec send(map(), integer()) :: :ok | {:error, term()}

Sends the document to the specified chat.

Parameters

  • ctx - Context map with accumulated document data
  • id - Chat ID to send the document to

Returns

  • :ok - Document sent successfully
  • {:error, reason} - Failed to send document

silent(ctx)

@spec silent(map()) :: map()

Sends the document without notification sound.

Parameters

  • ctx - Context map

Returns

Updated context map with silent flag set.

url(ctx, url)

@spec url(map(), String.t()) :: map()

Sets the document from a URL.

Parameters

  • ctx - Context map
  • url - URL of the document

Returns

Updated context map with document URL set.