Class: Events::BounceBack

Inherits:
Base
  • Object
show all
Defined in:
lib/events/bounce_back.rb

Overview

Transient failure event emitted when LLM delivery fails inside the Bounce Back transaction. The user event record is rolled back, and this event notifies clients to remove the phantom message and restore the text to the input field.

Not persisted — not included in Message::TYPES.

Constant Summary collapse

TYPE =
"bounce_back"

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #session_id, #timestamp

Instance Method Summary collapse

Methods inherited from Base

#event_name

Constructor Details

#initialize(content:, error:, session_id:, message_id: nil) ⇒ BounceBack

Returns a new instance of BounceBack.

Parameters:

  • content (String)

    original user message text to restore to input

  • error (String)

    error description for the flash message

  • session_id (Integer)

    session the message was intended for

  • message_id (Integer, nil) (defaults to: nil)

    ID of the message that was broadcast optimistically



23
24
25
26
27
# File 'lib/events/bounce_back.rb', line 23

def initialize(content:, error:, session_id:, message_id: nil)
  super(content: content, session_id: session_id)
  @error = error
  @message_id = message_id
end

Instance Attribute Details

#errorString (readonly)

Returns human-readable error description.

Returns:

  • (String)

    human-readable error description



14
15
16
# File 'lib/events/bounce_back.rb', line 14

def error
  @error
end

#message_idInteger? (readonly)

Returns database ID of the rolled-back message (for client-side removal).

Returns:

  • (Integer, nil)

    database ID of the rolled-back message (for client-side removal)



17
18
19
# File 'lib/events/bounce_back.rb', line 17

def message_id
  @message_id
end

Instance Method Details

#to_hObject



33
34
35
# File 'lib/events/bounce_back.rb', line 33

def to_h
  super.merge(error: error, message_id: message_id)
end

#typeObject



29
30
31
# File 'lib/events/bounce_back.rb', line 29

def type
  TYPE
end