Class: Legion::Extensions::MicrosoftTeams::Actor::ChannelPoller

Inherits:
Actors::Every
  • Object
show all
Includes:
Helpers::Client
Defined in:
lib/legion/extensions/microsoft_teams/actors/channel_poller.rb

Constant Summary collapse

DEFAULT_INTERVAL =
60
DEFAULT_MAX_TEAMS =
10
DEFAULT_MAX_CHANNELS =
5

Instance Method Summary collapse

Methods included from Helpers::Client

#bot_connection, #graph_connection, #oauth_connection, #user_path

Constructor Details

#initialize(**opts) ⇒ ChannelPoller

Returns a new instance of ChannelPoller.



14
15
16
17
18
19
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 14

def initialize(**opts)
  return unless enabled?

  @channel_hwm = {}
  super
end

Instance Method Details

#check_subtask?Boolean

Returns:

  • (Boolean)


27
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 27

def check_subtask?  = false

#delayObject



24
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 24

def delay           = 300

#enabled?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 38

def enabled?
  return false unless defined?(Legion::Extensions::MicrosoftTeams::Helpers::TokenCache)

  channel_setting(:enabled, false) == true
rescue StandardError => e
  log.debug("ChannelPoller#enabled?: #{e.message}")
  false
end

#generate_task?Boolean

Returns:

  • (Boolean)


28
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 28

def generate_task?  = false

#manualObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 51

def manual
  log.info('ChannelPoller polling team channels')
  token = token_cache.cached_delegated_token
  unless token
    log.debug('No token available, skipping poll')
    return
  end

  teams = fetch_joined_teams(token: token)
  log.debug("Found #{teams.length} joined team(s)")

  teams.first(max_teams).each do |team|
    poll_team(team: team, token: token)
  rescue StandardError => e
    log.error("Error polling team #{team['displayName']}: #{e.message}")
  end
rescue StandardError => e
  log.error("ChannelPoller: #{e.message}")
end

#memory_available?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 30

def memory_available?
  defined?(Legion::Extensions::Agentic::Memory::Trace::Runners::Traces)
end

#memory_runnerObject



34
35
36
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 34

def memory_runner
  @memory_runner ||= Object.new.extend(Legion::Extensions::Agentic::Memory::Trace::Runners::Traces)
end

#run_now?Boolean

Returns:

  • (Boolean)


25
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 25

def run_now?        = false

#runner_classObject



21
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 21

def runner_class    = self.class

#runner_functionObject



22
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 22

def runner_function = 'manual'

#timeObject



23
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 23

def time            = channel_setting(:poll_interval, DEFAULT_INTERVAL)

#token_cacheObject



47
48
49
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 47

def token_cache
  Legion::Extensions::MicrosoftTeams::Helpers::TokenCache.instance
end

#use_runner?Boolean

Returns:

  • (Boolean)


26
# File 'lib/legion/extensions/microsoft_teams/actors/channel_poller.rb', line 26

def use_runner?     = false