Class: Legion::Extensions::MicrosoftTeams::Actor::DirectChatPoller

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

Constant Summary collapse

POLL_INTERVAL =
15

Constants included from Helpers::HighWaterMark

Helpers::HighWaterMark::HWM_TTL

Instance Method Summary collapse

Methods included from Helpers::HighWaterMark

#get_extended_hwm, #get_hwm, #hwm_key, #memory_runner, #new_messages, #persist_hwm_as_trace, #restore_hwm_from_traces, #set_extended_hwm, #set_hwm, #update_extended_hwm, #update_hwm_from_messages

Methods included from Helpers::Client

#bot_connection, #graph_connection, #oauth_connection, #user_path

Constructor Details

#initialize(**opts) ⇒ DirectChatPoller

Returns a new instance of DirectChatPoller.



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

def initialize(**opts)
  return unless enabled?

  @bot_id = bot_id_from_settings
  super
end

Instance Method Details

#check_subtask?Boolean

Returns:

  • (Boolean)


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

def check_subtask?  = false

#delayObject



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

def delay           = 60

#enabled?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/legion/extensions/microsoft_teams/actors/direct_chat_poller.rb', line 29

def enabled?
  defined?(Legion::Extensions::MicrosoftTeams::Runners::Bot) &&
    Legion.const_defined?(:Transport, false)
rescue StandardError => e
  log.debug("DirectChatPoller#enabled?: #{e.message}")
  false
end

#generate_task?Boolean

Returns:

  • (Boolean)


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

def generate_task?  = false

#manualObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/legion/extensions/microsoft_teams/actors/direct_chat_poller.rb', line 41

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

  log.info('Polling bot DM chats')
  chats = fetch_bot_chats(token: token)
  log.info("Found #{chats.length} bot chats")
  chats.each { |chat| poll_chat(chat_id: chat[:id], token: token) }
rescue StandardError => e
  log.error("DirectChatPoller: #{e.message}")
end

#run_now?Boolean

Returns:

  • (Boolean)


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

def run_now?        = false

#runner_classObject



20
# File 'lib/legion/extensions/microsoft_teams/actors/direct_chat_poller.rb', line 20

def runner_class    = Legion::Extensions::MicrosoftTeams::Runners::Bot

#runner_functionObject



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

def runner_function = 'handle_message'

#timeObject



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

def time            = settings_interval(:direct_poll_interval, POLL_INTERVAL)

#token_cacheObject



37
38
39
# File 'lib/legion/extensions/microsoft_teams/actors/direct_chat_poller.rb', line 37

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

#use_runner?Boolean

Returns:

  • (Boolean)


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

def use_runner?     = false