Created
March 12, 2013 10:56
-
-
Save andrius/5141993 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Loads initial data (use once after migration)" | |
task "db:initialize" do | |
require './lib/initialize' | |
require 'fileutils' | |
# Print out DB log | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Base.logger.level = Logger::DEBUG | |
YAML::load_file("#{APP_ROOT}/config/pbxes.yml").each_pair do |name,params| | |
Pbx.create :name => name, | |
:hostname_or_ip_address => params["hostname"], | |
:username => params["username"], | |
:password => params["password"], | |
:port => params["port"] | |
end | |
pbx_1 = Pbx.first | |
debt_reminder_trunk_1 = Trunk.create :pbx => pbx_1, :sip_peer_name => "debt_reminder_outgoing", :dial_prefix => "00" | |
default_business_time = BusinessTime.create :name => "Call Mon-Fri 9 to 21; Sat, Sun 11 to 19" | |
# Always closed! | |
# It is a default condition with lowest priority and will be executed it other conditions did not met. | |
# BusinessTimeMember.create :business_time => business_time, :item => closed_action | |
BusinessTimeMember.create :business_time => default_business_time, :item_id => nil | |
# Make calls on business days (Monday to Friday) from 9:00 to 21:00, | |
# on weekends (Sunday and Saturday) from 11:00 to 19:00 | |
# 0 - Sun, 6 - Sat | |
0.upto(6) do |day| | |
time_from, time_to = if day == 0 || day == 6 then | |
#[Time.parse("11:00:00"), Time.parse("18:59:59")] | |
[Time.parse("00:00:00"), Time.parse("23:59:59")] | |
else | |
#[Time.parse("9:00:00"), Time.parse("20:59:59")] | |
[Time.parse("00:00:00"), Time.parse("23:59:59")] | |
end | |
# item_id 0 = continue dialplan! | |
# BusinessTimeMember.create :business_time => business_time, | |
# :item_id => 0, :weekday => day, | |
# :time_from => "6:00", :time_to => "17:00" | |
BusinessTimeMember.create :business_time => default_business_time, :item_id => 0, | |
:weekday => day, :time_from => time_from, :time_to => time_to | |
end | |
audios = {} | |
FileUtils.rm_rf "/var/lib/asterisk/audiofiles/_mohs" rescue nil | |
FileUtils.rm_rf "/var/lib/asterisk/audiofiles" rescue nil | |
FileUtils.mkdir_p "/var/lib/asterisk/audiofiles/_mohs" | |
FileUtils.mkdir_p "/var/lib/asterisk/audiofiles/audios" | |
%w(hello sorry-youre-having-problems your-account has not-enough-credit | |
if-you-need-help call someone-you-trust1 auth-thankyou goodbye | |
).each do |name| | |
key = name.gsub(/-| /,"_").to_sym | |
audio = AudioFile.create :name => key, :audio => File.new("/var/lib/asterisk/sounds/en/#{name}.wav", "r") | |
audio.convert :realtime => false | |
audios[key] = audio | |
end | |
introduction = AudioPhrase.create :audio1 => audios[:hello], | |
:audio2 => audios[:sorry_youre_having_problems], | |
:audio3 => audios[:your_account], | |
:audio4 => audios[:has], | |
:audio5 => audios[:not_enough_credit] | |
conclusion = AudioPhrase.create :audio1 => audios[:if_you_need_help], | |
:audio2 => audios[:call], | |
:audio3 => audios[:someone_you_trust1], | |
:audio4 => audios[:auth_thankyou], | |
:audio5 => audios[:goodbye] | |
# FaxCampaign.create :name => "fax_template_1", :faxfile => "fax_template_1.tif", :business_time_id => 1 | |
# creates a voice campaign with active state, so can start it immediately | |
# to start do following: rake console; Campaign.delivery_all (then ctrl-c and type 'exit') | |
campaign = VoiceCampaign.create :name => "Microsoft", :business_time_id => 1, | |
:introduction => introduction, :conclusion => conclusion, :state => "active" | |
CampaignTrunk.create :campaign => campaign, :trunk => debt_reminder_trunk_1 | |
# CampaignTrunk.create :campaign => campaign, :trunk => debt_reminder_trunk_2 | |
CampaignNumber.create :number => 37052030095, :campaign => campaign | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yay Ruby!!