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

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.



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

def initialize(**opts)
  return unless enabled?

  @bot_id = bot_id_from_settings
  super
end

Instance Method Details

#check_subtask?Boolean

Returns:

  • (Boolean)


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

def check_subtask?  = false

#delayObject



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

def delay           = 60

#enabled?Boolean

Returns:

  • (Boolean)


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

def enabled?
  settings.dig(:direct_chat_poller, :enabled) &&
    defined?(Legion::Extensions::MicrosoftTeams::Runners::Bot) &&
    Legion.const_defined?(:Transport, false)
rescue StandardError => e
  handle_exception(e, level: :debug, operation: 'DirectChatPoller#enabled?')
  false
end

#generate_task?Boolean

Returns:

  • (Boolean)


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

def generate_task?  = false

#manualObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/extensions/microsoft_teams/actors/direct_chat_poller.rb', line 36

def manual
  log.debug('DirectChatPoller#manual starting')
  token = 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("DirectChatPoller found #{chats.length} bot chats")
  chats.each { |chat| poll_chat(chat_id: chat[:id], token: token) }
rescue StandardError => e
  handle_exception(e, level: :error, operation: 'DirectChatPoller#manual')
end

#run_now?Boolean

Returns:

  • (Boolean)


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

def run_now?        = false

#runner_classObject



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

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

#runner_functionObject



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

def runner_function = 'handle_message'

#timeObject



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

def time            = settings.dig(:direct_chat_poller, :interval)

#use_runner?Boolean

Returns:

  • (Boolean)


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

def use_runner?     = false