How to use the aiogram.api.methods.base.TelegramMethod function in aiogram

To help you get started, we’ve selected a few aiogram examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiogram / aiogram / aiogram / api / methods / get_chat_administrators.py View on Github external
from typing import Any, Dict, List, Union

from ..types import ChatMember
from .base import Request, TelegramMethod


class GetChatAdministrators(TelegramMethod[List[ChatMember]]):
    """
    Use this method to get a list of administrators in a chat. On success, returns an Array of
    ChatMember objects that contains information about all chat administrators except other bots.
    If the chat is a group or a supergroup and no administrators were appointed, only the creator
    will be returned.

    Source: https://core.telegram.org/bots/api#getchatadministrators
    """

    __returning__ = List[ChatMember]

    chat_id: Union[int, str]
    """Unique identifier for the target chat or username of the target supergroup or channel (in
    the format @channelusername)"""

    def build_request(self) -> Request:
github aiogram / aiogram / aiogram / api / methods / set_webhook.py View on Github external
from typing import Any, Dict, List, Optional

from ..types import InputFile
from .base import Request, TelegramMethod, prepare_file


class SetWebhook(TelegramMethod[bool]):
    """
    Use this method to specify a url and receive incoming updates via an outgoing webhook.
    Whenever there is an update for the bot, we will send an HTTPS POST request to the specified
    url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up
    after a reasonable amount of attempts. Returns True on success.
    If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a
    secret path in the URL, e.g. https://www.example.com/. Since nobody else knows your
    bot‘s token, you can be pretty sure it’s us.
    Notes
    1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook
    is set up.
    2. To use a self-signed certificate, you need to upload your public key certificate using
    certificate parameter. Please upload as InputFile, sending a String will not work.
    3. Ports currently supported for Webhooks: 443, 80, 88, 8443.
    NEW! If you're having any trouble setting up webhooks, please check out this amazing guide to
    Webhooks.
github aiogram / aiogram / aiogram / api / methods / delete_chat_sticker_set.py View on Github external
from typing import Any, Dict, Union

from .base import Request, TelegramMethod


class DeleteChatStickerSet(TelegramMethod[bool]):
    """
    Use this method to delete a group sticker set from a supergroup. The bot must be an
    administrator in the chat for this to work and must have the appropriate admin rights. Use the
    field can_set_sticker_set optionally returned in getChat requests to check if the bot can use
    this method. Returns True on success.

    Source: https://core.telegram.org/bots/api#deletechatstickerset
    """

    __returning__ = bool

    chat_id: Union[int, str]
    """Unique identifier for the target chat or username of the target supergroup (in the format
    @supergroupusername)"""

    def build_request(self) -> Request:
github aiogram / aiogram / aiogram / api / methods / set_chat_title.py View on Github external
from typing import Any, Dict, Union

from .base import Request, TelegramMethod


class SetChatTitle(TelegramMethod[bool]):
    """
    Use this method to change the title of a chat. Titles can't be changed for private chats. The
    bot must be an administrator in the chat for this to work and must have the appropriate admin
    rights. Returns True on success.

    Source: https://core.telegram.org/bots/api#setchattitle
    """

    __returning__ = bool

    chat_id: Union[int, str]
    """Unique identifier for the target chat or username of the target channel (in the format
    @channelusername)"""
    title: str
    """New chat title, 1-255 characters"""
github aiogram / aiogram / aiogram / api / methods / get_me.py View on Github external
from typing import Any, Dict

from ..types import User
from .base import Request, TelegramMethod


class GetMe(TelegramMethod[User]):
    """
    A simple method for testing your bot's auth token. Requires no parameters. Returns basic
    information about the bot in form of a User object.

    Source: https://core.telegram.org/bots/api#getme
    """

    __returning__ = User

    def build_request(self) -> Request:
        data: Dict[str, Any] = self.dict()

        return Request(method="getMe", data=data)
github aiogram / aiogram / aiogram / api / methods / edit_message_caption.py View on Github external
from typing import Any, Dict, Optional, Union

from ..types import InlineKeyboardMarkup, Message
from .base import Request, TelegramMethod, prepare_parse_mode


class EditMessageCaption(TelegramMethod[Union[Message, bool]]):
    """
    Use this method to edit captions of messages. On success, if edited message is sent by the
    bot, the edited Message is returned, otherwise True is returned.

    Source: https://core.telegram.org/bots/api#editmessagecaption
    """

    __returning__ = Union[Message, bool]

    chat_id: Optional[Union[int, str]] = None
    """Required if inline_message_id is not specified. Unique identifier for the target chat or
    username of the target channel (in the format @channelusername)"""
    message_id: Optional[int] = None
    """Required if inline_message_id is not specified. Identifier of the message to edit"""
    inline_message_id: Optional[str] = None
    """Required if chat_id and message_id are not specified. Identifier of the inline message"""
github aiogram / aiogram / aiogram / api / methods / unban_chat_member.py View on Github external
from typing import Any, Dict, Union

from .base import Request, TelegramMethod


class UnbanChatMember(TelegramMethod[bool]):
    """
    Use this method to unban a previously kicked user in a supergroup or channel. The user will
    not return to the group or channel automatically, but will be able to join via link, etc. The
    bot must be an administrator for this to work. Returns True on success.

    Source: https://core.telegram.org/bots/api#unbanchatmember
    """

    __returning__ = bool

    chat_id: Union[int, str]
    """Unique identifier for the target group or username of the target supergroup or channel (in
    the format @username)"""
    user_id: int
    """Unique identifier of the target user"""
github aiogram / aiogram / aiogram / api / methods / set_game_score.py View on Github external
from typing import Any, Dict, Optional, Union

from ..types import Message
from .base import Request, TelegramMethod


class SetGameScore(TelegramMethod[Union[Message, bool]]):
    """
    Use this method to set the score of the specified user in a game. On success, if the message
    was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if
    the new score is not greater than the user's current score in the chat and force is False.

    Source: https://core.telegram.org/bots/api#setgamescore
    """

    __returning__ = Union[Message, bool]

    user_id: int
    """User identifier"""
    score: int
    """New score, must be non-negative"""
    force: Optional[bool] = None
    """Pass True, if the high score is allowed to decrease. This can be useful when fixing
github aiogram / aiogram / aiogram / api / methods / restrict_chat_member.py View on Github external
import datetime
from typing import Any, Dict, Optional, Union

from ..types import ChatPermissions
from .base import Request, TelegramMethod


class RestrictChatMember(TelegramMethod[bool]):
    """
    Use this method to restrict a user in a supergroup. The bot must be an administrator in the
    supergroup for this to work and must have the appropriate admin rights. Pass True for all
    permissions to lift restrictions from a user. Returns True on success.

    Source: https://core.telegram.org/bots/api#restrictchatmember
    """

    __returning__ = bool

    chat_id: Union[int, str]
    """Unique identifier for the target chat or username of the target supergroup (in the format
    @supergroupusername)"""
    user_id: int
    """Unique identifier of the target user"""
    permissions: ChatPermissions