Guest User

Untitled

a guest
Mar 4th, 2018
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. require 'rubygems'
  2. require 'sinatra' # Get with "gem install sinatra"
  3. require 'restful_adhearsion'
  4. require 'pp'
  5.  
  6. #Create our Adhearsion object connected to the RESTful API of Adhearsion
  7. Adhearsion = RESTfulAdhearsion.new(:host => "localhost",
  8. :port => 5000,
  9. :user => "jicksta",
  10. :password => "roflcopterz")
  11.  
  12. # You'll need to change this for your own format.
  13. # Note: this will soon be handled by the Call Routing DSL in Adhearsion.
  14. def format_number(number)
  15. "IAX2/username:password@test.voipjet.com/#{number}"
  16. #""
  17. end
  18.  
  19. get "/callurl" do
  20. options = { :channel => format_number(params[:source]),
  21. :context => "clicktocall",
  22. :priority => "1",
  23. :exten => "1000",
  24. :async => 'true',
  25. :variable => "destination=" + format_number(params[:destination]) }
  26.  
  27. #Originates a call over the AMI interface
  28. Adhearsion.originate options
  29. "ok".to_json
  30. end
  31.  
  32. post "/call" do
  33. options = { :channel => format_number(params[:source]),
  34. :context => "clicktocall",
  35. :priority => "1",
  36. :exten => "1000",
  37. :async => 'true',
  38. :variable => "destination=" + format_number(params[:destination]) }
  39.  
  40. #Originates a call over the AMI interface
  41. Adhearsion.originate options
  42. "ok".to_json
  43. end
  44.  
  45. post "/hangup" do
  46. #Get the channel of the active call, then hang it up
  47. channel_of_active_call = Adhearsion.hangup_channel_with_destination params[:call_to_hangup]
  48. "ok".to_json
  49. end
  50.  
  51. get '/status' do
  52. # The line below will return either {result:"alive"} or {result:"dead"} to the browser
  53. {:result => Adhearsion.call_with_destination(params[:destination])}.to_json
  54. end
  55.  
  56. get '/' do
  57. #Build our web form that has the JQuery sprinkled in
  58. <<-HTML
  59. <html>
  60.  
  61. (some html)
  62.  
  63. HTML
  64. end
Add Comment
Please, Sign In to add comment