mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add additional API message methods to ChatJoinRequest class
ChatJoinRequest now includes additional message methods including SendAnimation, SendAudio, SendContact, and many more. The changes are useful for sending various types of messages during chat join requests.
This commit is contained in:
parent
a1513ddb2d
commit
d9fd665c53
21 changed files with 2524 additions and 8 deletions
|
|
@ -3,6 +3,145 @@ approve:
|
|||
fill: &request-target
|
||||
chat_id: self.chat.id
|
||||
user_id: self.from_user.id
|
||||
|
||||
decline:
|
||||
method: declineChatJoinRequest
|
||||
fill: *request-target
|
||||
|
||||
answer:
|
||||
method: sendMessage
|
||||
fill: &fill-answer-chat
|
||||
chat_id: self.chat.id
|
||||
|
||||
answer_pm:
|
||||
method: sendMessage
|
||||
fill: &fill-answer-user
|
||||
chat_id: self.user_chat_id
|
||||
|
||||
answer_animation:
|
||||
method: sendAnimation
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_animation_pm:
|
||||
method: sendAnimation
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_audio:
|
||||
method: sendAudio
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_audio_pm:
|
||||
method: sendAudio
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_contact:
|
||||
method: sendContact
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_contact_pm:
|
||||
method: sendContact
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_document:
|
||||
method: sendDocument
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_document_pm:
|
||||
method: sendDocument
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_game:
|
||||
method: sendGame
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_game_pm:
|
||||
method: sendGame
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_invoice:
|
||||
method: sendInvoice
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_invoice_pm:
|
||||
method: sendInvoice
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_location:
|
||||
method: sendLocation
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_location_pm:
|
||||
method: sendLocation
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_media_group:
|
||||
method: sendMediaGroup
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_media_group_pm:
|
||||
method: sendMediaGroup
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_photo:
|
||||
method: sendPhoto
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_photo_pm:
|
||||
method: sendPhoto
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_poll:
|
||||
method: sendPoll
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_poll_pm:
|
||||
method: sendPoll
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_dice:
|
||||
method: sendDice
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_dice_pm:
|
||||
method: sendDice
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_sticker:
|
||||
method: sendSticker
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_sticker_pm:
|
||||
method: sendSticker
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_venue:
|
||||
method: sendVenue
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_venue_pm:
|
||||
method: sendVenue
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_video:
|
||||
method: sendVideo
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_video_pm:
|
||||
method: sendVideo
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_video_note:
|
||||
method: sendVideoNote
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_video_note_pm:
|
||||
method: sendVideoNote
|
||||
fill: *fill-answer-user
|
||||
|
||||
answer_voice:
|
||||
method: sendVoice
|
||||
fill: *fill-answer-chat
|
||||
|
||||
answer_voice_pm:
|
||||
method: sendVoice
|
||||
fill: *fill-answer-user
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_animation`
|
||||
- :meth:`aiogram.types.message.Message.reply_animation`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_animation`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_animation`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_animation_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_audio`
|
||||
- :meth:`aiogram.types.message.Message.reply_audio`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_audio`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_audio`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_audio_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_contact`
|
||||
- :meth:`aiogram.types.message.Message.reply_contact`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_contact`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_contact`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_contact_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_dice`
|
||||
- :meth:`aiogram.types.message.Message.reply_dice`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_dice`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_dice`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_dice_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_document`
|
||||
- :meth:`aiogram.types.message.Message.reply_document`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_document`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_document`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_document_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_game`
|
||||
- :meth:`aiogram.types.message.Message.reply_game`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_game`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_game`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_game_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_invoice`
|
||||
- :meth:`aiogram.types.message.Message.reply_invoice`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_invoice`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_invoice`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_invoice_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_location`
|
||||
- :meth:`aiogram.types.message.Message.reply_location`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_location`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_location`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_location_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_media_group`
|
||||
- :meth:`aiogram.types.message.Message.reply_media_group`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_media_group`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_media_group`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_media_group_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer`
|
||||
- :meth:`aiogram.types.message.Message.reply`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_photo`
|
||||
- :meth:`aiogram.types.message.Message.reply_photo`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_photo`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_photo`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_photo_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_poll`
|
||||
- :meth:`aiogram.types.message.Message.reply_poll`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_poll`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_poll`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_poll_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_sticker`
|
||||
- :meth:`aiogram.types.message.Message.reply_sticker`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_sticker`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_sticker`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_sticker_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_venue`
|
||||
- :meth:`aiogram.types.message.Message.reply_venue`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_venue`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_venue`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_venue_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_video`
|
||||
- :meth:`aiogram.types.message.Message.reply_video`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_video`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_video`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_video_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_video_note`
|
||||
- :meth:`aiogram.types.message.Message.reply_video_note`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_video_note`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_video_note`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_video_note_pm`
|
||||
|
|
|
|||
|
|
@ -51,3 +51,5 @@ As shortcut from received object
|
|||
- :meth:`aiogram.types.message.Message.answer_voice`
|
||||
- :meth:`aiogram.types.message.Message.reply_voice`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_voice`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_voice`
|
||||
- :meth:`aiogram.types.chat_join_request.ChatJoinRequest.answer_voice_pm`
|
||||
|
|
|
|||
|
|
@ -1,7 +1,34 @@
|
|||
import datetime
|
||||
from typing import Any, Dict, Type, Union
|
||||
|
||||
from aiogram.methods import ApproveChatJoinRequest, DeclineChatJoinRequest
|
||||
from aiogram.types import Chat, ChatJoinRequest, User
|
||||
import pytest
|
||||
|
||||
from aiogram.methods import (
|
||||
ApproveChatJoinRequest,
|
||||
DeclineChatJoinRequest,
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
SendDice,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
SendLocation,
|
||||
SendMediaGroup,
|
||||
SendMessage,
|
||||
SendPhoto,
|
||||
SendPoll,
|
||||
SendSticker,
|
||||
SendVenue,
|
||||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
)
|
||||
from aiogram.types import (
|
||||
Chat,
|
||||
ChatJoinRequest,
|
||||
User,
|
||||
)
|
||||
|
||||
|
||||
class TestChatJoinRequest:
|
||||
|
|
@ -32,3 +59,96 @@ class TestChatJoinRequest:
|
|||
assert isinstance(api_method, DeclineChatJoinRequest)
|
||||
assert api_method.chat_id == chat_join_request.chat.id
|
||||
assert api_method.user_id == chat_join_request.from_user.id
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"alias_for_method,kwargs,method_class",
|
||||
[
|
||||
["answer_animation", dict(animation="animation"), SendAnimation],
|
||||
["answer_audio", dict(audio="audio"), SendAudio],
|
||||
["answer_contact", dict(phone_number="+000000000000", first_name="Test"), SendContact],
|
||||
["answer_document", dict(document="document"), SendDocument],
|
||||
["answer_game", dict(game_short_name="game"), SendGame],
|
||||
[
|
||||
"answer_invoice",
|
||||
dict(
|
||||
title="title",
|
||||
description="description",
|
||||
payload="payload",
|
||||
provider_token="provider_token",
|
||||
start_parameter="start_parameter",
|
||||
currency="currency",
|
||||
prices=[],
|
||||
),
|
||||
SendInvoice,
|
||||
],
|
||||
["answer_location", dict(latitude=0.42, longitude=0.42), SendLocation],
|
||||
["answer_media_group", dict(media=[]), SendMediaGroup],
|
||||
["answer", dict(text="test"), SendMessage],
|
||||
["answer_photo", dict(photo="photo"), SendPhoto],
|
||||
["answer_poll", dict(question="Q?", options=[]), SendPoll],
|
||||
["answer_dice", dict(), SendDice],
|
||||
["answer_sticker", dict(sticker="sticker"), SendSticker],
|
||||
["answer_sticker", dict(sticker="sticker"), SendSticker],
|
||||
[
|
||||
"answer_venue",
|
||||
dict(
|
||||
latitude=0.42,
|
||||
longitude=0.42,
|
||||
title="title",
|
||||
address="address",
|
||||
),
|
||||
SendVenue,
|
||||
],
|
||||
["answer_video", dict(video="video"), SendVideo],
|
||||
["answer_video_note", dict(video_note="video_note"), SendVideoNote],
|
||||
["answer_voice", dict(voice="voice"), SendVoice],
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("suffix", ["", "_pm"])
|
||||
def test_answer_aliases(
|
||||
self,
|
||||
alias_for_method: str,
|
||||
suffix: str,
|
||||
kwargs: Dict[str, Any],
|
||||
method_class: Type[
|
||||
Union[
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
SendLocation,
|
||||
SendMediaGroup,
|
||||
SendMessage,
|
||||
SendPhoto,
|
||||
SendPoll,
|
||||
SendSticker,
|
||||
SendSticker,
|
||||
SendVenue,
|
||||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
]
|
||||
],
|
||||
):
|
||||
event = ChatJoinRequest(
|
||||
chat=Chat(id=-42, type="channel"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
user_chat_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
)
|
||||
|
||||
alias = getattr(event, alias_for_method + suffix)
|
||||
assert callable(alias)
|
||||
|
||||
api_method = alias(**kwargs)
|
||||
assert isinstance(api_method, method_class)
|
||||
|
||||
if suffix == "_pm":
|
||||
assert api_method.chat_id == event.user_chat_id
|
||||
else:
|
||||
assert api_method.chat_id == event.chat.id
|
||||
|
||||
for key, value in kwargs.items():
|
||||
assert getattr(api_method, key) == value
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ from aiogram.types import (
|
|||
ChatMemberUpdated,
|
||||
User,
|
||||
)
|
||||
from aiogram.types.message import Message
|
||||
|
||||
|
||||
class TestChatMemberUpdated:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue