IVR.pm 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package ESL::IVR;
  2. use ESL;
  3. use Data::Dumper;
  4. sub new($$) {
  5. my $proto = shift;
  6. my $class = ref($proto) || $proto;
  7. my $self = {};
  8. $self->{_esl} = new ESL::ESLconnection(fileno(STDIN));
  9. $self->{_info} = $self->{_esl}->getInfo();
  10. $self->{_uuid} = $self->{_info}->getHeader("unique-id");
  11. return bless($self, $class);
  12. }
  13. sub getHeader($;) {
  14. my $self = shift;
  15. return $self->{_info} ? $self->{_info}->getHeader(shift) : undef;
  16. }
  17. sub execute($;) {
  18. my $self = shift;
  19. return $self->{_esl}->execute(@_);
  20. }
  21. sub api($;) {
  22. my $self = shift;
  23. return $self->{_esl}->api(@_);
  24. }
  25. sub disconnect($;) {
  26. my $self = shift;
  27. return $self->{_esl}->disconnect(@_);
  28. }
  29. sub getVar($;) {
  30. my $self = shift;
  31. my ($var) = @_;
  32. my $e = $self->api("uuid_getvar", "$self->{_uuid} $var");
  33. my $input;
  34. if ($e) {
  35. $input = $e->getBody();
  36. if ($input && $input eq "_undef_") {
  37. $input = undef;
  38. }
  39. }
  40. return $input;
  41. }
  42. sub setVar($;) {
  43. my $self = shift;
  44. my ($var, $val) = @_;
  45. my $e = $self->api("uuid_setvar", "$self->{_uuid} $var $val");
  46. my $input;
  47. if ($e) {
  48. $input = $e->getBody() . "\n";
  49. if ($input eq "_undef_") {
  50. $input = undef;
  51. }
  52. }
  53. chomp $input;
  54. return $input;
  55. }
  56. sub playAndGetDigits($;) {
  57. my $self = shift;
  58. my ($min, $max, $tries, $to, $term, $file, $invalid_file, $var, $regex, $digit_timeout) = @_;
  59. if (!$self->{_esl}->connected()) {
  60. return undef;
  61. }
  62. $self->execute("play_and_get_digits", "$min $max $tries $to $term $file $invalid_file $var $regex $digit_timeout");
  63. return $self->getVar($var);
  64. }
  65. sub read($;) {
  66. my $self = shift;
  67. my ($min, $max, $file, $var, $to, $term) = @_;
  68. if (!$self->{_esl}->connected()) {
  69. return undef;
  70. }
  71. $self->execute("read", "$min $max $file $var $to $term");
  72. return $self->getVar($var);
  73. }
  74. sub playback($;) {
  75. my $self = shift;
  76. my ($file) = @_;
  77. if (!$self->{_esl}->connected()) {
  78. return undef;
  79. }
  80. $self->execute("playback", $file);
  81. return $self->getVar("playback_terminators_used");
  82. }
  83. 1;