Guest User

Untitled

a guest
Jun 24th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. require 'fsr'
  2. require 'fsr/listener/outbound'
  3. require 'activerecord'
  4.  
  5. FSR.load_all_commands
  6.  
  7. class Card < ActiveRecord::Base
  8. ActiveRecord::Base.establish_connection(
  9. :adapter => "mysql",
  10. :host => "localhost",
  11. :username => "root",
  12. :password => "secret",
  13. :database => "fs_bill_development"
  14. )
  15. end
  16.  
  17. class CallCard < FSR::Listener::Outbound
  18. def session_initiated
  19. exten = @session.headers[:caller_caller_id_number]
  20. pin_wav = "/usr/local/freeswitch/sounds/en/us/callie/conference/8000/conf-pin.wav"
  21. bad_pin_wav = "/usr/local/freeswitch/sounds/en/us/callie/conference/8000/conf-bad-pin.wav"
  22. dial_tone = "tone_stream://%(10000,0,350,440)"
  23. FSR::Log.info "*** Answering incoming call from #{exten}"
  24. answer do
  25. play_and_get_digits(pin_wav, bad_pin_wav, 2, 10, 3, 7000, ["#"], "pin_number", "\\d") do |pin_number|
  26. @card = Card.find_by_card_number(pin_number)
  27. if @card then
  28. FSR::Log.info "*** Success, grabbed #{pin_number} from #{exten}"
  29. play_and_get_digits(dial_tone, bad_pin_wav, 2, 10, 3, 7000, ["#"], "destination_number", "\\d") do |destination_number|
  30. FSR::Log.info "*** Success, grabbed #{destination_number} from #{exten}"
  31. FSR::Log.info "*** Billing."
  32. uuid_setvar(@session.headers[:unique_id], 'nibble_rate', @card.rate)
  33. uuid_setvar(@session.headers[:unique_id], 'nibble_account', @card.id)
  34. FSR::Log.info "*** Bridging."
  35. FSR::Log.info "*** You have #{duration} minutes to talk."
  36. speak("You have #{duration} minutes to talk.")
  37. transfer("#{destination_number}", "XML", "default") { close_connection }
  38. #bridge("sofia/internal/#{destination_number}@63.211.239.19")
  39. end
  40. else
  41. FSR::Log.info "*** Failure, grabbed #{pin_number} from #{exten}"
  42. playback(bad_pin_wav)
  43. FSR::Log.info "*** Hanging up the call."
  44. hangup
  45. end
  46. end
  47. end
  48. end
  49.  
  50. def duration
  51. @duration = @card.balance.to_i / @card.rate.to_i
  52. return @duration
  53. end
  54. end
  55.  
  56. FSR.start_oes! CallCard, :port => 8084, :host => "127.0.0.1"
Add Comment
Please, Sign In to add comment