Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save MaksimAbramchuk/da84477311279a9fa97cf0e6cda651bd to your computer and use it in GitHub Desktop.

Select an option

Save MaksimAbramchuk/da84477311279a9fa97cf0e6cda651bd to your computer and use it in GitHub Desktop.
class BotMessageDispatcher
attr_reader :message, :user
def initialize(message, user)
@message = message
@user = user
end
def process
if user.get_next_bot_command
bot_command = user.get_next_bot_command.safe_constantize.new(user, message)
if bot_command.should_start?
bot_command.start
else
unknown_command
end
else
start_command = BotCommand::Start.new(user, message)
if start_command.should_start?
start_command.start
else
unknown_command
end
end
end
private
def unknown_command
BotCommand::Undefined.new(user, message).start
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment