This presentation was given by Jay Phillips, Adhearsion's creator, at the Gotham Ruby Conference on April 21st, 2007. Adhearsion is a framework for developing collaboration applications with Asterisk (VoIP), Rails, instant messaging, email, and many other technologies.
22. Writing Adhearsion Dialplans internal { case extension when 10 ... 100 dial SIP /extension when 6000 ... 6020 , 7000 .. 7030 join extension when _ ' 21XX ' if Time .now.hour.between? 2 , 10 dial SIP / " berlin-office " /extension[ 2 .. 4 ] else speak " It is not business hours now in Germany. " end ...
23. Writing Adhearsion Dialplans ... when US_NUMBER dial SIP / ' us-trunk-out ' /extension when / ^ {11,}$ / dial IAX / ' intl-trunk-out ' /extension else play %w' sorry invalid extension please-try-again ' end }
24. Database-Driven Dialplans Dialplans service { customer = Account.find_by_phone_number callerid usage = customer.usage_this_month if usage >= 100.hours then +beyond_limit else customer.usage_this_month += time do dial IAX2/'main-trunk'/extension end end } beyond_limit { play %w"sorry your-limit-of 100 hours has-been-reached" }
29. Helpers require "hpricot" require "open-uri" def lookup number hash = {} url = " http://www.whitepages.com/9901/search/ReversePhone?phone=#{number} " doc = Hpricot open(url) # This div contains all the information we need, unless it's an unlisted number if (results = doc.at "#results_single_listing") then # This div's h3 contains the name of the caller hash[:first_name], hash[:last_name] = results.at('h3').inner_html.split(/,*/).reverse # Now we just need the rest of the information contained in p's. meta = results/'p' meta.pop # Discard the useless p element hash[:number] = meta.pop.inner_html city_info = meta.pop.inner_html city_info = city_info.match /(.+), ([A-Za-z]{2}) ({5})/ hash[:city] = city_info[1] hash[:state] = city_info[2] hash[:zip] = city_info[3] hash[:address] = meta.map(&:inner_html) * " " elsif (results = doc.at "#results_single_phone_info") then meta = results/'span' hash[:location] = (meta.pop.inner_html.match /Location: (.*)/)[1] end if hash[:first_name] or hash[:last_name] then hash[:composite] = "#{hash[:first_name]} #{hash[:last_name]}" else hash[:composite] = hash[:location] end hash end
30. Helpers (in C) (in C) int fast_factorial(int input) { int prod = 1, count = 1; while(count <= input) { prod *= count++; } return sum; }
33. Micromenus item 'Adhearsion Server Statistics' do item 'View Registered SIP Users' do PBX.sip_users.each do |u| item "SIP user '#{u.username}' on IP #{u.ip}" end end item 'View System Uptime' do item `uptime` end item 'Network' do heading 'Network Interface Info' `ifconfig eth1`.each_line do |line| item line end end end
34. Micromenus item 'Call an Employee' do item 'Select an employee below.' User.find(:all).each do |user| call user.extension, user.name end end call 'Join main conference' do play 'welcome' join 5555 end