Guest User

Untitled

a guest
Jun 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'fsr'
  3. require 'fsr/listener/outbound'
  4. require 'activerecord'
  5.  
  6. FSR.load_all_commands
  7.  
  8. class Card < ActiveRecord::Base
  9. ActiveRecord::Base.establish_connection(
  10. :adapter => "mysql",
  11. :host => "localhost",
  12. :username => "root",
  13. :password => "leenuhks",
  14. :database => "fs_bill_development"
  15. )
  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. play_and_get_digits(pin_wav, bad_pin_wav, 2, 10, 3, 7000, ["#"], "pin_number", "\\d") do |pin_number|
  27. @card = Card.find_by_card_number(pin_number)
  28. if @card then
  29. FSR::Log.info "*** Success, grabbed #{pin_number} from #{exten}"
  30. play_and_get_digits(dial_tone, bad_pin_wav, 2, 10, 3, 7000, ["#"], "destination_number", "\\d") do |destination_number|
  31. FSR::Log.info "*** Success, grabbed #{destination_number} from #{exten}"
  32. FSR::Log.info "*** Setting up the billing variables."
  33. uuid_setvar(@session.headers[:unique_id], 'nibble_rate', @card.rate)
  34. uuid_setvar(@session.headers[:unique_id], 'nibble_account', @card.id)
  35. FSR::Log.info "*** Bridging."
  36. FSR::Log.info "*** You have #{duration} minutes to talk."
  37. speak("You have #{duration} minutes to talk.")
  38. api("sched_api +#{(duration*60)-60} none uuid_displace #{@session.headers[:unique_id]} start tone_stream://%(500,0,500)")
  39. transfer("#{destination_number}", "XML", "default") { close_connection }
  40. #bridge("sofia/internal/#{destination_number}@63.211.239.19")
  41. end
  42. else
  43. FSR::Log.info "*** Failure, grabbed #{pin_number} from #{exten}"
  44. playback(bad_pin_wav)
  45. FSR::Log.info "*** Hanging up the call."
  46. hangup
  47. end
  48. end
  49. end
  50. end
  51.  
  52. def duration
  53. @duration = @card.balance.to_i / @card.rate.to_i
  54. return @duration
  55. end
  56. end
  57.  
  58. FSR.start_oes! CallCard, :port => 8084, :host => "127.0.0.1"
Add Comment
Please, Sign In to add comment