Class: TelegramWorkflow::Workflow
- Inherits:
-
Object
- Object
- TelegramWorkflow::Workflow
- Defined in:
- lib/telegram_workflow/workflow.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(raw_params) ⇒ Workflow
constructor
A new instance of Workflow.
- #process ⇒ Object
- #redirect_to(action_or_step, session_params = nil) ⇒ Object
Constructor Details
#initialize(raw_params) ⇒ Workflow
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/telegram_workflow/workflow.rb', line 4 def initialize(raw_params) @params = TelegramWorkflow::Params.new(raw_params) @session = TelegramWorkflow::Session.new(@params) @logger = TelegramWorkflow.config.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
#client ⇒ Object (readonly)
Returns the value of attribute client.
2 3 4 |
# File 'lib/telegram_workflow/workflow.rb', line 2 def client @client end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
2 3 4 |
# File 'lib/telegram_workflow/workflow.rb', line 2 def params @params end |
Instance Method Details
#process ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/telegram_workflow/workflow.rb', line 17 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 a callback else @logger.info "[TelegramWorkflow] 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
38 39 40 41 42 43 44 45 |
# File 'lib/telegram_workflow/workflow.rb', line 38 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 |