Previously, email replies were handled inside workers. There was no execution logs. This meant if emails silently failed (as reported by a customer), we had no way to trace where the issue happened, the only assumption was “no error = mail sent.” By moving email handling into jobs, we now have proper execution logs for each attempt. This makes it easier to debug delivery issues and would have better visibility when investigating customer reports. Fixes https://linear.app/chatwoot/issue/CW-5538/emails-are-not-sentdelivered-to-the-contact --------- Co-authored-by: Sojan Jose <sojan@pepalo.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
39 lines
1.3 KiB
Ruby
39 lines
1.3 KiB
Ruby
class SendReplyJob < ApplicationJob
|
|
queue_as :high
|
|
|
|
CHANNEL_SERVICES = {
|
|
'Channel::TwitterProfile' => ::Twitter::SendOnTwitterService,
|
|
'Channel::TwilioSms' => ::Twilio::SendOnTwilioService,
|
|
'Channel::Line' => ::Line::SendOnLineService,
|
|
'Channel::Telegram' => ::Telegram::SendOnTelegramService,
|
|
'Channel::Whatsapp' => ::Whatsapp::SendOnWhatsappService,
|
|
'Channel::Sms' => ::Sms::SendOnSmsService,
|
|
'Channel::Instagram' => ::Instagram::SendOnInstagramService,
|
|
'Channel::Email' => ::Email::SendOnEmailService,
|
|
'Channel::WebWidget' => ::Messages::SendEmailNotificationService,
|
|
'Channel::Api' => ::Messages::SendEmailNotificationService
|
|
}.freeze
|
|
|
|
def perform(message_id)
|
|
message = Message.find(message_id)
|
|
channel_name = message.conversation.inbox.channel.class.to_s
|
|
|
|
return send_on_facebook_page(message) if channel_name == 'Channel::FacebookPage'
|
|
|
|
service_class = CHANNEL_SERVICES[channel_name]
|
|
return unless service_class
|
|
|
|
service_class.new(message: message).perform
|
|
end
|
|
|
|
private
|
|
|
|
def send_on_facebook_page(message)
|
|
if message.conversation.additional_attributes['type'] == 'instagram_direct_message'
|
|
::Instagram::Messenger::SendOnInstagramService.new(message: message).perform
|
|
else
|
|
::Facebook::SendOnFacebookService.new(message: message).perform
|
|
end
|
|
end
|
|
end
|