Ejemplo n.º 1
0
    def from_array(array):
        """
        Deserialize a new ChosenInlineResult from a given dictionary.

        :return: new ChosenInlineResult instance.
        :rtype: ChosenInlineResult
        """
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.peer import User

        data = {}
        data['result_id'] = u(array.get('result_id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['query'] = u(array.get('query'))
        data['location'] = Location.from_array(array.get(
            'location')) if array.get('location') is not None else None
        data['inline_message_id'] = u(
            array.get('inline_message_id')) if array.get(
                'inline_message_id') is not None else None
        data['_raw'] = array
        return ChosenInlineResult(**data)
Ejemplo n.º 2
0
    def from_array(array):
        """
        Deserialize a new PreCheckoutQuery from a given dictionary.

        :return: new PreCheckoutQuery instance.
        :rtype: PreCheckoutQuery
        """
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.peer import User

        data = {}
        data['id'] = u(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['currency'] = u(array.get('currency'))
        data['total_amount'] = int(array.get('total_amount'))
        data['invoice_payload'] = u(array.get('invoice_payload'))
        data['shipping_option_id'] = u(
            array.get('shipping_option_id')) if array.get(
                'shipping_option_id') is not None else None
        data['order_info'] = OrderInfo.from_array(array.get(
            'order_info')) if array.get('order_info') is not None else None
        data['_raw'] = array
        return PreCheckoutQuery(**data)
Ejemplo n.º 3
0
    def from_array(array):
        """
        Deserializes a new ChosenInlineResult from a given dictionary.

        :return: new ChosenInlineResult instance.
        :rtype: ChosenInlineResult
        """
        if array is None or not array:
            return None
        # end if
        assert (isinstance(array, dict))

        from ..receivable.peer import User
        from ..receivable.media import Location

        data = {}
        data['result_id'] = str(array.get('result_id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['query'] = str(array.get('query'))
        data['location'] = Location.from_array(array.get(
            'location')) if array.get('location') is not None else None
        data['inline_message_id'] = str(
            array.get('inline_message_id')) if array.get(
                'inline_message_id') is not None else None
        return ChosenInlineResult(**data)
Ejemplo n.º 4
0
    def from_array(array):
        """
        Deserializes a new CallbackQuery from a given dictionary.

        :return: new CallbackQuery instance.
        :rtype: CallbackQuery
        """
        if array is None or not array:
            return None
        # end if
        assert (isinstance(array, dict))

        from pytgbot.api_types.receivable.peer import User
        from pytgbot.api_types.receivable.updates import Message

        data = {}
        data['id'] = str(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['chat_instance'] = str(array.get('chat_instance'))
        data['message'] = Message.from_array(
            array.get('message')) if array.get('message') is not None else None
        data['inline_message_id'] = str(
            array.get('inline_message_id')) if array.get(
                'inline_message_id') is not None else None
        data['data'] = str(
            array.get('data')) if array.get('data') is not None else None
        data['game_short_name'] = str(
            array.get('game_short_name')) if array.get(
                'game_short_name') is not None else None
        return CallbackQuery(**data)
Ejemplo n.º 5
0
 def get_me(self):
     assert self.return_python_objects
     from pytgbot.api_types.receivable.peer import User
     return User(id=0,
                 is_bot=True,
                 first_name="UNITTEST",
                 username="******")
Ejemplo n.º 6
0
    def from_array(array):
        """
        Deserialize a new ChatMember from a given dictionary.

        :return: new ChatMember instance.
        :rtype: ChatMember
        """
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.peer import User

        data = {}
        data['user'] = User.from_array(array.get('user'))
        data['status'] = u(array.get('status'))
        data['until_date'] = int(array.get('until_date')) if array.get(
            'until_date') is not None else None
        data['can_be_edited'] = bool(array.get('can_be_edited')) if array.get(
            'can_be_edited') is not None else None
        data['can_change_info'] = bool(
            array.get('can_change_info')) if array.get(
                'can_change_info') is not None else None
        data['can_post_messages'] = bool(
            array.get('can_post_messages')) if array.get(
                'can_post_messages') is not None else None
        data['can_edit_messages'] = bool(
            array.get('can_edit_messages')) if array.get(
                'can_edit_messages') is not None else None
        data['can_delete_messages'] = bool(
            array.get('can_delete_messages')) if array.get(
                'can_delete_messages') is not None else None
        data['can_invite_users'] = bool(
            array.get('can_invite_users')) if array.get(
                'can_invite_users') is not None else None
        data['can_restrict_members'] = bool(
            array.get('can_restrict_members')) if array.get(
                'can_restrict_members') is not None else None
        data['can_pin_messages'] = bool(
            array.get('can_pin_messages')) if array.get(
                'can_pin_messages') is not None else None
        data['can_promote_members'] = bool(
            array.get('can_promote_members')) if array.get(
                'can_promote_members') is not None else None
        data['can_send_messages'] = bool(
            array.get('can_send_messages')) if array.get(
                'can_send_messages') is not None else None
        data['can_send_media_messages'] = bool(
            array.get('can_send_media_messages')) if array.get(
                'can_send_media_messages') is not None else None
        data['can_send_other_messages'] = bool(
            array.get('can_send_other_messages')) if array.get(
                'can_send_other_messages') is not None else None
        data['can_add_web_page_previews'] = bool(
            array.get('can_add_web_page_previews')) if array.get(
                'can_add_web_page_previews') is not None else None
        data['_raw'] = array
        return ChatMember(**data)
Ejemplo n.º 7
0
    def validate_array(array):
        """
        Builds a new array with valid values for the GameHighScore constructor.

        :return: new array with valid values
        :rtype: dict
        """
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.peer import User
        
        data = Result.validate_array(array)
        data['position'] = int(array.get('position'))
        data['user'] = User.from_array(array.get('user'))
        data['score'] = int(array.get('score'))
Ejemplo n.º 8
0
    def test_commands(self):
        self.m.BEST_PONY = self.s
        self.assertEqual(self.m.CURRENT, self.m.DEFAULT)
        self.assertEqual(self.m.CURRENT.name, 'DEFAULT')

        update = Update(1,
                        message=Message(2,
                                        date=int(time.time()),
                                        from_peer=User(3, False, "Günter"),
                                        chat=Chat(4, 'supergroup',
                                                  'FAKE CHAT'),
                                        text='/start'))
        called = [False, False]

        def call_me(i):
            def call_me_inner(u, text):
                logger.info('called {i}.'.format(i=i))
                self.assertEqual(u, update)
                called[i] = True

            # end def
            return call_me_inner

        # end def

        self.m.DEFAULT.command('start')(call_me(0))
        self.m.BEST_PONY.command('start')(call_me(1))

        self.m.BEST_PONY.activate()
        self.assertEqual(self.m.CURRENT, self.s)
        self.assertEqual(self.m.CURRENT, self.m.BEST_PONY)
        self.assertEqual(self.m.CURRENT.name, 'BEST_PONY')

        self.m.process_update(update)
        self.assertEqual(
            self.m.CURRENT, self.m.DEFAULT,
            "load_state_for_chat_user should set DEFAULT (None) state again.")
        self.assertEqual(
            self.m.CURRENT.name, 'DEFAULT',
            "load_state_for_chat_user should set DEFAULT (None) state again.")
        self.assertTrue(
            called[0],
            'DEFAULT should have been called: load_state_for_chat_user set DEFAULT (None) state again.'
        )
        self.assertFalse(
            called[1],
            'BEST_PONY should not have been called: load_state_for_chat_user set DEFAULT (None) state again.'
        )
Ejemplo n.º 9
0
    def validate_array(array):
        """
        Builds a new array with valid values for the ShippingQuery constructor.

        :return: new array with valid values
        :rtype: dict
        """
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.payments import ShippingAddress
        from pytgbot.api_types.receivable.peer import User
        
        data = UpdateType.validate_array(array)
        data['id'] = u(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['invoice_payload'] = u(array.get('invoice_payload'))
        data['shipping_address'] = ShippingAddress.from_array(array.get('shipping_address'))
Ejemplo n.º 10
0
    def validate_array(array):
        """
        Builds a new array with valid values for the InlineQuery constructor.

        :return: new array with valid values
        :rtype: dict
        """
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.peer import User

        data = Result.validate_array(array)
        data['id'] = u(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['query'] = u(array.get('query'))
        data['offset'] = u(array.get('offset'))
        data['location'] = Location.from_array(array.get(
            'location')) if array.get('location') is not None else None
Ejemplo n.º 11
0
    def from_array(array):
        """
        Deserializes a new User from a given dictionary.

        :return: new User instance.
        :rtype: User
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))
        
        data = {}
        data['id'] = int(array.get('id'))
        data['first_name'] = str(array.get('first_name'))
        data['last_name'] = str(array.get('last_name')) if array.get('last_name') is not None else None
        data['username'] = str(array.get('username')) if array.get('username') is not None else None
        return User(**data)
Ejemplo n.º 12
0
    def from_array(array):
        """
        Deserializes a new ChatMember from a given dictionary.

        :return: new ChatMember instance.
        :rtype: ChatMember
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))
        
        from pytgbot.api_types.receivable.peer import User
        
        data = {}
        data['user'] = User.from_array(array.get('user'))
        data['status'] = str(array.get('status'))
        return ChatMember(**data)
Ejemplo n.º 13
0
    def validate_array(array):
        """
        Builds a new array with valid values for the PreCheckoutQuery constructor.

        :return: new array with valid values
        :rtype: dict
        """
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.payments import OrderInfo
        from pytgbot.api_types.receivable.peer import User
        
        data = UpdateType.validate_array(array)
        data['id'] = u(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['currency'] = u(array.get('currency'))
        data['total_amount'] = int(array.get('total_amount'))
        data['invoice_payload'] = u(array.get('invoice_payload'))
        data['shipping_option_id'] = u(array.get('shipping_option_id')) if array.get('shipping_option_id') is not None else None
        data['order_info'] = OrderInfo.from_array(array.get('order_info')) if array.get('order_info') is not None else None
Ejemplo n.º 14
0
    def from_array(array):
        """
        Deserializes a new GameHighScore from a given dictionary.

        :return: new GameHighScore instance.
        :rtype: GameHighScore
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))
        
        from pytgbot.api_types.receivable.peer import User
        
        data = {}
        data['position'] = int(array.get('position'))
        data['user'] = User.from_array(array.get('user'))
        data['score'] = int(array.get('score'))
        return GameHighScore(**data)
Ejemplo n.º 15
0
    def validate_array(array):
        """
        Builds a new array with valid values for the ChosenInlineResult constructor.

        :return: new array with valid values
        :rtype: dict
        """
        assert_type_or_raise(array, dict, parameter_name="array")
        from ..receivable.media import Location
        from ..receivable.peer import User

        data = UpdateType.validate_array(array)
        data['result_id'] = u(array.get('result_id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['query'] = u(array.get('query'))
        data['location'] = Location.from_array(array.get(
            'location')) if array.get('location') is not None else None
        data['inline_message_id'] = u(
            array.get('inline_message_id')) if array.get(
                'inline_message_id') is not None else None
        return data
Ejemplo n.º 16
0
    def from_array(array):
        """
        Deserializes a new MessageEntity from a given dictionary.

        :return: new MessageEntity instance.
        :rtype: MessageEntity
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))

        from pytgbot.api_types.receivable.peer import User

        data = {}
        data['type'] = str(array.get('type'))
        data['offset'] = int(array.get('offset'))
        data['length'] = int(array.get('length'))
        data['url'] = str(array.get('url')) if array.get('url') is not None else None
        data['user'] = User.from_array(array.get('user')) if array.get('user') is not None else None
        return MessageEntity(**data)
Ejemplo n.º 17
0
    def from_array(array):
        """
        Deserialize a new ShippingQuery from a given dictionary.

        :return: new ShippingQuery instance.
        :rtype: ShippingQuery
        """
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.peer import User

        data = {}
        data['id'] = u(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['invoice_payload'] = u(array.get('invoice_payload'))
        data['shipping_address'] = ShippingAddress.from_array(
            array.get('shipping_address'))
        data['_raw'] = array
        return ShippingQuery(**data)
Ejemplo n.º 18
0
    def from_array(array):
        """
        Deserializes a new InlineQuery from a given dictionary.

        :return: new InlineQuery instance.
        :rtype: InlineQuery
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))
        
        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.peer import User
        
        data = {}
        data['id'] = str(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['query'] = str(array.get('query'))
        data['offset'] = str(array.get('offset'))
        data['location'] = Location.from_array(array.get('location')) if array.get('location') is not None else None
        return InlineQuery(**data)
Ejemplo n.º 19
0
    def from_array(array):
        """
        Deserializes a new ChosenInlineResult from a given dictionary.

        :return: new ChosenInlineResult instance.
        :rtype: ChosenInlineResult
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))
        
        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.peer import User
        
        data = {}
        data['result_id'] = str(array.get('result_id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['query'] = str(array.get('query'))
        data['location'] = Location.from_array(array.get('location')) if array.get('location') is not None else None
        data['inline_message_id'] = str(array.get('inline_message_id')) if array.get('inline_message_id') is not None else None
        return ChosenInlineResult(**data)
Ejemplo n.º 20
0
    def from_array(array):
        """
        Deserializes a new InlineQuery from a given dictionary.

        :return: new InlineQuery instance.
        :rtype: InlineQuery
        """
        if array is None or not array:
            return None
        # end if
        assert isinstance(array, dict)

        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.peer import User

        data = {}

        data["id"] = str(array.get("id"))
        data["from_peer"] = User.from_array(array.get("from"))
        data["query"] = str(array.get("query"))
        data["offset"] = str(array.get("offset"))
        data["location"] = Location.from_array(array.get("location")) if array.get("location") is not None else None
        return InlineQuery(**data)
Ejemplo n.º 21
0
    def from_array(array):
        """
        Deserialize a new User from a given dictionary.

        :return: new User instance.
        :rtype: User
        """
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")

        data = {}
        data['id'] = int(array.get('id'))
        data['first_name'] = u(array.get('first_name'))
        data['last_name'] = u(array.get('last_name')) if array.get(
            'last_name') is not None else None
        data['username'] = u(array.get('username')) if array.get(
            'username') is not None else None
        data['language_code'] = u(array.get('language_code')) if array.get(
            'language_code') is not None else None
        data['_raw'] = array
        return User(**data)
Ejemplo n.º 22
0
    def from_array(array):
        """
        Deserializes a new ChosenInlineResult from a given dictionary.

        :return: new ChosenInlineResult instance.
        :rtype: ChosenInlineResult
        """
        if array is None or not array:
            return None
        # end if
        assert isinstance(array, dict)

        from ..receivable.peer import User
        from ..receivable.media import Location

        data = {}
        data["result_id"] = str(array.get("result_id"))
        data["from_peer"] = User.from_array(array.get("from"))
        data["query"] = str(array.get("query"))
        data["location"] = Location.from_array(array.get("location")) if array.get("location") is not None else None
        data["inline_message_id"] = (
            str(array.get("inline_message_id")) if array.get("inline_message_id") is not None else None
        )
        return ChosenInlineResult(**data)
Ejemplo n.º 23
0
    def from_array(array):
        """
        Deserializes a new InlineQuery from a given dictionary.

        :return: new InlineQuery instance.
        :rtype: InlineQuery
        """
        if array is None or not array:
            return None
        # end if
        assert (isinstance(array, dict))

        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.peer import User

        data = {}

        data['id'] = str(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['query'] = str(array.get('query'))
        data['offset'] = str(array.get('offset'))
        data['location'] = Location.from_array(array.get(
            'location')) if array.get('location') is not None else None
        return InlineQuery(**data)
Ejemplo n.º 24
0
    def from_array(array):
        """
        Deserializes a new CallbackQuery from a given dictionary.

        :return: new CallbackQuery instance.
        :rtype: CallbackQuery
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))
        
        from pytgbot.api_types.receivable.peer import User
        from pytgbot.api_types.receivable.updates import Message
        
        data = {}
        data['id'] = str(array.get('id'))
        data['from_peer'] = User.from_array(array.get('from'))
        data['chat_instance'] = str(array.get('chat_instance'))
        data['message'] = Message.from_array(array.get('message')) if array.get('message') is not None else None
        data['inline_message_id'] = str(array.get('inline_message_id')) if array.get('inline_message_id') is not None else None
        data['data'] = str(array.get('data')) if array.get('data') is not None else None
        data['game_short_name'] = str(array.get('game_short_name')) if array.get('game_short_name') is not None else None
        return CallbackQuery(**data)
Ejemplo n.º 25
0
    def from_array(array):
        """
        Deserializes a new Message from a given dictionary.

        :return: new Message instance.
        :rtype: Message
        """
        if array is None or not array:
            return None
        # end if
        assert(isinstance(array, dict))
        
        from pytgbot.api_types.receivable.media import Audio
        from pytgbot.api_types.receivable.media import Contact
        from pytgbot.api_types.receivable.media import Document
        from pytgbot.api_types.receivable.media import Game
        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.media import MessageEntity
        from pytgbot.api_types.receivable.media import PhotoSize
        from pytgbot.api_types.receivable.media import Sticker
        from pytgbot.api_types.receivable.media import Venue
        from pytgbot.api_types.receivable.media import Video
        from pytgbot.api_types.receivable.media import Voice
        from pytgbot.api_types.receivable.peer import Chat
        from pytgbot.api_types.receivable.peer import User
        from pytgbot.api_types.receivable.updates import Message
        
        data = {}
        data['message_id'] = int(array.get('message_id'))
        data['date'] = int(array.get('date'))
        data['chat'] = Chat.from_array(array.get('chat'))
        data['from_peer'] = User.from_array(array.get('from')) if array.get('from') is not None else None
        data['forward_from'] = User.from_array(array.get('forward_from')) if array.get('forward_from') is not None else None
        data['forward_from_chat'] = Chat.from_array(array.get('forward_from_chat')) if array.get('forward_from_chat') is not None else None
        data['forward_from_message_id'] = int(array.get('forward_from_message_id')) if array.get('forward_from_message_id') is not None else None
        data['forward_date'] = int(array.get('forward_date')) if array.get('forward_date') is not None else None
        data['reply_to_message'] = Message.from_array(array.get('reply_to_message')) if array.get('reply_to_message') is not None else None
        data['edit_date'] = int(array.get('edit_date')) if array.get('edit_date') is not None else None
        data['text'] = str(array.get('text')) if array.get('text') is not None else None
        data['entities'] = MessageEntity.from_array_list(array.get('entities'), list_level=1) if array.get('entities') is not None else None
        data['audio'] = Audio.from_array(array.get('audio')) if array.get('audio') is not None else None
        data['document'] = Document.from_array(array.get('document')) if array.get('document') is not None else None
        data['game'] = Game.from_array(array.get('game')) if array.get('game') is not None else None
        data['photo'] = PhotoSize.from_array_list(array.get('photo'), list_level=1) if array.get('photo') is not None else None
        data['sticker'] = Sticker.from_array(array.get('sticker')) if array.get('sticker') is not None else None
        data['video'] = Video.from_array(array.get('video')) if array.get('video') is not None else None
        data['voice'] = Voice.from_array(array.get('voice')) if array.get('voice') is not None else None
        data['caption'] = str(array.get('caption')) if array.get('caption') is not None else None
        data['contact'] = Contact.from_array(array.get('contact')) if array.get('contact') is not None else None
        data['location'] = Location.from_array(array.get('location')) if array.get('location') is not None else None
        data['venue'] = Venue.from_array(array.get('venue')) if array.get('venue') is not None else None
        data['new_chat_member'] = User.from_array(array.get('new_chat_member')) if array.get('new_chat_member') is not None else None
        data['left_chat_member'] = User.from_array(array.get('left_chat_member')) if array.get('left_chat_member') is not None else None
        data['new_chat_title'] = str(array.get('new_chat_title')) if array.get('new_chat_title') is not None else None
        data['new_chat_photo'] = PhotoSize.from_array_list(array.get('new_chat_photo'), list_level=1) if array.get('new_chat_photo') is not None else None
        data['delete_chat_photo'] = bool(array.get('delete_chat_photo')) if array.get('delete_chat_photo') is not None else None
        data['group_chat_created'] = bool(array.get('group_chat_created')) if array.get('group_chat_created') is not None else None
        data['supergroup_chat_created'] = bool(array.get('supergroup_chat_created')) if array.get('supergroup_chat_created') is not None else None
        data['channel_chat_created'] = bool(array.get('channel_chat_created')) if array.get('channel_chat_created') is not None else None
        data['migrate_to_chat_id'] = int(array.get('migrate_to_chat_id')) if array.get('migrate_to_chat_id') is not None else None
        data['migrate_from_chat_id'] = int(array.get('migrate_from_chat_id')) if array.get('migrate_from_chat_id') is not None else None
        data['pinned_message'] = Message.from_array(array.get('pinned_message')) if array.get('pinned_message') is not None else None
        return Message(**data)
Ejemplo n.º 26
0
    def from_array(array):
        """
        Deserializes a new Message from a given dictionary.

        :return: new Message instance.
        :rtype: Message
        """
        if array is None or not array:
            return None
        # end if
        assert (isinstance(array, dict))

        from pytgbot.api_types.receivable.media import Audio
        from pytgbot.api_types.receivable.media import Contact
        from pytgbot.api_types.receivable.media import Document
        from pytgbot.api_types.receivable.media import Game
        from pytgbot.api_types.receivable.media import Location
        from pytgbot.api_types.receivable.media import MessageEntity
        from pytgbot.api_types.receivable.media import PhotoSize
        from pytgbot.api_types.receivable.media import Sticker
        from pytgbot.api_types.receivable.media import Venue
        from pytgbot.api_types.receivable.media import Video
        from pytgbot.api_types.receivable.media import Voice
        from pytgbot.api_types.receivable.peer import Chat
        from pytgbot.api_types.receivable.peer import User
        from pytgbot.api_types.receivable.updates import Message

        data = {}
        data['message_id'] = int(array.get('message_id'))
        data['date'] = int(array.get('date'))
        data['chat'] = Chat.from_array(array.get('chat'))
        data['from_peer'] = User.from_array(
            array.get('from')) if array.get('from') is not None else None
        data['forward_from'] = User.from_array(array.get(
            'forward_from')) if array.get('forward_from') is not None else None
        data['forward_from_chat'] = Chat.from_array(
            array.get('forward_from_chat')) if array.get(
                'forward_from_chat') is not None else None
        data['forward_from_message_id'] = int(
            array.get('forward_from_message_id')) if array.get(
                'forward_from_message_id') is not None else None
        data['forward_date'] = int(array.get('forward_date')) if array.get(
            'forward_date') is not None else None
        data['reply_to_message'] = Message.from_array(
            array.get('reply_to_message')) if array.get(
                'reply_to_message') is not None else None
        data['edit_date'] = int(array.get('edit_date')) if array.get(
            'edit_date') is not None else None
        data['text'] = str(
            array.get('text')) if array.get('text') is not None else None
        data['entities'] = MessageEntity.from_array_list(
            array.get('entities'),
            list_level=1) if array.get('entities') is not None else None
        data['audio'] = Audio.from_array(
            array.get('audio')) if array.get('audio') is not None else None
        data['document'] = Document.from_array(array.get(
            'document')) if array.get('document') is not None else None
        data['game'] = Game.from_array(
            array.get('game')) if array.get('game') is not None else None
        data['photo'] = PhotoSize.from_array_list(
            array.get('photo'),
            list_level=1) if array.get('photo') is not None else None
        data['sticker'] = Sticker.from_array(
            array.get('sticker')) if array.get('sticker') is not None else None
        data['video'] = Video.from_array(
            array.get('video')) if array.get('video') is not None else None
        data['voice'] = Voice.from_array(
            array.get('voice')) if array.get('voice') is not None else None
        data['caption'] = str(
            array.get('caption')) if array.get('caption') is not None else None
        data['contact'] = Contact.from_array(
            array.get('contact')) if array.get('contact') is not None else None
        data['location'] = Location.from_array(array.get(
            'location')) if array.get('location') is not None else None
        data['venue'] = Venue.from_array(
            array.get('venue')) if array.get('venue') is not None else None
        data['new_chat_member'] = User.from_array(
            array.get('new_chat_member')) if array.get(
                'new_chat_member') is not None else None
        data['left_chat_member'] = User.from_array(
            array.get('left_chat_member')) if array.get(
                'left_chat_member') is not None else None
        data['new_chat_title'] = str(array.get('new_chat_title')) if array.get(
            'new_chat_title') is not None else None
        data['new_chat_photo'] = PhotoSize.from_array_list(
            array.get('new_chat_photo'),
            list_level=1) if array.get('new_chat_photo') is not None else None
        data['delete_chat_photo'] = bool(
            array.get('delete_chat_photo')) if array.get(
                'delete_chat_photo') is not None else None
        data['group_chat_created'] = bool(
            array.get('group_chat_created')) if array.get(
                'group_chat_created') is not None else None
        data['supergroup_chat_created'] = bool(
            array.get('supergroup_chat_created')) if array.get(
                'supergroup_chat_created') is not None else None
        data['channel_chat_created'] = bool(
            array.get('channel_chat_created')) if array.get(
                'channel_chat_created') is not None else None
        data['migrate_to_chat_id'] = int(
            array.get('migrate_to_chat_id')) if array.get(
                'migrate_to_chat_id') is not None else None
        data['migrate_from_chat_id'] = int(
            array.get('migrate_from_chat_id')) if array.get(
                'migrate_from_chat_id') is not None else None
        data['pinned_message'] = Message.from_array(
            array.get('pinned_message')) if array.get(
                'pinned_message') is not None else None
        return Message(**data)