Class: TelegramWorkflow::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_workflow/workflow.rb

Direct Known Subclasses

TelegramActionExampleGroup::TestFlow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_params) ⇒ Workflow

Returns a new instance of Workflow.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/telegram_workflow/workflow.rb', line 6

def initialize(raw_params)
  @params  = TelegramWorkflow::Params.new(raw_params)
  @session = TelegramWorkflow::Session.new(@params)

  @logger = TelegramWorkflow.config.logger
  @logger = @logger.tagged(SecureRandom.hex(8)) if TelegramWorkflow.config.tagged_logger?

  if @params.start?
    set_current_action(TelegramWorkflow.config.start_action)
  end

  chat_id = @session.read(:chat_id) || @session.write(:chat_id, @params.chat_id)
  @client = TelegramWorkflow.config.client.new(chat_id)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/telegram_workflow/workflow.rb', line 4

def client
  @client
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/telegram_workflow/workflow.rb', line 4

def logger
  @logger
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/telegram_workflow/workflow.rb', line 4

def params
  @params
end

Instance Method Details

#processObject



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

def process
  # run the shared step
  shared_step_result = current_action.shared

  if shared_step_result == :__continue
    log_request
    current_action.public_send(current_step) # setup callbacks
    current_action.__run_on_message # run a callback
  else
    @logger.info "Processing by shared handler"
  end

  while @redirect_to
    do_redirect
  end

  @session.dump

  @client.inline_request
end

#redirect_to(action_or_step, session_params = nil) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/telegram_workflow/workflow.rb', line 42

def redirect_to(action_or_step, session_params = nil)
  raise TelegramWorkflow::Errors::DoubleRedirect if @redirect_to
  raise TelegramWorkflow::Errors::SharedRedirect if action_or_step == :shared
  raise TelegramWorkflow::Errors::StartRedirect  if action_or_step == TelegramWorkflow.config.start_action

  @redirect_to = action_or_step
  @session_params = session_params
end