Class: Botiasloop::Commands::Archive

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

Overview

Archive command - archives a conversation by label or ID, or current conversation if no args

Instance Method Summary collapse

Methods inherited from Base

command, description, inherited

Instance Method Details

#execute(context, args = nil) ⇒ String

Execute the archive command Without args: archives current conversation and creates a new one With args: archives the specified conversation

Parameters:

  • context (Context)

    Execution context

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

    Label or ID to archive (nil = archive current)

Returns:

  • (String)

    Command response with archived conversation details



17
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/commands/archive.rb', line 17

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

  if identifier.empty?
    # Archive current conversation and create new one
    result = context.chat.archive_current
    context.conversation = result[:new_conversation]
    format_archive_current_response(result[:archived], result[:new_conversation])
  else
    # Archive specific conversation by label or ID
    conversation = find_conversation(identifier)
    raise Botiasloop::Error, "Conversation '#{identifier}' not found" unless conversation

    # Cannot archive current conversation via identifier
    if conversation.id == context.conversation.id
      raise Botiasloop::Error,
        "Cannot archive the current conversation. Use /archive without arguments to archive current and start new."
    end

    conversation.archive!
    format_archive_response(conversation)
  end
rescue Botiasloop::Error => e
  "Error: #{e.message}"
end