Module: Legion::Gaia::Proactive

Defined in:
lib/legion/gaia/proactive.rb

Class Method Summary collapse

Class Method Details

.broadcast(content:, channels: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/legion/gaia/proactive.rb', line 27

def broadcast(content:, channels: nil)
  registry = Legion::Gaia.channel_registry
  return { error: 'channel registry not available' } unless registry

  targets = channels || registry.active_channels
  results = {}
  targets.each do |ch|
    results[ch] = send_message(channel_id: ch, content: content)
  end
  results
end

.send_message(channel_id:, content:, user_id: nil, content_type: :text) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/gaia/proactive.rb', line 7

def send_message(channel_id:, content:, user_id: nil, content_type: :text)
  registry = Legion::Gaia.channel_registry
  return { error: 'channel registry not available' } unless registry

  adapter = registry.adapter_for(channel_id)
  return { error: "no adapter for channel: #{channel_id}" } unless adapter

  output = OutputFrame.new(
    content: content,
    content_type: content_type,
    channel_id: channel_id,
    metadata: { proactive: true, target_user: user_id }
  )

  registry.deliver(output)
  { sent: true, frame_id: output.id, channel: channel_id }
rescue StandardError => e
  { error: e.message }
end