#1520 Fixed event context resolving for the callback query (#1521)

* #1520 Fixed event context resolving for the callback query that is coming from the business account

* Simplify some conditions

* Added changelog

* Fixed AttributeError
This commit is contained in:
Alex Root Junior 2024-07-06 20:46:45 +03:00 committed by GitHub
parent 46e033e6da
commit 7f47609585
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 24 additions and 17 deletions

1
CHANGES/1520.bugfix.rst Normal file
View file

@ -0,0 +1 @@
Fixed event context resolving for the callback query that is coming from the business account

View file

@ -80,14 +80,20 @@ class UserContextMiddleware(BaseMiddleware):
if event.chosen_inline_result:
return EventContext(user=event.chosen_inline_result.from_user)
if event.callback_query:
if event.callback_query.message:
callback_query_message = event.callback_query.message
if callback_query_message:
return EventContext(
chat=event.callback_query.message.chat,
chat=callback_query_message.chat,
user=event.callback_query.from_user,
thread_id=(
event.callback_query.message.message_thread_id
if not isinstance(event.callback_query.message, InaccessibleMessage)
and event.callback_query.message.is_topic_message
callback_query_message.message_thread_id
if not isinstance(callback_query_message, InaccessibleMessage)
and callback_query_message.is_topic_message
else None
),
business_connection_id=(
callback_query_message.business_connection_id
if not isinstance(callback_query_message, InaccessibleMessage)
else None
),
)

View file

@ -3,8 +3,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any, Literal, Union
from ..enums import InputPaidMediaType
from .input_paid_media import InputPaidMedia
from .input_file import InputFile
from .input_paid_media import InputPaidMedia
class InputPaidMediaPhoto(InputPaidMedia):

View file

@ -10,10 +10,10 @@ from aiogram.utils.text_decorations import (
html_decoration,
markdown_decoration,
)
from . import InputPaidMediaPhoto, InputPaidMediaVideo
from ..client.default import Default
from ..enums import ContentType
from . import InputPaidMediaPhoto, InputPaidMediaVideo
from .custom import DateTime
from .maybe_inaccessible_message import MaybeInaccessibleMessage
@ -38,6 +38,7 @@ if TYPE_CHECKING:
SendLocation,
SendMediaGroup,
SendMessage,
SendPaidMedia,
SendPhoto,
SendPoll,
SendSticker,
@ -48,7 +49,6 @@ if TYPE_CHECKING:
SetMessageReaction,
StopMessageLiveLocation,
UnpinChatMessage,
SendPaidMedia,
)
from .animation import Animation
from .audio import Audio

View file

@ -2,8 +2,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any, List, Literal
from .paid_media import PaidMedia
from ..enums import PaidMediaType
from .paid_media import PaidMedia
if TYPE_CHECKING:
from .photo_size import PhotoSize

View file

@ -2,8 +2,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any, Literal, Optional
from .paid_media import PaidMedia
from ..enums import PaidMediaType
from .paid_media import PaidMedia
class PaidMediaPreview(PaidMedia):

View file

@ -2,8 +2,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any, Literal
from .paid_media import PaidMedia
from ..enums import PaidMediaType
from .paid_media import PaidMedia
if TYPE_CHECKING:
from .video import Video

View file

@ -4,6 +4,7 @@ from os import getenv
from typing import Any, Dict, Union
from aiohttp import web
from finite_state_machine import form_router
from aiogram import Bot, Dispatcher, F, Router
from aiogram.client.session.aiohttp import AiohttpSession
@ -18,7 +19,6 @@ from aiogram.webhook.aiohttp_server import (
TokenBasedRequestHandler,
setup_application,
)
from finite_state_machine import form_router
main_router = Router()

View file

@ -2,12 +2,12 @@ import datetime
from aiogram.methods import SendPaidMedia
from aiogram.types import (
Message,
Chat,
PaidMediaPhoto,
PaidMediaInfo,
PhotoSize,
InputPaidMediaPhoto,
Message,
PaidMediaInfo,
PaidMediaPhoto,
PhotoSize,
)
from tests.mocked_bot import MockedBot

View file

@ -24,6 +24,7 @@ from aiogram.methods import (
SendLocation,
SendMediaGroup,
SendMessage,
SendPaidMedia,
SendPhoto,
SendPoll,
SendSticker,
@ -35,7 +36,6 @@ from aiogram.methods import (
StopMessageLiveLocation,
TelegramMethod,
UnpinChatMessage,
SendPaidMedia,
)
from aiogram.types import (
UNSET_PARSE_MODE,