Class: ChatMessage

Inherits:
ApplicationRecord show all
Defined in:
app/models/chat_message.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection

Instance Method Details

#broadcast_message(event_type) ⇒ Object

Returns the content of the message

Parameters:

  • event_type (String)

    The type of message, either ‘new_message’ or ‘updated_message’ or ‘updating_finished’ or ‘message_deleted’



20
21
22
23
24
25
26
27
28
29
# File 'app/models/chat_message.rb', line 20

def broadcast_message(event_type)
  ActionCable.server.broadcast(
    "chat_channel_#{chat.id}",
    {
      message: event_type,
      # data: self.as_json(include: :chat)
      data: self.as_json
    }
  )
end

#roleObject



13
14
15
# File 'app/models/chat_message.rb', line 13

def role
  sender == 'user' ? 'user' : 'assistant'
end