diff --git a/app/interactors/spree_cm_commissioner/telegram_debug_pin_code_sender.rb b/app/interactors/spree_cm_commissioner/telegram_debug_pin_code_sender.rb index 16be24bd4..f9249e46f 100644 --- a/app/interactors/spree_cm_commissioner/telegram_debug_pin_code_sender.rb +++ b/app/interactors/spree_cm_commissioner/telegram_debug_pin_code_sender.rb @@ -4,7 +4,7 @@ class TelegramDebugPinCodeSender < BaseInteractor def call telegram_client.send_message( - chat_id: ENV.fetch('EXCEPTION_NOTIFIER_TELEGRAM_CHANNEL_ID', nil), + chat_id: chat_id, parse_mode: 'HTML', text: body ) diff --git a/app/interactors/spree_cm_commissioner/telegram_notification_sender.rb b/app/interactors/spree_cm_commissioner/telegram_notification_sender.rb index 34342289b..a45d80e1d 100644 --- a/app/interactors/spree_cm_commissioner/telegram_notification_sender.rb +++ b/app/interactors/spree_cm_commissioner/telegram_notification_sender.rb @@ -19,7 +19,7 @@ def telegram_client def notifier_error_message(error_message) ::Telegram.bots[:exception_notifier].send_message( chat_id: chat_id, - text: "Telgram Notifier Error:\n#{error_message}\nSend Text:\n#{message}" + text: "Telegram Notifier Error:\n#{error_message}\nSend Text:\n#{message}" ) end end diff --git a/app/jobs/spree_cm_commissioner/telegram_notification_sender_job.rb b/app/jobs/spree_cm_commissioner/telegram_notification_sender_job.rb index 4cf686fa8..ccaa93406 100644 --- a/app/jobs/spree_cm_commissioner/telegram_notification_sender_job.rb +++ b/app/jobs/spree_cm_commissioner/telegram_notification_sender_job.rb @@ -1,6 +1,8 @@ module SpreeCmCommissioner class TelegramNotificationSenderJob < ApplicationJob def perform(options) + return if options[:chat_id].nil? + SpreeCmCommissioner::TelegramNotificationSender.call( chat_id: options[:chat_id], message: options[:message], diff --git a/app/models/concerns/spree_cm_commissioner/order_requestable.rb b/app/models/concerns/spree_cm_commissioner/order_requestable.rb index 6ea06b87b..cc42f1d29 100644 --- a/app/models/concerns/spree_cm_commissioner/order_requestable.rb +++ b/app/models/concerns/spree_cm_commissioner/order_requestable.rb @@ -97,8 +97,10 @@ def send_order_complete_telegram_alert_to_vendors vendor_list.each do |vendor| title = '🎫 --- [NEW ORDER FROM BOOKME+] ---' chat_id = vendor.preferred_telegram_chat_id - factory = OrderTelegramMessageFactory.new(title: title, order: self, vendor: vendor) - TelegramNotificationSenderJob.perform_later(chat_id: chat_id, message: factory.message, parse_mode: factory.parse_mode) + if chat_id.present? + factory = OrderTelegramMessageFactory.new(title: title, order: self, vendor: vendor) + TelegramNotificationSenderJob.perform_later(chat_id: chat_id, message: factory.message, parse_mode: factory.parse_mode) + end end end diff --git a/spec/jobs/spree_cm_commissioner/telegram_notification_sender_job_spec.rb b/spec/jobs/spree_cm_commissioner/telegram_notification_sender_job_spec.rb index 1201ecdb4..1bd948b0d 100644 --- a/spec/jobs/spree_cm_commissioner/telegram_notification_sender_job_spec.rb +++ b/spec/jobs/spree_cm_commissioner/telegram_notification_sender_job_spec.rb @@ -18,4 +18,14 @@ parse_mode: parse_mode ) end -end \ No newline at end of file + + it 'does not call TelegramNotificationSender when chat_id is nil' do + expect(SpreeCmCommissioner::TelegramNotificationSender).not_to receive(:call) + + subject.perform( + chat_id: nil, + message: message, + parse_mode: parse_mode + ) + end +end