Class: TelegramOnSteroids::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_on_steroids/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_params) ⇒ Process

Returns a new instance of Process.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/telegram_on_steroids/process.rb', line 4

def initialize(raw_params)
  @params  = TelegramOnSteroids::Params.new(raw_params)
  @session = TelegramOnSteroids::Session.new(@params)
  chat_id = @params.chat_id
  @client = TelegramOnSteroids.config.client.new(chat_id)
  @logger = TelegramOnSteroids.config.logger

  if TelegramOnSteroids.config.commands.keys.include?(params.message_text)
    set_current_action(TelegramOnSteroids.config.commands[params.message_text])
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2
3
4
# File 'lib/telegram_on_steroids/process.rb', line 2

def client
  @client
end

#paramsObject (readonly)

Returns the value of attribute params.



2
3
4
# File 'lib/telegram_on_steroids/process.rb', line 2

def params
  @params
end

#sessionObject (readonly)

Returns the value of attribute session.



2
3
4
# File 'lib/telegram_on_steroids/process.rb', line 2

def session
  @session
end

Instance Method Details

#log_requestObject



16
17
18
19
# File 'lib/telegram_on_steroids/process.rb', line 16

def log_request
  @logger.info "[TelegramOnSteroids] Processing by #{current_action.class.name}##{current_step}"
  @logger.info "[TelegramOnSteroids] Params: #{params.to_h}"
end

#processObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/telegram_on_steroids/process.rb', line 21

def process
  log_request

  if current_action.respond_to?("__run_on_#{params.type}".to_sym)
    current_action.send("__run_on_#{params.type}".to_sym)
  else
    current_action.__run_on_message if current_action.respond_to?(:__run_on_message)
  end

  session.write(:current_page, 1) unless params.callback?

  if current_action.redirect_to
    do_redirect
  end

  @session.dump

  @client.inline_request
end