summaryrefslogtreecommitdiff
path: root/lib/tasks/send_voicemail_notifications.rake
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks/send_voicemail_notifications.rake')
-rw-r--r--lib/tasks/send_voicemail_notifications.rake52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/tasks/send_voicemail_notifications.rake b/lib/tasks/send_voicemail_notifications.rake
new file mode 100644
index 0000000..214d832
--- /dev/null
+++ b/lib/tasks/send_voicemail_notifications.rake
@@ -0,0 +1,52 @@
+# encoding: UTF-8
+
+desc "Import inbound voicemail"
+
+task :send_voicemail_notifications => :environment do
+ VoicemailMessage.where(:notification => nil).each do |message|
+
+ message.notification = false
+ message.save
+ if !File.exists?( message.file_path )
+ $stderr.puts "File \"#{message.file_path}\" does not exist"
+ next
+ end
+
+ sip_account = SipAccount.where(:auth_name => message.username).first
+ if ! sip_account
+ $stderr.puts "SipAccount \"#{message.username}\" does not exist"
+ next
+ end
+
+ user = sip_account.sip_accountable
+ if user.class != User
+ next
+ end
+
+ if user.email.blank?
+ $stderr.puts "no email address"
+ next
+ end
+
+ voicemail_settings = sip_account.voicemail_setting
+ if !voicemail_settings
+ voicemail_settings = VoicemailSetting.new(:notify => user.send_voicemail_as_email_attachment, :attachment => user.send_voicemail_as_email_attachment, :mark_read => user.send_voicemail_as_email_attachment)
+ end
+
+ message.notification = voicemail_settings.notify
+ if voicemail_settings.notify
+ if Notifications.new_voicemail(message, voicemail_settings.attachment).deliver
+ if voicemail_settings.purge
+ message.delete
+ next
+ end
+ message.save
+ if voicemail_settings.mark_read
+ message.mark_read
+ end
+ end
+ else
+ message.save
+ end
+ end
+end