Class: Legion::Extensions::MicrosoftTeams::Absorbers::Chat

Inherits:
Absorbers::Base
  • Object
show all
Defined in:
lib/legion/extensions/microsoft_teams/absorbers/chat.rb

Instance Method Summary collapse

Instance Method Details

#absorb(url: nil, content: nil, metadata: {}, context: {}) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/legion/extensions/microsoft_teams/absorbers/chat.rb', line 12

def absorb(url: nil, content: nil, metadata: {}, context: {}) # rubocop:disable Lint/UnusedMethodArgument
  report_progress(message: 'extracting chat id from url')
  chat_id = extract_chat_id(url)
  return { success: false, error: 'could not extract chat id from url' } unless chat_id

  report_progress(message: 'fetching chat metadata', percent: 10)
  chat = resolve_chat(chat_id)
  return { success: false, error: 'could not resolve chat' } unless chat

  topic = chat['topic'] || chat[:topic] || 'untitled chat'
  results = { chat_id: chat_id, topic: topic, chunks: 0 }

  ingest_messages(chat_id, topic, results)
  ingest_members(chat_id, topic, results)

  report_progress(message: 'done', percent: 100)
  results.merge(success: true)
rescue StandardError => e
  log.error("Chat absorber failed: #{e.message}")
  { success: false, error: e.message }
end