I basically integrate Asterisk with RAGI (Ruby Asterisk Gateway
Interface). I use this program inside the handlers directory which is
the controller for RAGI.
The following is my program:
Code : - fold - unfold
1. #ivr_handler.rb
2.
3. require ''rubygems''
4. require ''active_record''
5. require ''ragi/call_handler''
6. require ''ragi/call_connection''
7. require ''action_controller''
8.
9. class IvrHandler < RAGI::CallHandler
10.
11. def dialout(arg,id)
12. @params = {}
13. #place_call(phoneNumber, callerID, urn, hashData, callDate,
uniqueID, maxRetries, retryTime, waitTime, extraChannelVars)
14. @params[:id] = id
15.
RAGI::CallInitiate.place_call(arg,''naveen'',''/ivr/speak'',@params[:id],nil,''5'',''0'',''1'',''90'',''1'')
16. @usermaster = Usermaster.find(id)
17. @usermaster.ivr_status = 1
18. @usermaster.save
19. puts ''title from the table usermaster ---------dailout
-------''+@usermaster.Title.to_s
20.
21. end
22.
23. def speak
24. count = 0
25. flag = true
26. msgr = true
27. while (flag == true)
28.
29. if msgr == true
30. puts ''This is naveen from the asterisk group.''
31. speak_text ("Hi , This is a reminder on your appointment with
Dr. John on wednesday 23rd of August")
32. play_sound ("beep")
33. end
34.
35.
36. speak_text ("To confirm your appointment, Press 1. To request
for reschedule, Press 3. To replay the message from begining, Press 9")
37. keypresses = get_data("beep",5000,1)
38. puts (''ekyeie
----------------------------------''+keypresses.to_s)
39. if (keypresses == "1")
40. speak_text ''Your appointment is confirmed. Have a
goodday.''
41. break
42. elsif (keypresses == "3")
43. speak_text ''Doctors office will get in touch with you
shortly''
44. break
45. end
46. end
47. flag =false
48. end
49.
50. end
I call the method speak from the asterisk pbx configuration file by
giving the url direction.
usermasters is the table i created in the database and generated a
usermaster.rb model file in the models directory. I use another program
in the lib directory to get the values from database. It is shown below:
Code : - fold - unfold
1. require "rubygems"
2.
3. require "active_record"
4.
5. require "../app/handlers/ivr_handler"
6. # accessing the database.yml file which is located in config
folder
7.
8. db_config = YAML::load(File.open("../config/database.yml"))
9.
10. # accessing the database configuration in development mode using
database.yml file
11.
ActiveRecord::Base.establish_connection(db_config[''development''])
12.
13. # access the data using model in app/models
14. require "../app/models/usermaster"
15.
16. # substracting n number of days from current date
17.
18. #date = DateTime.now - 3
19.
20. # finding users created on the above date
21. @users = Usermaster.find(:all,:conditions
=>["ivr_status=?","0"])
22.
23. # creating object for ivrhandler
24. ivr_obj = IvrHandler.new
25.
26. # iterating each user in users table
27. @users.each do |user|
28. # passing phone_number to dialout method in ivrhandler class
29.
30. ivr_obj.dialout(user.contact_number.to_s,user.id)
31. end
I hope this explanation is more clear enough to you. Please suggest me
now how will the speak method get the id from usermaster table. Iam
already passing the value of id to dialout method, you can see that in
the ivr_handler.rb file.
Thanks and appreciate your response.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---