[Freeswitch-users] [Freeswitch-dev] How to check the "fax_result_code" in the script? such as php script?
Nathan Neulinger
nneul at mst.edu
Tue Apr 15 16:48:53 MSD 2014
Can't help you on the PHP side, but I do this with sending a fax with perl based web page. If you're wanting to do it
inline, I think you'd have to listen for events as you've described...
...
push( @args, "fax_notify_address='" . $ENV{REMOTE_USER} . "\@mst.edu'" );
push( @args, "api_hangup_hook='perl /local/freeswitch/bin/notify-fax-status-hook.pl'" );
...
and then the attached script.
Key parts:
our $env;
our $session;
my $addr = $session->getVariable("fax_notify_address");
my $to = $session->getVariable("destination_number");
...
my $fax_status = $session->getVariable("fax_success");
my $status_msg = "Sent OK";
if ( $fax_status != 1 ) {
$status_msg = "Failed";
}
my $result = $session->getVariable("fax_result_text");
On 04/15/2014 01:00 AM, sparklezou wrote:
> Hi All,
> I checked and find two possible solution. But still NOT clear.
> 1. Run "fs_cli" in PHP script. But NOT find to correct command to show the channel variables. Nor the data for Mod_spandsp.
> https://wiki.freeswitch.org/wiki/Fs_cli#Simple
> 2. get info from "Mod event socket". But still NOT very clear how to get the Mod_spandsp event.
> https://wiki.freeswitch.org/wiki/Mod_event_socket#api
> https://wiki.freeswitch.org/wiki/Event_Socket_Library#events
> https://wiki.freeswitch.org/wiki/Event_List#Event-Name
> https://wiki.freeswitch.org/wiki/Mod_spandsp
> Please share your idea, how to handle such issue?
> Hope there is direct way to get the result code, then it will be easy to handle fax step in the script.
> Thanks!
> 2014-04-15
> ------------------------------------------------------------------------------------------------------------------------
> sparklezou
> ------------------------------------------------------------------------------------------------------------------------
> *发件人:*Michael Jerris <mike at jerris.com>
> *发送时间:*2014-04-14 20:08
> *主题:*Re: [Freeswitch-users] How to check the "fax_result_code" in the script? such as php script?
> *收件人:*"FreeSWITCH Users Help"<freeswitch-users at lists.freeswitch.org>
> *抄送:*
> you could use an api hangup hook, or possibly do it in cdr processing.
>
> On Apr 10, 2014, at 10:39 PM, sparklezou <sparklezou at 163.com <mailto:sparklezou at 163.com>> wrote:
>
>> Hi Buddies,
>> Reviewed the wiki,https://wiki.freeswitch.org/wiki/Mod_spandsp
>> How to check the "fax_result_code" in the php script?
>> Also other result info, such as*fax_result_text,*then could provide more detail response info to the client.
>> Thanks!
>> 2014-03-03
>> ------------------------------------------------------------------------------------------------------------------------
>> sparklezou
>> _________________________________________________________________________
>
>
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
>
>
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-dev mailing list
> FreeSWITCH-dev at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev
> http://www.freeswitch.org
>
--
------------------------------------------------------------
Nathan Neulinger nneul at mst.edu
Missouri S&T Information Technology (573) 612-1412
System Administrator - Architect
-------------- next part --------------
#!/usr/bin/perl
use strict;
use MIME::Lite;
require "/local/freeswitch/bin/hook-libs.pl";
our $env;
our $session;
my $addr = $session->getVariable("fax_notify_address");
my $to = $session->getVariable("destination_number");
my $from = $session->getVariable("caller_id_number");
my $fromname = $session->getVariable("caller_id_name");
my $debug = 0;
if ($debug) {
my $sid = $session->getVariable("session_id");
if ( int($sid) eq $sid ) {
open( my $out, "|sort > /tmp/notify-${sid}.txt" );
print $out $env->serialize;
close($out);
}
}
my $direction = $session->getVariable("direction");
my $cause = $session->getVariable("hangup_cause");
if ( $direction eq "inbound" || $cause eq "NORMAL_UNSPECIFIED" ) {
# ignore
}
else {
my $time = scalar( localtime(time) );
my $fax_status = $session->getVariable("fax_success");
my $status_msg = "Sent OK";
if ( $fax_status != 1 ) {
$status_msg = "Failed";
}
my $result = $session->getVariable("fax_result_text");
freeswitch::console_log( "info",
"sending fax status notify ($status_msg) for call from $from to $to to address $addr\n" );
my $msg = MIME::Lite->new(
From => "freeswitch\@mst.edu",
To => $addr,
Subject => "Fax status ($status_msg) for fax to ($to) at ($time)",
Type => "multipart/mixed"
);
if ( !$result ) {
$result = "Hangup Cause (" . $session->getVariable("hangup_cause") . ")";
}
my $content = <<EOF;
Fax Message: $status_msg
Fax Result: $result
Call To: $to
Call From: $from ($fromname)
Call Time: $time
EOF
foreach my $var (
"fax_bad_rows", "fax_document_total_pages",
"fax_document_transferred_pages", "fax_ecm_requested",
"fax_ecm_used", "fax_filename",
"fax_image_resolution", "fax_image_size",
"fax_local_station_id", "fax_result_code",
"fax_result_text", "fax_remote_station_id",
"fax_success", "fax_transfer_rate",
"hangup_cause", "direction",
"loopback_leg", "channel_name"
)
{
my $tmp;
eval { $tmp = $session->getVariable($var); };
$content .= "Variable($var): " . $tmp . "\n";
freeswitch::console_log( "info", "fax status notify ($var => $tmp)\n" );
}
$msg->attach(
Type => 'TEXT',
Data => $content,
);
&stack_max();
$msg->send();
&stack_restore();
freeswitch::console_log( "info", "done sending fax status notify for call from $from to $to to address $addr\n" );
}
# Finish with a true status
1;
Join us at ClueCon 2013 Aug 6-8, 2013
More information about the FreeSWITCH-users
mailing list