Class: Telegram::Rails::ActionDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/rails/action_dispatcher.rb

Constant Summary collapse

ROUTE_DELIMETER =
"/"
ENDPOINT_DELIMETER =
"#"
COMMAND_START_SYMBOL =
"/"
COMMAND_ARGS_SEPARATOR =
/\s+/
DEFAULT_ACTION_NAME =
:process

Instance Method Summary collapse

Constructor Details

#initialize(adapters) ⇒ ActionDispatcher

Returns a new instance of ActionDispatcher.



15
16
17
18
# File 'lib/telegram/rails/action_dispatcher.rb', line 15

def initialize adapters
  @adapters = adapters
  @routes   = []
end

Instance Method Details

#dispatch_message(bot_name, message) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/telegram/rails/action_dispatcher.rb', line 27

def dispatch_message bot_name, message
  adapter = find_adapter_for bot_name
  return unless adapter

  command, args = extract_command_from message
  route = find_route_for bot_name, command
  return unless route

  process_message message, with: route
end

#register_route(route_data) ⇒ Object



21
22
23
24
# File 'lib/telegram/rails/action_dispatcher.rb', line 21

def register_route route_data
  route = parse_route(route_data)
  @routes << route
end