Skip to content
Snippets Groups Projects
Unverified Commit a249b289 authored by tribut's avatar tribut :man_dancing:
Browse files

Refactor telegram notification settings

parent 2cb5d60a
Branches
No related tags found
No related merge requests found
......@@ -9,7 +9,8 @@ class TelegramGroupChatNotificationJob < NotificationJob
return unless channel&.data
token = channel.data['token']
return unless token
args[:target] = "2192297" if Rails.env.development?
args[:parse_mode] ||= "HTML"
args[:target] ||= Rails.application.config.telegram_default_target
Telegram::Bot::Client.run(token) do |bot|
bot.api.send_message(chat_id: args[:target], text: args[:text], parse_mode: args[:parse_mode])
end
......
......@@ -13,13 +13,11 @@ class TelegramNotifyUpcomingJob < ApplicationJob
message = notify_names.join(' ') + ": Your scheduled session <i>#{session.title}</i> starts at <b>#{session.starts_at.strftime("%H:%M")}</b> on <b>#{session.stage.name}</b>"
message += "<br>Speakers: #{session.speakers.map(&:name).join(', ')}"
TelegramGroupChatNotificationJob.perform_later(target: "-316096320", text: message, parse_mode: 'HTML')
# TelegramGroupChatNotificationJob.perform_now(target: "2192297", text: message, parse_mode: 'HTML')
TelegramGroupChatNotificationJob.perform_later(text: message)
else
message = "<b>⚠️ No assignees</b> for session <i>#{session.title}</i> starting at <b>#{session.starts_at.strftime("%H:%M")}</b> on <b>#{session.stage.name}</b>"
message += "<br>Speakers: #{session.speakers.map(&:name).join(', ')}"
TelegramGroupChatNotificationJob.perform_later(target: "-316096320", text: message, parse_mode: 'HTML')
# TelegramGroupChatNotificationJob.perform_now(target: "2192297", text: message, parse_mode: 'HTML')
TelegramGroupChatNotificationJob.perform_later(text: message)
end
end
end
......
......@@ -30,8 +30,7 @@ class TelegramBotSubscriber
message = "<b><a href=\"#{conference_session_url(session.conference, session, host: 'rescheduled.c3lingo.org', protocol: 'https')}\">Session #{session.title}</a> #{action}</b>\n" +
changes.map { |attr, (from, to)| "- #{attr}: #{from} -> #{to}" }.join("\n") + "\n#{conference_session_url(session.conference, session)}"
TelegramGroupChatNotificationJob.perform_later(target: "-316096320", text: message, parse_mode: 'HTML')
# TelegramGroupChatNotificationJob.perform_later(target: "2192297", text: message, parse_mode: 'HTML')
TelegramGroupChatNotificationJob.perform_later(text: message)
end
def handle_session_speaker_event(event)
......@@ -45,6 +44,6 @@ class TelegramBotSubscriber
message = "<b><a href=\"#{conference_session_url(session.conference, session, host: 'rescheduled.c3lingo.org', protocol: 'https')}\">Session #{session.title}</a> Speaker Change</b>\n" +
"#{session_speaker.speaker.name} #{action == 'destroyed' ? 'removed' : 'added'}" + "\n#{conference_session_url(session.conference, session)}"
TelegramGroupChatNotificationJob.perform_later(target: "-316096320", text: message, parse_mode: 'HTML')
TelegramGroupChatNotificationJob.perform_later(text: message)
end
end
......@@ -73,6 +73,8 @@ Rails.application.configure do
# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true
config.telegram_default_target = ENV["TELEGRAM_DEFAULT_TARGET"] || "2192297"
end
Rails.application.routes.default_url_options[:host] = '127.0.0.1'
......
......@@ -103,6 +103,8 @@ Rails.application.configure do
# ]
# Skip DNS rebinding protection for the default health check endpoint.
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
config.telegram_default_target = ENV["TELEGRAM_DEFAULT_TARGET"] || "-316096320"
end
# Rails.application.routes.default_url_options.merge({ host: 'rescheduled.c3lingo.org', protocol: 'https' })
......
def fetch_credential(key)
ENV[key.upcase] ||
Rails.application.credentials.dig(Rails.env.to_sym, key) ||
Rails.application.credentials[key.to_sym]
end
......@@ -78,7 +78,9 @@ end
end
end
NotificationChannel.create!(
name: 'telegram_group_chat',
data: { token: '6001822848:AAGR0hPl3upppQAQy2VrJBHud466QVsBnyQ' }
)
if token = fetch_credential("telegram_bot_token")
NotificationChannel.find_or_create_by(name: "telegram_group_chat") do |c|
c.token = token
c.save!
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment