lua_ivr.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. -- lua_ivr.lua
  2. --
  3. -- This script is virtually identical to the demo_ivr defined in conf/autoload_configs/ivr.conf.xml
  4. -- It uses the same sound files and mostly the same settings
  5. -- It is intended to be used as an example of how you can use Lua to create dynamic IVRs
  6. --
  7. -- This hash defines the main IVR menu. It is equivalent to the <menu name="demo_ivr" ... > lines in ivr.conf.xml
  8. ivr_def = {
  9. ["main"] = undef,
  10. ["name"] = "demo_ivr_lua",
  11. ["greet_long"] = "phrase:demo_ivr_main_menu",
  12. ["greet_short"] = "phrase:demo_ivr_main_menu_short",
  13. ["invalid_sound"] = "ivr/ivr-that_was_an_invalid_entry.wav",
  14. ["exit_sound"] = "voicemail/vm-goodbye.wav",
  15. ["confirm_macro"] = "",
  16. ["confirm_key"] = "",
  17. ["tts_engine"] = "flite",
  18. ["tts_voice"] = "rms",
  19. ["confirm_attempts"] = "3",
  20. ["inter_digit_timeout"] = "2000",
  21. ["digit_len"] = "4",
  22. ["timeout"] = "10000",
  23. ["max_failures"] = "3",
  24. ["max_timeouts"] = "2"
  25. }
  26. -- top is an object of class IVRMenu
  27. -- pass in all 16 args to the constructor to define a new IVRMenu object
  28. top = freeswitch.IVRMenu(
  29. ivr_def["main"],
  30. ivr_def["name"],
  31. ivr_def["greet_long"],
  32. ivr_def["greet_short"],
  33. ivr_def["invalid_sound"],
  34. ivr_def["exit_sound"],
  35. ivr_def["confirm_macro"],
  36. ivr_def["confirm_key"],
  37. ivr_def["tts_engine"],
  38. ivr_def["tts_voice"],
  39. ivr_def["confirm_attempts"],
  40. ivr_def["inter_digit_timeout"],
  41. ivr_def["digit_len"],
  42. ivr_def["timeout"],
  43. ivr_def["max_failures"],
  44. ivr_def["max_timeouts"]
  45. );
  46. -- bindAction args = action, param, digits
  47. -- The following bindAction line is the equivalent of this XML from demo_ivr in ivr.conf.xml
  48. -- <entry action="menu-exec-app" digits="2" param="transfer 9996 XML default"/>
  49. top:bindAction("menu-exec-app", "transfer 9996 XML default", "2");
  50. top:bindAction("menu-exec-app", "transfer 9999 XML default", "3");
  51. top:bindAction("menu-exec-app", "transfer 9991 XML default", "4");
  52. top:bindAction("menu-exec-app", "bridge sofia/${domain}/888@conference.freeswitch.org", "1");
  53. top:bindAction("menu-exec-app", "transfer 1234*256 enum", "5");
  54. top:bindAction("menu-sub", "demo_ivr_submenu","6");
  55. top:bindAction("menu-exec-app", "transfer $1 XML features", "/^(10[01][0-9])$/");
  56. top:bindAction("menu-top", "demo_ivr_lua","9");
  57. -- This hash defines the main IVR sub-menu. It is equivalent to the <menu name="demo_ivr_submenu" ... > lines in ivr.conf.xml
  58. ivr_sub_def = {
  59. ["main"] = undef,
  60. ["name"] = "demo_ivr_submenu_lua",
  61. ["greet_long"] = "phrase:demo_ivr_sub_menu",
  62. ["greet_short"] = "phrase:demo_ivr_main_sub_menu_short",
  63. ["invalid_sound"] = "ivr/ivr-that_was_an_invalid_entry.wav",
  64. ["exit_sound"] = "voicemail/vm-goodbye.wav",
  65. ["confirm_macro"] = "",
  66. ["confirm_key"] = "",
  67. ["tts_engine"] = "flite",
  68. ["tts_voice"] = "rms",
  69. ["confirm_attempts"] = "3",
  70. ["inter_digit_timeout"] = "2000",
  71. ["digit_len"] = "4",
  72. ["timeout"] = "15000",
  73. ["max_failures"] = "3",
  74. ["max_timeouts"] = "2"
  75. }
  76. -- sub_menu is an object of class IVRMenu
  77. -- pass in all 16 args to the constructor to define a new IVRMenu object
  78. sub_menu = freeswitch.IVRMenu(
  79. ivr_sub_def["main"],
  80. ivr_sub_def["name"],
  81. ivr_sub_def["greet_long"],
  82. ivr_sub_def["greet_short"],
  83. ivr_sub_def["invalid_sound"],
  84. ivr_sub_def["exit_sound"],
  85. ivr_sub_def["confirm_macro"],
  86. ivr_sub_def["confirm_key"],
  87. ivr_sub_def["tts_engine"],
  88. ivr_sub_def["tts_voice"],
  89. ivr_sub_def["confirm_attempts"],
  90. ivr_sub_def["inter_digit_timeout"],
  91. ivr_sub_def["digit_len"],
  92. ivr_sub_def["timeout"],
  93. ivr_sub_def["max_failures"],
  94. ivr_sub_def["max_timeouts"]
  95. );
  96. -- Bind the action "menu-top" to the * key
  97. sub_menu:bindAction("menu-top","demo_ivr_lua","*");
  98. --sub_menu:execute(session,"demo_ivr_submenu_lua");
  99. -- Run the main menu
  100. top:execute(session, "demo_ivr_lua");