1
0
Fork 0
This repository has been archived on 2023-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/interactors/initialize_telegram_bot.rb

41 lines
817 B
Ruby

# frozen_string_literal: true
class InitializeTelegramBot
include Interactor
include Rails.application.routes.url_helpers
def call
fetch_info
set_webhook
end
private
def fetch_info
user = context.telegram_bot.client.get_me
context.telegram_bot.update! username: user.username
rescue Telegram::Bot::Error, ActiveRecord::RecordInvalid
context.fail!
end
def set_webhook
context.telegram_bot.client.set_webhook(
url: webhook_url,
max_connections: 1,
)
rescue Telegram::Bot::Error
context.fail!
end
def webhook_url
telegram_bot_updates_url(
context.telegram_bot,
format: 'json',
protocol: 'https',
host: Rails.application.config.site_domain,
secret: context.telegram_bot.secret,
)
end
end