Class: SpreeCmCommissioner::TelegramChatsAutoFinder

Inherits:
BaseInteractor show all
Defined in:
app/interactors/spree_cm_commissioner/telegram_chats_auto_finder.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/interactors/spree_cm_commissioner/telegram_chats_auto_finder.rb', line 5

def call
  context.chats = []
  context.verified_chat_ids = []

  updates = fetch_updates

  if updates['result'].any?
    updates['result'].sort_by { |u| u['update_id'] }.reverse.each do |update|
      handle_message_update(update) if update['message']
      handle_channel_post_update(update) if update['channel_post']
      handle_chat_member_update(update) if update['my_chat_member']
    end
  end
  context.fail!(message: 'No pin codes verified') if context.verified_chat_ids.empty?
end