diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:01:45 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:01:45 +0100 |
commit | b80bd744ad873f6fc43018bc4bfb90677de167bd (patch) | |
tree | 072c4b0e33d442528555b82c415f5e7a1712b2b0 /lib/tasks/send_voicemail_notifications.rake | |
parent | 3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff) |
Start of GS5.
Diffstat (limited to 'lib/tasks/send_voicemail_notifications.rake')
-rw-r--r-- | lib/tasks/send_voicemail_notifications.rake | 52 |
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 |