Guest User

Untitled

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