-
Notifications
You must be signed in to change notification settings - Fork 9
/
agi-IVR_recording_verification.agi
executable file
·816 lines (698 loc) · 24.8 KB
/
agi-IVR_recording_verification.agi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
#!/usr/bin/perl
#
# agi-IVR_recording_verification.agi version 2.6
#
# This script is designed to function as a complete automated 3rd party
# verification IVR recording system. This script will work by optionally asking
# for a company ID and/or a customer phone number, then it will play through the
# listed prompts asking for a single digit press (i.e. 1 for a yes or a 3 for a
# no, hash/pound/star/zero/0 are not accepted only 1-9 is valid for these steps).
# All data for these calls will be logged to the vicidial_ivr table as well as
# optionally to a log file in the standard astguiclient log file directory
# and/or STDERR output on the asterisk process. This script uses the
# /etc/astguiclient.conf file for database connection settings, logging data and
# for logfile path information only.
#
# With a modified VDAD agi transfer script, this script could also be used to do
# automated outbound surveys as well. Feature under development.
#
# ; 1. the DNIS or inbound number called
# ; 2. play the recording ID (Y|N) with prompt leading up to it
# ; 3. record this call(Y|N)
# ; 4. ask for a company code(Y|N) with the number of digits in that company code and the prompt
# ; 5. ask for a user code(Y|N) with the number of digits in that user code and the prompt
# ; 6. ask for the customer phone number(Y|N) with the number of digits in that phone number and the prompt (Y-10-85100001)
# ; 7. speak the current date (Y|N) with prompt announcing the date
# ; 8. a dash-delimited list of prompts that expect responses(85100002-85100003)
# ; 9. a "your recording ID is..." prompt (85100004)
# ; 10. logging/output (FILE|STDERR|BOTH|NONE)
#
# ;inbound IVR call:
#exten => 1234,1,Ringing ; call ringing
#exten => 1234,2,Wait(1) ; Wait 1 second for CID delivery from PRI
#exten => 1234,3,Answer ; Answer the line
#exten => 1234,4,AGI(agi-IVR_recording_verification.agi,7274506620---Y-85100004---Y---Y-1-85100016---N---N---Y-85100007---85100009-600--85100012-30--85100013---85100004---BOTH)
#exten => 1234,5,Hangup
#
# ;inbound IVR call from a VICIDIAL transfer:
#exten => _83002*.,1,Ringing ; call ringing
#exten => _83002*.,2,Wait(1) ; Wait 1 second for CID delivery
#exten => _83002*.,3,Answer ; Answer the line
#exten => _83002*.,4,AGI(agi-IVR_recording_verification.agi,7275551234---N---Y---N---N---Y-10-85100001---N---85100002-85100003---85100004---BOTH)
#exten => _83002*.,5,Hangup
#
#
# Copyright (C) 2013 Matt Florell <[email protected]> LICENSE: AGPLv2
#
# CHANGELOG
# 70912-1105 - First build, non-functional
# 70916-2331 - functional alpha version, reads all prompts and logs data, no recording yet
# 70921-1110 - full beta version with recording working
# 71028-1122 - added say datetime as an option
# 71112-0238 - added prompt delays and date announcement message
# 71120-1337 - added playing of recording ID at beginning of session
# 120430-2214 - Converted call to Monitor app to be asterisk 1.8 compatible
# 130108-1816 - Changes for Asterisk 1.8 compatibility
#
&get_time_now;
$start_epoch = $now_date_epoch;
$script = 'agi-IVR_recording_verification.agi';
$now_date_epoch = time();
$now_date = "$year-$mon-$mday $hour:$min:$sec";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$hour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$US='_';
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
if (!$VARDB_port) {$VARDB_port='3306';}
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/ivrout.$year-$mon-$mday";}
use DBI;
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$stmtA = "SELECT agi_output,ext_context,asterisk_version FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
$AGILOG = '0';
@aryA = $sthA->fetchrow_array;
$DBagi_output = $aryA[0];
$ext_context = $aryA[1];
$asterisk_version = $aryA[2];
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
$rec_count++;
}
$sthA->finish();
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
if ($ARGV[0] =~ /---/)
{
### list of command-line array arguments:
@ARGV_vars = split(/---/, $ARGV[0]);
$inbound_number = $ARGV_vars[0];
$play_ID = $ARGV_vars[1];
$record_call = $ARGV_vars[2];
$company_ID_ask = $ARGV_vars[3];
$user_ID_ask = $ARGV_vars[4];
$cust_phone_ask = $ARGV_vars[5];
$say_date = $ARGV_vars[6];
$prompts = $ARGV_vars[7];
$last_prompt = $ARGV_vars[8];
$AGI_output = $ARGV_vars[9];
@prompts_list = split(/-/, $prompts);
$prompts_count = $#prompts_list;
if ($play_ID =~ /Y/)
{
@play_IDary = split(/-/, $play_ID);
$play_ID_prompt = $play_IDary[1];
}
if ($company_ID_ask =~ /Y/)
{
@company_ID = split(/-/, $company_ID_ask);
$company_ID_length = $company_ID[1];
$company_ID_prompt = $company_ID[2];
}
if ($user_ID_ask =~ /Y/)
{
@user_ID = split(/-/, $user_ID_ask);
$user_ID_length = $user_ID[1];
$user_ID_prompt = $user_ID[2];
}
if ($cust_phone_ask =~ /Y/)
{
@cust_phone_ID = split(/-/, $cust_phone_ask);
$cust_phone_length = $cust_phone_ID[1];
$cust_phone_prompt = $cust_phone_ID[2];
}
if ($say_date =~ /Y/)
{
@say_date_ID = split(/-/, $say_date);
$say_date_prompt = $say_date_ID[1];
}
if ($AGI_output =~ /STDERR/) {$AGILOG = '1';}
if ($AGI_output =~ /FILE/) {$AGILOG = '2';}
if ($AGI_output =~ /BOTH/) {$AGILOG = '3';}
}
}
$|=1;
while(<STDIN>)
{
chomp;
last unless length($_);
if ($V)
{
if (/^agi_(\w+)\:\s+(.*)$/)
{
$AGI{$1} = $2;
}
}
if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1;}
if (/^agi_extension\:\s+(.*)$/) {$extension = $1;}
if (/^agi_channel\:\s+(.*)$/) {$channel = $1;}
if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;}
if (/^agi_calleridname\:\s+(.*)$/) {$calleridname = $1;}
}
if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) )
{
$calleridname = $callerid;
$calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi;
$calleridname =~ s/\"|\" //gi;
}
$callerid =~ s/\D//gi;
$calleridname =~ s/unknown//gi;
if ( (!$callerid) or ($callerid =~ /unknown/) )
{$callerid = $calleridname;}
$phone_number=$callerid;
### allow for VICIDIAL transfer data string "83002*3125551212*10000123*TESTCAMP*ABC*1234*"
if ($extension =~ /^832\d\d\*|^833\d\d\*/)
{
@EXT_vars = split(/\*/, $extension);
$referring_extension = $EXT_vars[0]; # initial extension sent
$phone_number = $EXT_vars[1]; # phone number
$lead_id = $EXT_vars[2]; # lead_id in vicidial_list
$campaign_id = $EXT_vars[3]; # campaign id
$product_code = $EXT_vars[4]; # product code
$user = $EXT_vars[5]; # vicidial_user that sent the call here
}
### table structure for data ###
# CREATE TABLE vicidial_ivr (
# ivr_id INT(9) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
# entry_time DATETIME,
# length_in_sec SMALLINT(5) UNSIGNED default '0',
# inbound_number VARCHAR(12),
# recording_id INT(9) UNSIGNED,
# recording_filename VARCHAR(50),
# company_id VARCHAR(12),
# phone_number VARCHAR(12),
# lead_id INT(9) UNSIGNED,
# campaign_id VARCHAR(20),
# product_code VARCHAR(20),
# user VARCHAR(20),
# prompt_audio_1 VARCHAR(20),
# prompt_response_1 TINYINT(1) UNSIGNED default '0',
# prompt_audio_2 VARCHAR(20),
# prompt_response_2 TINYINT(1) UNSIGNED default '0',
# prompt_audio_3 VARCHAR(20),
# prompt_response_3 TINYINT(1) UNSIGNED default '0',
# prompt_audio_4 VARCHAR(20),
# prompt_response_4 TINYINT(1) UNSIGNED default '0',
# prompt_audio_5 VARCHAR(20),
# prompt_response_5 TINYINT(1) UNSIGNED default '0',
# prompt_audio_6 VARCHAR(20),
# prompt_response_6 TINYINT(1) UNSIGNED default '0',
# prompt_audio_7 VARCHAR(20),
# prompt_response_7 TINYINT(1) UNSIGNED default '0',
# prompt_audio_8 VARCHAR(20),
# prompt_response_8 TINYINT(1) UNSIGNED default '0',
# prompt_audio_9 VARCHAR(20),
# prompt_response_9 TINYINT(1) UNSIGNED default '0',
# prompt_audio_10 VARCHAR(20),
# prompt_response_10 TINYINT(1) UNSIGNED default '0',
# prompt_audio_11 VARCHAR(20),
# prompt_response_11 TINYINT(1) UNSIGNED default '0',
# prompt_audio_12 VARCHAR(20),
# prompt_response_12 TINYINT(1) UNSIGNED default '0',
# prompt_audio_13 VARCHAR(20),
# prompt_response_13 TINYINT(1) UNSIGNED default '0',
# prompt_audio_14 VARCHAR(20),
# prompt_response_14 TINYINT(1) UNSIGNED default '0',
# prompt_audio_15 VARCHAR(20),
# prompt_response_15 TINYINT(1) UNSIGNED default '0',
# prompt_audio_16 VARCHAR(20),
# prompt_response_16 TINYINT(1) UNSIGNED default '0',
# prompt_audio_17 VARCHAR(20),
# prompt_response_17 TINYINT(1) UNSIGNED default '0',
# prompt_audio_18 VARCHAR(20),
# prompt_response_18 TINYINT(1) UNSIGNED default '0',
# prompt_audio_19 VARCHAR(20),
# prompt_response_19 TINYINT(1) UNSIGNED default '0',
# prompt_audio_20 VARCHAR(20),
# prompt_response_20 TINYINT(1) UNSIGNED default '0',
# index (phone_number),
# index (entry_time)
# );
### insert record into vicidial_ivr table ###
$stmtA = "INSERT INTO vicidial_ivr (entry_time,length_in_sec,inbound_number,phone_number,lead_id,campaign_id,product_code,user) values('$now_date','0','$inbound_number','$phone_number','$lead_id','$campaign_id','$product_code','$user');";
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$ivr_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
if ($AGILOG) {$agi_string = "IVR START- $ivr_id $inbound_number|$record_call|$company_ID_ask|$cust_phone_ask|$prompts|$last_prompt|$AGI_output"; &agi_output;}
$AGI->stream_file('beep');
### if set to play ID at beginning of session ###
if ($play_ID =~ /Y/)
{
$AGI->stream_file("$play_ID_prompt");
$AGI->say_digits("$ivr_id");
sleep(1);
$AGI->stream_file('beep');
$AGI->say_digits("$ivr_id");
sleep(1);
}
### if set to ask for company ID, run that subroutine ###
if ($company_ID_ask =~ /Y/)
{
&company_ID_gather_response;
$company_ID = $totalDTMF;
&get_time_now;
$length_in_sec = ($now_date_epoch - $start_epoch);
$stmtA = "UPDATE vicidial_ivr SET company_id='$company_ID', length_in_sec='$length_in_sec' where ivr_id='$ivr_id';";
if ($AGILOG) {$agi_string = "IVR- $ivr_id company: $company_ID length: $length_in_sec"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
}
### if set to ask for user ID, run that subroutine ###
if ($user_ID_ask =~ /Y/)
{
&user_ID_gather_response;
$user_ID = $totalDTMF;
&get_time_now;
$length_in_sec = ($now_date_epoch - $start_epoch);
$stmtA = "UPDATE vicidial_ivr SET user='$user_ID', length_in_sec='$length_in_sec' where ivr_id='$ivr_id';";
if ($AGILOG) {$agi_string = "IVR- $ivr_id user: $user_ID length: $length_in_sec"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
}
### if set to ask for customer phone number, run that subroutine ###
if ($cust_phone_ask =~ /Y/)
{
&cust_phone_gather_response;
$phone_number = $totalDTMF;
&get_time_now;
$length_in_sec = ($now_date_epoch - $start_epoch);
$stmtA = "UPDATE vicidial_ivr SET phone_number='$phone_number', length_in_sec='$length_in_sec' where ivr_id='$ivr_id';";
if ($AGILOG) {$agi_string = "IVR- $ivr_id phone: $phone_number length: $length_in_sec"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
}
### if set to record this session, start recording ###
if ($record_call =~ /Y/)
{
#$filename = "$inbound_number$US$phone_number$US$ivr_id";
$filename = "$ivr_id";
### code to record call goes here ###
%ast_ver_str = parse_asterisk_version($asterisk_version);
if (( $ast_ver_str{major} = 1 ) && ($ast_ver_str{minor} < 6))
{
$AGI->exec("Monitor wav|/var/spool/asterisk/monitor/MIX/$filename|m");
}
else
{
$AGI->exec("Monitor","wav,/var/spool/asterisk/monitor/MIX/$filename,m");
}
### insert record into recording_log table ###
$stmtA = "INSERT INTO recording_log (channel,server_ip,extension,start_time,start_epoch,length_in_sec,filename,lead_id,user,location) values('$channel','$server_ip','$inbound_number','$now_date','start_epoch','0','$filename','$lead_id','$user','$ivr_id');";
$affected_rows = $dbhA->do($stmtA);
$cbc=0;
$stmtA = "select LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$recording_id = "$aryA[0]";
$cbc++;
}
$sthA->finish();
$stmtA = "UPDATE vicidial_ivr SET recording_id='$recording_id', recording_filename='$filename' where ivr_id='$ivr_id';";
if ($AGILOG) {$agi_string = "RECORDING- $recording_id $ivr_id START filename: $filename"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
}
### if set, say the current date ###
if ($say_date =~ /Y/)
{
if ($AGILOG) {$agi_string = "SAYING DATETIME $now_date_epoch"; &agi_output;}
if (length($say_date_prompt)>0) {$AGI->stream_file("$say_date_prompt");}
sleep(1);
$AGI->exec("SayUnixtime");
sleep(1);
}
##### Go through the propmts one at a time until done #####
@prompts_list = split(/--/, $prompts);
$prompts_count = $#prompts_list;
$i=0;
$j=1;
while($prompts_count >= $i)
{
$prompt_ary = $prompts_list[$i];
@prompts_specs = split(/-/, $prompt_ary);
$prompt = $prompts_specs[0];
$wait_sec = $prompts_specs[1];
if ($wait_sec < 1) {$wait_sec=10;}
$response = '';
$prompt_name = "prompt_audio_$j";
$response_name = "prompt_response_$j";
sleep(1);
&prompt_gather_response;
$response = $totalDTMF;
&get_time_now;
$length_in_sec = ($now_date_epoch - $start_epoch);
$stmtA = "UPDATE vicidial_ivr SET $prompt_name='$prompt', $response_name='$response', length_in_sec='$length_in_sec' where ivr_id='$ivr_id';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "IVR- $ivr_id $i prompt: $prompt - $wait_sec response: $response length: $length_in_sec"; &agi_output;}
$i++;
$j++;
}
##### Play the last prompt and say the IVR number #####
$AGI->stream_file("$last_prompt");
$AGI->say_digits("$ivr_id");
&get_time_now;
$length_in_sec = ($now_date_epoch - $start_epoch);
$stmtA = "UPDATE vicidial_ivr SET length_in_sec='$length_in_sec' where ivr_id='$ivr_id';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "IVR- $ivr_id END prompt: $last_prompt length: $length_in_sec"; &agi_output;}
if ($record_call =~ /Y/)
{
$stmtA = "UPDATE recording_log SET length_in_sec='$length_in_sec' where recording_id='$recording_id';";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$affected_rows = $dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "RECORDING- $recording_id length: $length_in_sec"; &agi_output;}
}
sleep(1);
$AGI->stream_file('beep');
$AGI->say_digits("$ivr_id");
sleep(1);
$AGI->stream_file('vm-goodbye');
if ($AGILOG) {$agi_string = "IVR- ID: $ivr_id DONE Exiting"; &agi_output;}
exit;
################################################################################
##### SUBROUTINES ##############################################################
################################################################################
##### BEGIN collect the company ID #############################################
sub company_ID_gather_response
{
$digit='';
$interrupt_digit='';
$interrupt_digit = $AGI->stream_file("$company_ID_prompt",'1234567890');
print STDERR "interrupt_digit |$interrupt_digit|\n";
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
if ($interrupt_digit > 1)
{
# if ($interrupt_digit == 35) {$interrupt_digit='#';}
# if ($interrupt_digit == 42) {$interrupt_digit='*';}
if ($interrupt_digit == 48) {$interrupt_digit=0;}
if ($interrupt_digit == 49) {$interrupt_digit=1;}
if ($interrupt_digit == 50) {$interrupt_digit=2;}
if ($interrupt_digit == 51) {$interrupt_digit=3;}
if ($interrupt_digit == 52) {$interrupt_digit=4;}
if ($interrupt_digit == 53) {$interrupt_digit=5;}
if ($interrupt_digit == 54) {$interrupt_digit=6;}
if ($interrupt_digit == 55) {$interrupt_digit=7;}
if ($interrupt_digit == 56) {$interrupt_digit=8;}
if ($interrupt_digit == 57) {$interrupt_digit=9;}
$totalDTMF=$interrupt_digit;
$digit_loop_counter++;
}
while ($digit_loop_counter < $company_ID_length)
{
$digit = chr($AGI->wait_for_digit('100000')); # wait 100 seconds for input
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
# $AGI->say_digits("$digit");
undef $digit;
}
else
{
$digit_loop_counter=$company_ID_length;
}
$digit_loop_counter++;
}
}
##### END collect the company ID ###############################################
##### BEGIN collect the user ID ################################################
sub user_ID_gather_response
{
$digit='';
$interrupt_digit='';
$interrupt_digit = $AGI->stream_file("$user_ID_prompt",'1234567890');
print STDERR "interrupt_digit |$interrupt_digit|\n";
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
if ($interrupt_digit > 1)
{
# if ($interrupt_digit == 35) {$interrupt_digit='#';}
# if ($interrupt_digit == 42) {$interrupt_digit='*';}
if ($interrupt_digit == 48) {$interrupt_digit=0;}
if ($interrupt_digit == 49) {$interrupt_digit=1;}
if ($interrupt_digit == 50) {$interrupt_digit=2;}
if ($interrupt_digit == 51) {$interrupt_digit=3;}
if ($interrupt_digit == 52) {$interrupt_digit=4;}
if ($interrupt_digit == 53) {$interrupt_digit=5;}
if ($interrupt_digit == 54) {$interrupt_digit=6;}
if ($interrupt_digit == 55) {$interrupt_digit=7;}
if ($interrupt_digit == 56) {$interrupt_digit=8;}
if ($interrupt_digit == 57) {$interrupt_digit=9;}
$totalDTMF=$interrupt_digit;
$digit_loop_counter++;
}
while ($digit_loop_counter < $user_ID_length)
{
$digit = chr($AGI->wait_for_digit('100000')); # wait 100 seconds for input
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
# $AGI->say_digits("$digit");
undef $digit;
}
else
{
$digit_loop_counter=$user_ID_length;
}
$digit_loop_counter++;
}
}
##### END collect the user ID ##################################################
##### BEGIN collect the customer phone number ##################################
sub cust_phone_gather_response
{
$digit='';
$interrupt_digit='';
$interrupt_digit = $AGI->stream_file("$cust_phone_prompt",'1234567890');
print STDERR "interrupt_digit |$interrupt_digit|\n";
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
if ($interrupt_digit > 1)
{
if ($interrupt_digit == 48) {$interrupt_digit=0;}
if ($interrupt_digit == 49) {$interrupt_digit=1;}
if ($interrupt_digit == 50) {$interrupt_digit=2;}
if ($interrupt_digit == 51) {$interrupt_digit=3;}
if ($interrupt_digit == 52) {$interrupt_digit=4;}
if ($interrupt_digit == 53) {$interrupt_digit=5;}
if ($interrupt_digit == 54) {$interrupt_digit=6;}
if ($interrupt_digit == 55) {$interrupt_digit=7;}
if ($interrupt_digit == 56) {$interrupt_digit=8;}
if ($interrupt_digit == 57) {$interrupt_digit=9;}
$totalDTMF=$interrupt_digit;
$digit_loop_counter++;
}
while ($digit_loop_counter < $cust_phone_length)
{
$digit = chr($AGI->wait_for_digit('100000')); # wait 100 seconds for input
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
# $AGI->say_digits("$digit");
undef $digit;
}
else
{
$digit_loop_counter=$cust_phone_length;
}
$digit_loop_counter++;
}
}
##### END collect the customer phone number ####################################
##### BEGIN collect the response to a prompt ###################################
sub prompt_gather_response
{
$digit='';
$interrupt_digit='';
$interrupt_digit = $AGI->stream_file("$prompt",'123456789');
print STDERR "interrupt_digit |$interrupt_digit|\n";
$digits_being_entered=1;
$digit_loop_counter=0;
$totalDTMF='';
if ($interrupt_digit > 1)
{
# if ($interrupt_digit == 48) {$interrupt_digit=0;}
if ($interrupt_digit == 49) {$interrupt_digit=1;}
if ($interrupt_digit == 50) {$interrupt_digit=2;}
if ($interrupt_digit == 51) {$interrupt_digit=3;}
if ($interrupt_digit == 52) {$interrupt_digit=4;}
if ($interrupt_digit == 53) {$interrupt_digit=5;}
if ($interrupt_digit == 54) {$interrupt_digit=6;}
if ($interrupt_digit == 55) {$interrupt_digit=7;}
if ($interrupt_digit == 56) {$interrupt_digit=8;}
if ($interrupt_digit == 57) {$interrupt_digit=9;}
$totalDTMF=$interrupt_digit;
$digit_loop_counter++;
}
while ($digit_loop_counter < 1)
{
$wait_ms = ($wait_sec * 1000);
$digit = chr($AGI->wait_for_digit("$wait_ms")); # wait number of milli-seconds for input
if ($digit =~ /\d/)
{
$totalDTMF = "$totalDTMF$digit";
print STDERR "digit |$digit| TotalDTMF |$totalDTMF|\n";
# $AGI->say_digits("$digit");
undef $digit;
}
else
{
$digit_loop_counter=-1;
}
$digit_loop_counter++;
}
}
##### END collect the response to a prompt #####################################
sub get_time_now #get the current date and time and epoch for logging call lengths and datetimes
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$hour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$now_date_epoch = time();
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$filedate = "$year$mon$mday$hour$min$sec";
}
sub checkresult
{
my ($res) = @_;
my $retval;
$tests++;
chomp $res;
if ($res =~ /^200/)
{
$res =~ /result=(-?\d+)/;
if (!length($1))
{
print STDERR "FAIL ($res)\n";
$fail++;
}
else
{
print STDERR "PASS ($1)\n";
$pass++;
}
}
else
{
print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}
sub agi_output
{
if ($AGILOG >=2)
{
### open the log file for writing ###
open(Lout, ">>$AGILOGfile")
|| die "Can't open $AGILOGfile: $!\n";
print Lout "$now_date|$script|$agi_string\n";
close(Lout);
}
### send to STDERR writing ###
if ( ($AGILOG == '1') || ($AGILOG == '3') )
{print STDERR "$now_date|$script|$agi_string\n";}
$agi_string='';
}
# subroutine to parse the asterisk version
# and return a hash with the various part
sub parse_asterisk_version
{
# grab the arguments
my $ast_ver_str = $_[0];
# get everything after the - and put it in $ast_ver_postfix
my @hyphen_parts = split( /-/ , $ast_ver_str );
my $ast_ver_postfix = $hyphen_parts[1];
# now split everything before the - up by the .
my @dot_parts = split( /\./ , $hyphen_parts[0] );
my %ast_ver_hash;
if ( $dot_parts[0] <= 1 )
{
%ast_ver_hash = (
"major" => $dot_parts[0],
"minor" => $dot_parts[1],
"build" => $dot_parts[2],
"revision" => $dot_parts[3],
"postfix" => $ast_ver_postfix
);
}
# digium dropped the 1 from asterisk 10 but we still need it
if ( $dot_parts[0] > 1 )
{
%ast_ver_hash = (
"major" => 1,
"minor" => $dot_parts[0],
"build" => $dot_parts[1],
"revision" => $dot_parts[2],
"postfix" => $ast_ver_postfix
);
}
return ( %ast_ver_hash );
}