Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from bundle
Use when building or fixing aiogram 3 bots that need aiogram_i18n with Fluent/FTL, topic-aware reply handling, Telegram quote and forward-origin context, and pr
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/forward_origin_context.py
1from dataclasses import dataclass23from aiogram.enums import MessageOriginType4from aiogram.types import Message567@dataclass(slots=True, frozen=True)8class ForwardOriginDTO:9origin_type: str10chat_id: int | None = None11user_id: int | None = None12display_name: str | None = None131415def extract_forward_origin(message: Message) -> ForwardOriginDTO | None:16origin = message.forward_origin17if origin is None:18return None1920if origin.type == MessageOriginType.USER:21return ForwardOriginDTO(22origin_type=origin.type,23user_id=origin.sender_user.id,24display_name=origin.sender_user.full_name,25)26if origin.type == MessageOriginType.HIDDEN_USER:27return ForwardOriginDTO(28origin_type=origin.type,29display_name=origin.sender_user_name,30)31if origin.type == MessageOriginType.CHAT:32return ForwardOriginDTO(33origin_type=origin.type,34chat_id=origin.sender_chat.id,35display_name=origin.sender_chat.title,36)37if origin.type == MessageOriginType.CHANNEL:38return ForwardOriginDTO(39origin_type=origin.type,40chat_id=origin.chat.id,41display_name=origin.chat.title,42)4344return ForwardOriginDTO(origin_type=origin.type)45