2019-05-12 22:37:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-11-02 11:58:29 -05:00
|
|
|
DiscourseEvent.on(:site_setting_changed) do |setting_name, old_value, new_value|
|
|
|
|
isEnabledSetting = setting_name == :chat_integration_telegram_enabled
|
|
|
|
isAccessToken = setting_name == :chat_integration_telegram_access_token
|
2019-06-05 22:26:24 -04:00
|
|
|
|
2020-11-02 11:58:29 -05:00
|
|
|
if (isEnabledSetting || isAccessToken)
|
|
|
|
enabled = isEnabledSetting ? new_value == true : SiteSetting.chat_integration_telegram_enabled
|
2019-06-05 21:51:40 -04:00
|
|
|
|
2020-11-02 11:58:29 -05:00
|
|
|
if enabled && SiteSetting.chat_integration_telegram_access_token.present?
|
|
|
|
Scheduler::Defer.later("Setup Telegram Webhook") do
|
2021-07-13 15:36:16 -04:00
|
|
|
DiscourseChatIntegration::Provider::TelegramProvider.setup_webhook
|
2017-07-19 11:28:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-01 15:53:39 -04:00
|
|
|
end
|