telega/update

Types

pub type Command {
  Command(
    text: String,
    command: String,
    payload: option.Option(String),
  )
}

Constructors

  • Command(
      text: String,
      command: String,
      payload: option.Option(String),
    )

    Represents a command message.

    Arguments

    text

    Whole command message

    command

    Command name without the leading slash

    payload

    The command arguments, if any.

Messages represent the data that the bot receives from the Telegram API.

pub type Update {
  TextUpdate(
    from_id: Int,
    chat_id: Int,
    text: String,
    message: types.Message,
    raw: types.Update,
  )
  CommandUpdate(
    from_id: Int,
    chat_id: Int,
    command: Command,
    message: types.Message,
    raw: types.Update,
  )
  PhotoUpdate(
    from_id: Int,
    chat_id: Int,
    photos: List(types.PhotoSize),
    message: types.Message,
    raw: types.Update,
  )
  VideoUpdate(
    from_id: Int,
    chat_id: Int,
    video: types.Video,
    message: types.Message,
    raw: types.Update,
  )
  AudioUpdate(
    from_id: Int,
    chat_id: Int,
    audio: types.Audio,
    message: types.Message,
    raw: types.Update,
  )
  VoiceUpdate(
    from_id: Int,
    chat_id: Int,
    voice: types.Voice,
    message: types.Message,
    raw: types.Update,
  )
  MediaGroupUpdate(
    from_id: Int,
    chat_id: Int,
    media_group_id: String,
    messages: List(types.Message),
    raw: types.Update,
  )
  WebAppUpdate(
    from_id: Int,
    chat_id: Int,
    web_app_data: types.WebAppData,
    message: types.Message,
    raw: types.Update,
  )
  MessageUpdate(
    from_id: Int,
    chat_id: Int,
    message: types.Message,
    raw: types.Update,
  )
  ChannelPostUpdate(
    from_id: Int,
    chat_id: Int,
    post: types.Message,
    raw: types.Update,
  )
  EditedMessageUpdate(
    from_id: Int,
    chat_id: Int,
    message: types.Message,
    raw: types.Update,
  )
  EditedChannelPostUpdate(
    from_id: Int,
    chat_id: Int,
    post: types.Message,
    raw: types.Update,
  )
  BusinessConnectionUpdate(
    from_id: Int,
    chat_id: Int,
    business_connection: types.BusinessConnection,
    raw: types.Update,
  )
  BusinessMessageUpdate(
    from_id: Int,
    chat_id: Int,
    message: types.Message,
    raw: types.Update,
  )
  EditedBusinessMessageUpdate(
    from_id: Int,
    chat_id: Int,
    message: types.Message,
    raw: types.Update,
  )
  DeletedBusinessMessageUpdate(
    from_id: Int,
    chat_id: Int,
    business_messages_deleted: types.BusinessMessagesDeleted,
    raw: types.Update,
  )
  MessageReactionUpdate(
    from_id: Int,
    chat_id: Int,
    message_reaction_updated: types.MessageReactionUpdated,
    raw: types.Update,
  )
  MessageReactionCountUpdate(
    from_id: Int,
    chat_id: Int,
    message_reaction_count_updated: types.MessageReactionCountUpdated,
    raw: types.Update,
  )
  InlineQueryUpdate(
    from_id: Int,
    chat_id: Int,
    inline_query: types.InlineQuery,
    raw: types.Update,
  )
  ChosenInlineResultUpdate(
    from_id: Int,
    chat_id: Int,
    chosen_inline_result: types.ChosenInlineResult,
    raw: types.Update,
  )
  CallbackQueryUpdate(
    from_id: Int,
    chat_id: Int,
    query: types.CallbackQuery,
    raw: types.Update,
  )
  ShippingQueryUpdate(
    from_id: Int,
    chat_id: Int,
    shipping_query: types.ShippingQuery,
    raw: types.Update,
  )
  PreCheckoutQueryUpdate(
    from_id: Int,
    chat_id: Int,
    pre_checkout_query: types.PreCheckoutQuery,
    raw: types.Update,
  )
  PaidMediaPurchaseUpdate(
    from_id: Int,
    chat_id: Int,
    paid_media_purchased: types.PaidMediaPurchased,
    raw: types.Update,
  )
  PollUpdate(
    from_id: Int,
    chat_id: Int,
    poll: types.Poll,
    raw: types.Update,
  )
  PollAnswerUpdate(
    from_id: Int,
    chat_id: Int,
    poll_answer: types.PollAnswer,
    raw: types.Update,
  )
  MyChatMemberUpdate(
    from_id: Int,
    chat_id: Int,
    chat_member_updated: types.ChatMemberUpdated,
    raw: types.Update,
  )
  ChatMemberUpdate(
    from_id: Int,
    chat_id: Int,
    chat_member_updated: types.ChatMemberUpdated,
    raw: types.Update,
  )
  ChatJoinRequestUpdate(
    from_id: Int,
    chat_id: Int,
    chat_join_request: types.ChatJoinRequest,
    raw: types.Update,
  )
  RemovedChatBoost(
    from_id: Int,
    chat_id: Int,
    removed_chat_boost: types.ChatBoostRemoved,
    raw: types.Update,
  )
  ChatBoostUpdate(
    from_id: Int,
    chat_id: Int,
    chat_boost: types.ChatBoostUpdated,
    raw: types.Update,
  )
  ManagedBotUpdate(
    from_id: Int,
    chat_id: Int,
    managed_bot: types.ManagedBotUpdated,
    raw: types.Update,
  )
  GuestMessageUpdate(
    from_id: Int,
    chat_id: Int,
    message: types.Message,
    raw: types.Update,
  )
  SubscriptionUpdate(
    from_id: Int,
    chat_id: Int,
    subscription: types.BotSubscriptionUpdated,
    raw: types.Update,
  )
  MessageGenerationStoppedUpdate(
    from_id: Int,
    chat_id: Int,
    stopped_message_generation: types.MessageGenerationStopped,
    raw: types.Update,
  )
  UnknownUpdate(from_id: Int, chat_id: Int, raw: types.Update)
}

