daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 116 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. #!/usr/bin/ruby
  2.  
  3. require 'rubygems'
  4. require 'fsr'
  5. require 'fsr/listener/outbound'
  6. require 'sequel'
  7.  
  8. FSR.load_all_commands
  9.  
  10. DB = Sequel.connect('mysql://root@localhost/callcard')
  11.  
  12. class Card < Sequel::Model
  13. end
  14.  
  15. class Destination < Sequel::Model
  16. end
  17.  
  18. class CallCard < FSR::Listener::Outbound
  19.   def session_initiated
  20.     exten = @session.headers[:caller_caller_id_number]
  21.     pin_wav = "/usr/local/freeswitch/sounds/en/us/callie/conference/8000/conf-pin.wav"
  22.     bad_pin_wav = "/usr/local/freeswitch/sounds/en/us/callie/conference/8000/conf-bad-pin.wav"
  23.     dial_tone = "tone_stream://%(10000,0,350,440)"
  24.     FSR::Log.info "*** Answering incoming call from #{exten}"
  25.     answer do
  26.       fs_sleep(2000) do
  27.         play_and_get_digits(pin_wav, bad_pin_wav, 2, 10, 3, 7000, ["#"], "pin_number", "\\d") do |pin_number|
  28.       @card = Card.find(:card_number => pin_number)
  29.           if @card
  30.             FSR::Log.info "*** Success, grabbed #{pin_number} from #{exten}"
  31.             play_and_get_digits(dial_tone, bad_pin_wav, 2, 11, 3, 7000, ["#"], "destination_number", "\\d") do |destination_number|
  32.               prefix = destination_number[0,5]
  33.           @destination = Destination.find(:prefix => prefix)
  34.               FSR::Log.info "*** Success, grabbed #{destination_number} from #{exten}"
  35.               FSR::Log.info "*** Setting up the billing variables."
  36.               uuid_setvar(@session.headers[:unique_id], 'nibble_rate', @destination.rate) if @destination.respond_to?(:rate)
  37.               uuid_setvar(@session.headers[:unique_id], 'nibble_account', @card.id)
  38.               FSR::Log.info "*** Bridging."
  39.               FSR::Log.info "*** You have #{duration} minutes to talk."
  40.               speak("You have #{duration} minutes to talk.")
  41.               transfer(destination_number, "XML", "default") { close_connection }
  42.               #bridge("sofia/internal/#{destination_number}@0.0.0.0")
  43.             end
  44.           else
  45.             FSR::Log.info "*** Failure, grabbed #{pin_number} from #{exten}"
  46.             playback(bad_pin_wav)
  47.             FSR::Log.info "*** Hanging up the call."
  48.             hangup
  49.           end
  50.         end
  51.       end
  52.     end
  53.   end
  54.  
  55.   def duration
  56.     @duration = @card.balance.to_i / @destination.rate.to_i if @destination.respond_to?(:rate)
  57.     return @duration
  58.   end
  59. end
  60.  
  61. FSR.start_oes! CallCard, :port => 8084, :host => "127.0.0.1"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top