require 'telegram/params' module Telegram module Params class Message attr_reader :params, :message_id, :from, :date, :chat, :forward_from, :forward_from_chat, :forward_from_message_id, :forward_signature, :forward_date, :reply_to_message, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities, :audio, :document, :animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact, :location, :venue, :new_chat_members, :left_chat_member, :new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created, :supergroup_chat_created, :channel_chat_created, :migrate_to_chat_id, :migrate_from_chat_id, :pinned_message, :invoice, :successful_payment, :connected_website, :passport_data def initialize(params) message_params = message_params_permit_from(params) @params = params.require(:message) @message_id = message_params[:message_id] @from = Telegram::Params::From.new(params) @date = message_params[:date] @chat = Telegram::Params::Chat.new(params) @forward_from = Telegram::Params::ForwardFrom.new(params) @forward_from_chat = Telegram::Params::ForwardChat.new(params) @forward_from_message_id = message_params[:forward_from_message_id] @forward_signature = message_params[:forward_signature] @forward_date = message_params[:forward_date] @reply_to_message = message_params[:reply_to_message] @edit_date = message_params[:edit_date] @media_group_id = message_params[:media_group_id] @author_signature = message_params[:author_signature] @text = message_params[:text] @entities = message_params[:entities] @caption_entities = message_params[:caption_entities] @audio = message_params[:audio] @document = message_params[:document] @animation = message_params[:animation] @game = message_params[:game] @photo = message_params[:photo] @sticker = message_params[:sticker] @video = message_params[:video] @voice = message_params[:voice] @video_note = message_params[:video_note] @caption = message_params[:caption] @contact = message_params[:contact] @location = message_params[:location] @venue = message_params[:venue] @new_chat_members = message_params[:new_chat_members] @left_chat_member = message_params[:left_chat_member] @new_chat_title = message_params[:new_chat_title] @new_chat_photo = message_params[:new_chat_photo] @delete_chat_photo = message_params[:delete_chat_photo] @group_chat_created = message_params[:group_chat_created] @supergroup_chat_created = message_params[:supergroup_chat_created] @channel_chat_created = message_params[:channel_chat_created] @migrate_to_chat_id = message_params[:migrate_to_chat_id] @migrate_from_chat_id = message_params[:migrate_from_chat_id] @pinned_message = message_params[:pinned_message] @invoice = message_params[:invoice] @successful_payment = message_params[:successful_payment] @connected_website = message_params[:connected_website] @passport_data = message_params[:passport_data] end def nil? self.instance_variables.map{ |attribute| self.instance_variable_get(attribute) } .map(&:nil?) .reduce(:&) end private def message_params_permit_from(params) params.require(:message) .permit( :message_id, :from, :date, :chat, :forward_from, :forward_from_chat, :forward_from_message_id, :forward_signature, :forward_date, :reply_to_message, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities, :audio, :document, :animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact, :location, :venue, :new_chat_members, :left_chat_member, :new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created, :supergroup_chat_created, :channel_chat_created, :migrate_to_chat_id, :migrate_from_chat_id, :pinned_message, :invoice, :successful_payment, :connected_website, :passport_data ) end end end end