-
Notifications
You must be signed in to change notification settings - Fork 0
/
voicemail.cgi
executable file
·72 lines (55 loc) · 1.73 KB
/
voicemail.cgi
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
#!/usr/bin/perl
# vi:set ai sw=4 ts=4:
use CGI;
use Text::Wrap;
use strict;
use warnings;
sub rmwhite {
my $string = shift;
$string =~ s/^\s+//gm;
return $string;
}
my $q = new CGI;
# These paramaters appear in both Recordings and Transcripts
my $RecordingUrl = $q->param("RecordingUrl");
my $RecordingSid = $q->param("RecordingSid");
my $Caller = $q->param("Caller");
# These appear only in Recordings
my $RecordingDuration = $q->param("RecordingDuration");
my $CallerCity = $q->param("CallerCity");
my $CallerState = $q->param("CallerState");
my $CallerZip = $q->param("CallerZip");
# These appear only in Transcripts
my $TranscriptionStatus = $q->param("TranscriptionStatus");
my $TranscriptionSid = $q->param("TranscriptionSid");
my $TranscriptionText = $q->param("TranscriptionText");
exit if $TranscriptionStatus and $TranscriptionStatus ne "completed";
$TranscriptionText = wrap("> ", "> ", $TranscriptionText) if $TranscriptionText;
open my $fd, "| /usr/sbin/sendmail -oi -t -fmct"
or die "fork: $!";
print $fd rmwhite <<" EOT";
From: Voicemail <admin\@noisetor.net>
Subject: New voicemail from $Caller
To: admin\@noisetor.net
EOT
unless ($TranscriptionSid) {
print $fd rmwhite <<" EOT";
Message-Id: <$RecordingSid\@voicemail.noisetor.net>
You have a new $RecordingDuration second long voicemail from $Caller ($CallerCity, $CallerState $CallerZip):
$RecordingUrl
EOT
}
else {
print $fd rmwhite <<" EOT";
Message-Id: <$TranscriptionSid\@voicemail.noisetor.net>
References: <$RecordingSid\@voicemail.noisetor.net>
Transcript of previously sent voicemail <$RecordingUrl>:
$TranscriptionText
EOT
}
print $q->header, rmwhite <<" EOT";
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Hangup/>
</Response>
EOT