Restructure omni services and add Chatwoot research snapshot
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
class AdministratorNotifications::AccountComplianceMailer < AdministratorNotifications::BaseMailer
|
||||
def account_deleted(account)
|
||||
return if instance_admin_email.blank?
|
||||
|
||||
subject = subject_for(account)
|
||||
meta = build_meta(account)
|
||||
|
||||
send_notification(subject, to: instance_admin_email, meta: meta)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_meta(account)
|
||||
deleted_users = params[:soft_deleted_users] || []
|
||||
|
||||
user_info_list = deleted_users.map do |user|
|
||||
{
|
||||
'user_id' => user[:id].to_s,
|
||||
'user_email' => user[:original_email].to_s
|
||||
}
|
||||
end
|
||||
|
||||
{
|
||||
'instance_url' => instance_url,
|
||||
'account_id' => account.id,
|
||||
'account_name' => account.name,
|
||||
'deleted_at' => format_time(Time.current.iso8601),
|
||||
'deletion_reason' => account.custom_attributes['marked_for_deletion_reason'] || 'not specified',
|
||||
'marked_for_deletion_at' => format_time(account.custom_attributes['marked_for_deletion_at']),
|
||||
'soft_deleted_users' => user_info_list,
|
||||
'deleted_user_count' => user_info_list.size
|
||||
}
|
||||
end
|
||||
|
||||
def format_time(time_string)
|
||||
return 'not specified' if time_string.blank?
|
||||
|
||||
Time.zone.parse(time_string).strftime('%B %d, %Y %H:%M:%S %Z')
|
||||
end
|
||||
|
||||
def subject_for(account)
|
||||
"Account Deletion Notice for #{account.id} - #{account.name}"
|
||||
end
|
||||
|
||||
def instance_admin_email
|
||||
GlobalConfig.get('CHATWOOT_INSTANCE_ADMIN_EMAIL')['CHATWOOT_INSTANCE_ADMIN_EMAIL']
|
||||
end
|
||||
|
||||
def instance_url
|
||||
ENV.fetch('FRONTEND_URL', 'not available')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,70 @@
|
||||
class AdministratorNotifications::AccountNotificationMailer < AdministratorNotifications::BaseMailer
|
||||
def account_deletion_user_initiated(account, reason)
|
||||
subject = 'Your Chatwoot account deletion has been scheduled'
|
||||
action_url = settings_url('general')
|
||||
meta = {
|
||||
'account_name' => account.name,
|
||||
'deletion_date' => format_deletion_date(account.custom_attributes['marked_for_deletion_at']),
|
||||
'reason' => reason
|
||||
}
|
||||
|
||||
send_notification(subject, action_url: action_url, meta: meta)
|
||||
end
|
||||
|
||||
def account_deletion_for_inactivity(account, reason)
|
||||
subject = 'Your Chatwoot account is scheduled for deletion due to inactivity'
|
||||
action_url = settings_url('general')
|
||||
meta = {
|
||||
'account_name' => account.name,
|
||||
'deletion_date' => format_deletion_date(account.custom_attributes['marked_for_deletion_at']),
|
||||
'reason' => reason
|
||||
}
|
||||
|
||||
send_notification(subject, action_url: action_url, meta: meta)
|
||||
end
|
||||
|
||||
def contact_import_complete(resource)
|
||||
subject = 'Contact Import Completed'
|
||||
|
||||
action_url = if resource.failed_records.attached?
|
||||
Rails.application.routes.url_helpers.rails_blob_url(resource.failed_records)
|
||||
else
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{resource.account.id}/contacts"
|
||||
end
|
||||
|
||||
meta = {
|
||||
'failed_contacts' => resource.total_records - resource.processed_records,
|
||||
'imported_contacts' => resource.processed_records
|
||||
}
|
||||
|
||||
send_notification(subject, action_url: action_url, meta: meta)
|
||||
end
|
||||
|
||||
def contact_import_failed
|
||||
subject = 'Contact Import Failed'
|
||||
send_notification(subject)
|
||||
end
|
||||
|
||||
def contact_export_complete(file_url, email_to)
|
||||
subject = "Your contact's export file is available to download."
|
||||
send_notification(subject, to: email_to, action_url: file_url)
|
||||
end
|
||||
|
||||
def automation_rule_disabled(rule)
|
||||
subject = 'Automation rule disabled due to validation errors.'
|
||||
action_url = settings_url('automation/list')
|
||||
meta = { 'rule_name' => rule.name }
|
||||
|
||||
send_notification(subject, action_url: action_url, meta: meta)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_deletion_date(deletion_date_str)
|
||||
return 'Unknown' if deletion_date_str.blank?
|
||||
|
||||
Time.zone.parse(deletion_date_str).strftime('%B %d, %Y')
|
||||
rescue StandardError
|
||||
'Unknown'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
class AdministratorNotifications::BaseMailer < ApplicationMailer
|
||||
# Common method to check SMTP configuration and send mail with liquid
|
||||
def send_notification(subject, to: nil, action_url: nil, meta: {})
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
@action_url = action_url
|
||||
@meta = meta || {}
|
||||
|
||||
send_mail_with_liquid(to: to || admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
# Helper method to generate inbox URL
|
||||
def inbox_url(inbox)
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}"
|
||||
end
|
||||
|
||||
# Helper method to generate settings URL
|
||||
def settings_url(section)
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/#{section}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def admin_emails
|
||||
Current.account.administrators.pluck(:email)
|
||||
end
|
||||
|
||||
def liquid_locals
|
||||
super.merge({ meta: @meta })
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
class AdministratorNotifications::ChannelNotificationsMailer < AdministratorNotifications::BaseMailer
|
||||
def facebook_disconnect(inbox)
|
||||
subject = 'Your Facebook page connection has expired'
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
|
||||
def instagram_disconnect(inbox)
|
||||
subject = 'Your Instagram connection has expired'
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
|
||||
def tiktok_disconnect(inbox)
|
||||
subject = 'Your TikTok connection has expired'
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
|
||||
def whatsapp_disconnect(inbox)
|
||||
subject = 'Your Whatsapp connection has expired'
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
|
||||
def email_disconnect(inbox)
|
||||
subject = 'Your email inbox has been disconnected. Please update the credentials for SMTP/IMAP'
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class AdministratorNotifications::IntegrationsNotificationMailer < AdministratorNotifications::BaseMailer
|
||||
def slack_disconnect
|
||||
subject = 'Your Slack integration has expired'
|
||||
action_url = settings_url('integrations/slack')
|
||||
send_notification(subject, action_url: action_url)
|
||||
end
|
||||
|
||||
def dialogflow_disconnect
|
||||
subject = 'Your Dialogflow integration was disconnected'
|
||||
send_notification(subject)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user