Class: Botiasloop::Commands::Switch

Inherits:
Base
  • Object
show all
Defined in:
lib/botiasloop/commands/switch.rb

Overview

Switch command - switches to a different conversation by label or ID

Instance Method Summary collapse

Methods inherited from Base

command, description, inherited

Instance Method Details

#execute(context, args = nil) ⇒ String

Execute the switch command

Parameters:

  • context (Context)

    Execution context

  • args (String, nil) (defaults to: nil)

    Label or UUID to switch to

Returns:

  • (String)

    Command response with conversation preview



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/botiasloop/commands/switch.rb', line 15

def execute(context, args = nil)
  identifier = args.to_s.strip

  return "Usage: /switch <label-or-id>" if identifier.empty?

  new_conversation = context.chat.switch_conversation(identifier)
  context.conversation = new_conversation

  format_switch_response(new_conversation)
rescue Botiasloop::Error => e
  "Error: #{e.message}"
end