Constructors

Values

pub fn background_update(
  chat_id chat_id: Int,
  user_id user_id: Int,
) -> Update

A stand-in update for work happening outside the update cycle.

It carries only the ids telega.background_context needs to address a chat; there is no Telegram event behind it. UnknownUpdate is deliberate — nothing routes it, and the dialog engine reads it as “not the user sending a message”, so a background re-render edits the live message rather than resending it below one.

pub fn chat(update: Update) -> option.Option(types.Chat)

The chat an update happened in, when it happened in one.

None for updates that carry no chat at all — inline queries, chosen inline results, polls, poll answers, shipping and pre-checkout queries, business connections, and updates this version cannot interpret. Those still have a chat_id (it is what the session key is built from), but it is a stand-in, not a chat: filtering on its sign is how an inline query ends up looking like a private chat.

pub fn decode_raw(
  json: dynamic.Dynamic,
) -> Result(types.Update, error.TelegaError)
pub fn message(update: Update) -> option.Option(types.Message)

The message an update carries, when it carries one.

None for updates that are not about a message at all — callback queries (the pressed message is query.message, which may be inaccessible), inline queries, polls, chat member changes, boosts. MediaGroupUpdate answers with the album’s first message, so content filters read the album’s own flags.

This is what the content filters in telega/router (is_reply, is_forwarded, has_entity, …) read.

pub fn raw(update: Update) -> types.Update

Get the original raw ModelUpdate behind any typed update. Useful when you need a field that the typed variant does not surface (e.g. the sender’s language_code).

pub fn raw_to_update(raw_update: types.Update) -> Update

Decode a update from the Telegram API to Update instance.

One on_field line per field of the spec’s Update type, message last because it dispatches further on the message’s own content. The chain is generated, so a new update kind cannot be forgotten here.

pub fn to_string(update: Update) -> String
pub fn type_to_string(update: Update) -> String

Returns a short snake_case tag for the update variant, e.g. "text", "command", "callback_query". Used as the update_type metadata in telemetry events.

Search Document