def format_message
      message = Message.new

      message.id = @id
      message.text = @raw_data['text'] ||= ''
      media = @raw_data['media']
      message.type = media ? media['type'] : 'text'
      message.raw_from = @raw_data['from']['peer_id']
      message.from_type = @raw_data['from']['peer_type']
      message.raw_to = @raw_data['to']['peer_id']
      message.to_type = @raw_data['to']['peer_type']

      from = @client.contacts.find { |c| c.id == message.raw_from }
      to = @client.contacts.find { |c| c.id == message.raw_to }
      to = @client.chats.find { |c| c.id == message.raw_to } if to.nil?

      message.from = from
      message.to = to

      @message = message

      if @message.from.nil?
        user = @raw_data['from']
        user = TelegramContact.pick_or_new(@client, user)
        @client.contacts << user unless @client.contacts.include?(user)
        @message.from = user
      end

      if @message.to.nil?
        type = @raw_data['to']['peer_type']
        case type
        when 'chat', 'encr_chat'
          chat = TelegramChat.pick_or_new(@client, @raw_data['to'])
          @client.chats << chat unless @client.chats.include?(chat)
          if type == 'encr_chat' then
            @message.to = chat
          else
            @message.from = chat
          end
        when 'user'
          user = TelegramContact.pick_or_new(@client, @raw_data['to'])
          @client.contacts << user unless @client.contacts.include?(user)
          @message.to = user
        end
      end
    end
def format_message
      message = Message.new

      message.id = @id
      message.text = @raw_data['text'] ||= ''
      media = @raw_data['media']
      message.type = media ? media['type'] : 'text'
      message.raw_from = @raw_data['from']['peer_id']
      message.from_type = @raw_data['from']['peer_type']
      message.raw_to = @raw_data['to']['peer_id']
      message.to_type = @raw_data['to']['peer_type']

      from = @client.contacts.find { |c| c.id == message.raw_from }
      to = @client.contacts.find { |c| c.id == message.raw_to }
      to = @client.chats.find { |c| c.id == message.raw_to } if to.nil?

      message.from = from
      message.to = to

      @message = message

      if @message.from.nil?
        user = @raw_data['from']
        user = TelegramContact.pick_or_new(@client, user)
        @client.contacts << user unless @client.contacts.include?(user)
        @message.from = user
      end

      if @message.to.nil?
        type = @raw_data['to']['peer_type']
        case type
        when 'chat', 'encr_chat'
          chat = TelegramChat.pick_or_new(@client, @raw_data['to'])
          @client.chats << chat unless @client.chats.include?(chat)
          if type == 'encr_chat' then
            @message.to = chat
          else
            @message.from = chat
          end
        when 'user'
          user = TelegramContact.pick_or_new(@client, @raw_data['to'])
          @client.contacts << user unless @client.contacts.include?(user)
          @message.to = user
        end
      end
    end
Process raw data in which event type is message given.

 @return [void]
 @api private