1
0
Fork 0
This repository has been archived on 2023-03-27. 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
827 B
Ruby
Raw Normal View History

2018-12-06 20:25:38 -05:00
# frozen_string_literal: true
class InitializeTelegramBot
include Interactor
2018-12-06 21:24:33 -05:00
include Rails.application.routes.url_helpers
2018-12-06 20:25:38 -05:00
def call
2018-12-06 21:24:33 -05:00
fetch_info
set_webhook
end
private
def fetch_info
2018-12-07 13:03:01 -05:00
user = context.telegram_bot.client.get_me
2018-12-07 09:31:06 -05:00
context.telegram_bot.update! username: user.username
rescue Telegram::Bot::Error, ActiveRecord::RecordInvalid
context.fail!
2018-12-06 20:25:38 -05:00
end
2018-12-06 21:24:33 -05:00
def set_webhook
2018-12-07 13:03:01 -05:00
context.telegram_bot.client.set_webhook(
2018-12-07 09:31:06 -05:00
url: webhook_url,
max_connections: 1,
2018-12-06 21:24:33 -05:00
)
2018-12-07 09:31:06 -05:00
rescue Telegram::Bot::Error
context.fail!
2018-12-06 21:24:33 -05:00
end
def webhook_url
2019-01-30 19:56:37 -05:00
callbacks_telegram_bot_updates_url(
2018-12-06 21:43:30 -05:00
context.telegram_bot,
format: 'json',
protocol: 'https',
host: Rails.application.config.site_domain,
secret: context.telegram_bot.secret,
2018-12-06 21:24:33 -05:00
)
end
2018-12-06 20:25:38 -05:00
end