Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 4.23 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. switchvox.yml
  2. default:
  3.    switchvox_ip: PBX.IP.Com
  4.    faye_ip: 0.0.0.0:9292
  5.  
  6. development:
  7.    switchvox_ip: PBX.IP.Com
  8.    faye_ip: 0.0.0.0:9292
  9.  
  10. production:
  11.    switchvox_ip: PBX.IP.Com
  12.    faye_ip: 0.0.0.0:9292
  13.  
  14. switchvox.rb
  15. yaml_config = YAML.load_file("#{RAILS_ROOT}/config/switchvox.yml") || {}
  16. CONFIG = (yaml_config['default'] || {}).symbolize_keys.merge((yaml_config[RAILS_ENV] || {}).symbolize_keys)
  17.  
  18. incomings_controller
  19. require 'switchvox'
  20. class IncomingsController < ApplicationController
  21.   def index
  22.    @incoming = Incoming.all
  23.  
  24.   end
  25. #the new method creates a record of the calls in database, queries sugarCRM for records matching the caller's phone number and publishes the data via the messaging server(faye)
  26.   def new
  27.     @incoming = Incoming.create({:exten_number => params[:exten_number], :cid_number => params[:cid_number]})
  28.   if (params[:cid_number])[0] == "8"
  29.    params[:cid_number] = "0" + params[:cid_number]
  30.    begin
  31.      @contact = Sugar.find_by_phone_fax(params[:cid_number]) || Sugar.find_by_phone_mobile(params[:cid_number]) || Sugar.find_by_phone_other(params[:cid_number]) || Sugar.find_by_phone_work(params[:cid_number])
  32.    rescue
  33.      @contact = Sugar.find_by_phone_fax(params[:cid_number]) || Sugar.find_by_phone_mobile(params[:cid_number]) || Sugar.find_by_phone_other(params[:cid_number]) || Sugar.find_by_phone_work(params[:cid_number])
  34.    end
  35.   elsif (params[:cid_number])[0] == "7"
  36.    params[:cid_number] = "0" + params[:cid_number]
  37.    begin
  38.      @contact = Sugar.find_by_phone_fax(params[:cid_number]) || Sugar.find_by_phone_mobile(params[:cid_number]) || Sugar.find_by_phone_other(params[:cid_number]) || Sugar.find_by_phone_work(params[:cid_number])
  39.    rescue
  40.      @contact = Sugar.find_by_phone_fax(params[:cid_number]) || Sugar.find_by_phone_mobile(params[:cid_number]) || Sugar.find_by_phone_other(params[:cid_number]) || Sugar.find_by_phone_work(params[:cid_number])
  41.    end
  42.   elsif (params[:cid_number])[0] == "1"
  43.    params[:cid_number] = "0" + params[:cid_number]
  44.    begin
  45.      @contact = Sugar.find_by_phone_fax(params[:cid_number]) || Sugar.find_by_phone_mobile(params[:cid_number]) || Sugar.find_by_phone_other(params[:cid_number]) || Sugar.find_by_phone_work(params[:cid_number])
  46.    rescue
  47.      @contact = Sugar.find_by_phone_fax(params[:cid_number]) || Sugar.find_by_phone_mobile(params[:cid_number]) || Sugar.find_by_phone_other(params[:cid_number]) || Sugar.find_by_phone_work(params[:cid_number])
  48.    end
  49.   end
  50.  
  51.      
  52.       if @incoming.update_attributes(params[:incoming])
  53.  
  54.        require 'eventmachine'
  55.        #the IP address for the machine hosting the faye messaging server should be passed here
  56.        faye = Faye::Client.new('http://' + "#{CONFIG.faye_ip}" + '/faye')
  57.        unless @contact.nil?
  58.           msg = JSON.dump('channel' => "/incomings", 'data' => {'exten_id' => "#{@incoming.exten_number}", 'caller_id' =>  "#{@contact.id}", 'caller_name' =>  "#{@contact.account_name.split(' ').map {|w| w.capitalize }.join(' ')}", 'caller_number' => "#{params[:cid_number]}" })
  59.           uri = URI.parse('http://' + "#{CONFIG.faye_ip}" + '/faye')
  60.           Net::HTTP.post_form(uri, :message => msg)
  61.          #EM.run {
  62.            #faye.publish("/incomings", {'exten_id' => "#{@incoming.exten_number}", 'caller_id' =>  "#{@contact.id}", 'caller_name' =>  "#{@contact.account_name.capitalize}", 'caller_number' => "#{params[:cid_number]}" })
  63.        #}
  64.        else
  65.           msg = JSON.dump('channel' => "/incomings", 'data' => {"exten_id" => "#{@incoming.exten_number}", "caller_number" => "#{params[:cid_number]}", "caller_name" => "no details exists for this user"})
  66.           uri = URI.parse('http://' + "#{CONFIG.faye_ip}" + '/faye')
  67.           Net::HTTP.post_form(uri, :message => msg)
  68.           #EM.run {
  69.             #faye.publish("/incomings", {"exten_id" => "#{@incoming.exten_number}", "caller_number" => "#{params[:cid_number]}", "caller_name" => "no details exists for this user"})
  70.           #}
  71.        end
  72. #       end
  73.    
  74.       end
  75.     respond_to do |format|
  76.       format.html # index.html.erb
  77.       format.xml  { render :xml => @incoming }
  78.     end
  79.   end
  80.  
  81.   def create
  82.     @incoming = Incoming.new(params[:incoming])
  83.   end
  84.  
  85.   # GET /incomings/1
  86.   # GET /incomings/1.xml
  87.  
  88.   def call
  89.       Switchvox_call.calling(params[:dial_number])
  90.   end
  91.  
  92.  
  93.     def update
  94.   end
  95. end