chore: Migrate mailers from the worker to jobs (#12331)
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>
This commit is contained in:
@@ -1,27 +1,29 @@
|
||||
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)
|
||||
conversation = message.conversation
|
||||
channel_name = conversation.inbox.channel.class.to_s
|
||||
channel_name = message.conversation.inbox.channel.class.to_s
|
||||
|
||||
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
|
||||
}
|
||||
return send_on_facebook_page(message) if channel_name == 'Channel::FacebookPage'
|
||||
|
||||
case channel_name
|
||||
when 'Channel::FacebookPage'
|
||||
send_on_facebook_page(message)
|
||||
else
|
||||
services[channel_name].new(message: message).perform if services[channel_name].present?
|
||||
end
|
||||
service_class = CHANNEL_SERVICES[channel_name]
|
||||
return unless service_class
|
||||
|
||||
service_class.new(message: message).perform
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user