TelegramEx.Builder.Photo (TelegramEx v1.2.1)

Copy Markdown View Source

Builder for photo payloads.

This module provides a fluent API for sending photos from URLs, file paths, or Telegram file IDs. Photos can include captions, parse modes, and other options.

Examples

# Send photo from URL
ctx
|> Photo.url("https://example.com/image.jpg")
|> Photo.caption("Look at this")
|> Photo.send(chat_id)

# Send photo from local file
ctx
|> Photo.path("/path/to/image.jpg")
|> Photo.caption("Local photo", "Markdown")
|> Photo.send(chat_id)

# Send photo silently
ctx
|> Photo.url("https://example.com/image.jpg")
|> Photo.silent()
|> Photo.send(chat_id)

Summary

Functions

Sets the photo caption.

Sets the photo caption with parse mode.

Sets the photo from a local file path.

Sends the photo to the specified chat.

Sends the photo without notification sound.

Sets the photo from a URL.

Functions

caption(ctx, caption)

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

Sets the photo caption.

Parameters

  • ctx - Context map
  • caption - Caption text

Returns

Updated context map with caption set.

Examples

ctx
|> Photo.url("https://example.com/photo.jpg")
|> Photo.caption("Beautiful sunset")
|> Photo.send(chat_id)

caption(ctx, caption, parse_mode)

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

Sets the photo 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.

Examples

ctx
|> Photo.url("https://example.com/photo.jpg")
|> Photo.caption("*Bold* caption", "Markdown")
|> Photo.send(chat_id)

path(ctx, path)

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

Sets the photo from a local file path.

Parameters

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

Returns

Updated context map with photo file content set.

Examples

ctx
|> Photo.path("/tmp/photo.jpg")
|> Photo.send(chat_id)

send(ctx, id)

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

Sends the photo to the specified chat.

Parameters

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

Returns

  • :ok - Photo sent successfully
  • {:error, reason} - Failed to send photo

Examples

ctx
|> Photo.url("https://example.com/photo.jpg")
|> Photo.send(chat_id)

silent(ctx)

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

Sends the photo without notification sound.

Parameters

  • ctx - Context map

Returns

Updated context map with silent flag set.

Examples

ctx
|> Photo.url("https://example.com/photo.jpg")
|> Photo.silent()
|> Photo.send(chat_id)

url(ctx, url)

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

Sets the photo from a URL.

Parameters

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

Returns

Updated context map with photo URL set.

Examples

ctx
|> Photo.url("https://example.com/photo.jpg")
|> Photo.send(chat_id)