""" This module contains the class used to communicate with Telegram's servers in plain text, when no authorization key has been created yet. """ import struct from .mtprotostate import MTProtoState from ..errors import BrokenAuthKeyError from ..extensions import BinaryReader class MTProtoPlainSender: """ MTProto Mobile Protocol plain sender (https://core.telegram.org/mtproto/description#unencrypted-messages) """ def __init__(self, connection): """ Initializes the MTProto plain sender. :param connection: the Connection to be used. """ self._state = MTProtoState(auth_key=None) self._connection = connection async def send(self, request): """ Sends and receives the result for the given request. """ body = bytes(request) msg_id = self._state._get_new_msg_id() await self._connection.send( struct.pack(' msg_id # msg_id assert reader.read_int() # length # No need to read "length" bytes first, just read the object return reader.tgread_object()