Skip to content

Commit

Permalink
close #1167 fix bug telegram bot chat_id nil bad request (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
LengTech11 authored Mar 1, 2024
1 parent 092a02c commit ffe4407
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@
parse_mode: parse_mode
)
end
end

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

0 comments on commit ffe4407

Please sign in to comment.