Sexy.Utils.Object (Sexy v0.9.13)

Copy Markdown View Source

The universal message container for Sexy.Bot.

Every message sent through Sexy.Bot.send/1 is represented as an Object struct. Build one from a plain map via Sexy.Bot.build/1:

Sexy.Bot.build(%{
  chat_id: 123,
  text: "Hello!",
  kb: %{inline_keyboard: [[%{text: "Go", callback_data: "/go"}]]}
})

Fields

FieldTypeDescription
chat_idintegerTelegram chat id (required)
textstringMessage text or caption (HTML supported)
mediastring/nilMedia file_id or "file" for documents. nil = text-only
kbmapReply markup (%{inline_keyboard: [[...]]})
entitylistTelegram message entities (bold, links, etc.)
update_datamapApp-specific data passed to Session.on_message_sent/4
filebinary/string/nilFile content (binary) or path for multipart uploads
filenamestring/nilFilename for multipart uploads
upload_typeatom/nil:photo, :video, :animation, :document — forces multipart upload

Media type detection

Detection looks at upload_type first, then falls back to media:

ConditionDetected typeAPI method
upload_type: :photophoto_uploadsendPhoto (multipart)
upload_type: :videovideo_uploadsendVideo (multipart)
upload_type: :animationanimation_uploadsendAnimation (multipart)
upload_type: :documentfilesendDocument (multipart)
media: niltxtsendMessage
media: "file" (legacy)filesendDocument (multipart)
media starts with "A"photosendPhoto (by file_id)
media starts with "B"videosendVideo (by file_id)
media starts with "C"animationsendAnimation (by file_id)

Telegram file_ids have a predictable prefix based on file type, which Sexy uses for automatic detection. For uploading a local file or binary, set upload_type.

Summary

Functions

Detect the content type of an Object.

Types

object_type()

@type object_type() :: String.t()

t()

@type t() :: %Sexy.Utils.Object{
  chat_id: integer() | nil,
  entity: list(),
  file: binary() | nil,
  filename: String.t() | nil,
  kb: map(),
  media: String.t() | nil,
  text: String.t(),
  update_data: map(),
  upload_type: upload_type()
}

upload_type()

@type upload_type() :: :photo | :video | :animation | :document | nil

Functions

detect_object_type(obj)

@spec detect_object_type(t()) :: object_type()

Detect the content type of an Object.

upload_type (if set) wins over media. Returns one of: "txt", "file", "photo", "video", "animation", "photo_upload", "video_upload", "animation_upload", "unknown".