Add support for purchased paid media events

Enhanced the router to include `purchased_paid_media` handling. Added corresponding test cases to verify the new functionality and updated middleware to return the appropriate `EventContext`.
This commit is contained in:
JRoot Junior 2024-09-08 03:51:37 +03:00
parent c79da13d8e
commit 1cb36adf21
No known key found for this signature in database
GPG key ID: 738964250D5FF6E2
3 changed files with 18 additions and 0 deletions

View file

@ -175,4 +175,8 @@ class UserContextMiddleware(BaseMiddleware):
),
business_connection_id=event.edited_business_message.business_connection_id,
)
if event.purchased_paid_media:
return EventContext(
user=event.purchased_paid_media.from_user,
)
return EventContext()

View file

@ -102,6 +102,7 @@ class Router:
"business_connection": self.business_connection,
"edited_business_message": self.edited_business_message,
"business_message": self.business_message,
"purchased_paid_media": self.purchased_paid_media,
"error": self.errors,
}

View file

@ -42,6 +42,7 @@ from aiogram.types import (
ShippingQuery,
Update,
User,
PaidMediaPurchased,
)
from aiogram.types.error_event import ErrorEvent
from tests.mocked_bot import MockedBot
@ -586,6 +587,18 @@ class TestDispatcher:
True,
True,
),
pytest.param(
"purchased_paid_media",
Update(
update_id=42,
purchased_paid_media=PaidMediaPurchased(
paid_media_payload="payload",
from_user=User(id=42, is_bot=False, first_name="Test"),
),
),
False,
True,
),
],
)
async def test_listen_update(