Class: Botiasloop::Channels::CLI
- Defined in:
- lib/botiasloop/channels/cli.rb
Constant Summary collapse
- EXIT_COMMANDS =
%w[exit quit \q].freeze
- SOURCE_ID =
"cli"
Instance Method Summary collapse
-
#authorized?(_source_id) ⇒ Boolean
Check if source is authorized (CLI is always authorized).
-
#deliver_message(_source_id, formatted_content) ⇒ Object
Deliver a formatted message to the CLI.
-
#extract_content(raw_message) ⇒ String
Extract content from raw message For CLI, the raw message is already the content string.
-
#handle_error(source_id, _user_id, error, _raw_message) ⇒ Object
Handle errors by sending error message to user.
-
#initialize ⇒ CLI
constructor
Initialize CLI channel.
-
#running? ⇒ Boolean
Check if CLI channel is running.
-
#start_listening ⇒ Object
Start the CLI interactive mode.
-
#stop_listening ⇒ Object
Stop the CLI channel.
Methods inherited from Base
#after_process, #before_process, #channel_config, channel_name, #channel_type, #chat_for, #extract_user_id, #format_message, #handle_unauthorized, #process_message, required_config_keys, requires_config, #send_message
Constructor Details
#initialize ⇒ CLI
Initialize CLI channel
12 13 14 15 |
# File 'lib/botiasloop/channels/cli.rb', line 12 def initialize super @running = false end |
Instance Method Details
#authorized?(_source_id) ⇒ Boolean
Check if source is authorized (CLI is always authorized)
69 70 71 |
# File 'lib/botiasloop/channels/cli.rb', line 69 def (_source_id) true end |
#deliver_message(_source_id, formatted_content) ⇒ Object
Deliver a formatted message to the CLI
88 89 90 91 |
# File 'lib/botiasloop/channels/cli.rb', line 88 def (_source_id, formatted_content) puts "Agent: #{formatted_content}" puts end |
#extract_content(raw_message) ⇒ String
Extract content from raw message For CLI, the raw message is already the content string
61 62 63 |
# File 'lib/botiasloop/channels/cli.rb', line 61 def extract_content() end |
#handle_error(source_id, _user_id, error, _raw_message) ⇒ Object
Handle errors by sending error message to user
79 80 81 82 |
# File 'lib/botiasloop/channels/cli.rb', line 79 def handle_error(source_id, _user_id, error, ) Logger.error "[CLI] Error processing message: #{error.}" (source_id, "Error: #{error.}") end |
#running? ⇒ Boolean
Check if CLI channel is running
52 53 54 |
# File 'lib/botiasloop/channels/cli.rb', line 52 def running? @running end |
#start_listening ⇒ Object
Start the CLI interactive mode
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/botiasloop/channels/cli.rb', line 18 def start_listening @running = true Logger.info "[CLI] Starting interactive mode..." puts "botiasloop v#{VERSION} - Interactive Mode" puts "Type 'exit', 'quit', or '\\q' to exit" puts while @running print "You: " input = $stdin.gets&.chomp break if input.nil? || EXIT_COMMANDS.include?(input.downcase) puts (SOURCE_ID, input) end @running = false Logger.info "[CLI] Interactive mode ended" rescue Interrupt @running = false puts "\nGoodbye!" Logger.info "[CLI] Interrupted by user" end |