summaryrefslogtreecommitdiff
path: root/app/mailers
diff options
context:
space:
mode:
Diffstat (limited to 'app/mailers')
-rw-r--r--app/mailers/.gitkeep0
-rw-r--r--app/mailers/notifications.rb110
2 files changed, 110 insertions, 0 deletions
diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/mailers/.gitkeep
diff --git a/app/mailers/notifications.rb b/app/mailers/notifications.rb
new file mode 100644
index 0000000..2c7f2ce
--- /dev/null
+++ b/app/mailers/notifications.rb
@@ -0,0 +1,110 @@
+class Notifications < ActionMailer::Base
+ default from: "admin@example.com"
+
+ # Subject can be set in your I18n file at config/locales/en.yml
+ # with the following lookup:
+ #
+ # en.notifications.new_pin.subject
+ #
+ def new_pin(conference)
+ @conference = conference
+
+ @pin = Hash.new()
+ if conference.conferenceable_type == 'User'
+ user = conference.conferenceable
+
+ if ! user.first_name.blank?
+ @pin[:greeting] = user.first_name
+ else
+ @pin[:greeting] = user.user_name
+ end
+ else
+ @pin[:greeting] = conference.conferenceable.to_s
+ end
+
+ @pin[:conference] = conference.to_s
+ @pin[:pin] = conference.pin
+ @pin[:phone_numbers] = conference.phone_numbers.join(', ')
+
+ mail(from: Tenant.find(DEFAULT_API_TENANT_ID).from_field_pin_change_email,to: "#{conference.conferenceable.email}", :subject => "Conference PIN changed: #{@pin[:conference]}")
+ end
+
+ def new_password(user, password)
+ @password = password
+
+ @message = Hash.new()
+ if ! user.first_name.blank?
+ @message[:greeting] = user.first_name
+ else
+ @message[:greeting] = user.user_name
+ end
+
+ mail(from: Tenant.find(DEFAULT_API_TENANT_ID).from_field_pin_change_email, to: "#{user.email}", :subject => "Password recovery")
+ end
+
+ def new_voicemail(freeswitch_voicemail_msg, attach_file = false)
+ sip_account = SipAccount.find_by_auth_name(freeswitch_voicemail_msg.username)
+ user = sip_account.sip_accountable
+
+ @voicemail = Hash.new()
+ if ! user.first_name.blank?
+ @voicemail[:greeting] = user.first_name
+ else
+ @voicemail[:greeting] = user.user_name
+ end
+
+ @voicemail[:destination] = freeswitch_voicemail_msg.in_folder
+ @voicemail[:from] = "#{freeswitch_voicemail_msg.cid_number} #{freeswitch_voicemail_msg.cid_name}"
+ @voicemail[:to] = sip_account.to_s
+ @voicemail[:date] = Time.at(freeswitch_voicemail_msg.created_epoch).getlocal.to_s
+ @voicemail[:duration] = Time.at(freeswitch_voicemail_msg.message_len).utc.strftime('%T')
+
+ if attach_file
+ caller_number = freeswitch_voicemail_msg.cid_number.gsub(/[^0-9]/, '')
+ if caller_number.blank?
+ caller_number = 'anonymous'
+ end
+ attachments["#{Time.at(freeswitch_voicemail_msg.created_epoch).getlocal.strftime('%Y%m%d-%H%M%S')}-#{caller_number}.wav"] = File.read(freeswitch_voicemail_msg.file_path)
+ end
+
+ mail(from: Tenant.find(DEFAULT_API_TENANT_ID).from_field_voicemail_email, to: "#{user.email}", :subject => "New Voicemail from #{@voicemail[:from]}, received #{Time.at(freeswitch_voicemail_msg.created_epoch).getlocal.to_s}")
+ end
+
+ def new_fax(fax_document)
+ fax_account = fax_document.fax_account
+
+ if !fax_account || fax_account.email.blank?
+ return false
+ end
+
+ caller_number = fax_document.caller_id_number.gsub(/[^0-9]/, '')
+ if caller_number.blank?
+ caller_number = 'anonymous'
+ end
+
+ @fax = {
+ :greeting => '',
+ :account_name => fax_account.name,
+ :from => "#{caller_number} #{fax_document.caller_id_name}",
+ :remote_station_id => fax_document.remote_station_id,
+ :local_station_id => fax_document.local_station_id,
+ :date => fax_document.created_at,
+ }
+
+ if fax_account.fax_accountable
+ if fax_account.fax_accountable_type == 'User'
+ user = fax_account.fax_accountable
+ if ! user.first_name.blank?
+ @fax[:greeting] = user.first_name
+ else
+ @fax[:greeting] = user.user_name
+ end
+ elsif fax_account.fax_accountable_type == 'Tenant'
+ @fax[:greeting] = fax_account.fax_accountable.name
+ end
+ end
+ attachments["#{fax_document.created_at.strftime('%Y%m%d-%H%M%S')}-#{caller_number}.pdf"] = File.read(fax_document.document.path)
+ mail(from: Tenant.find(DEFAULT_API_TENANT_ID).from_field_voicemail_email, to: "#{fax_account.email}", :subject => "New Fax Document from #{@fax[:from]}, received #{fax_document.created_at}")
+ end
+
+end