Author Topic: Fax issue  (Read 9196 times)

iKenny

  • Newbie
  • *
  • Posts: 18
    • View Profile
Fax issue
« on: April 25, 2013, 12:58:32 PM »
Hi, i am tryind to receive a fax with yate.
I use a script from https://github.com/shimaore/yate/blob/master/share/scripts/detector.php
I am iniciating a fax with pbxassist.
For example, in my regexroute are route
^964$=external/nodata/fax.php;called=${caller};
I use fax.php to iniciate fax receiving and detector.php
to write it into a file. The problem is, that in detector.php
filename consist of billid, called and called, but when it writes
a file it writes in form billid caller caller

For example, i make a call from extension 022768482 to 022244340
I make one change in detector.php i v added a print of $num varueble.

My pbxassist transfer trigger:
[transfer]
; blind transfer: make call on behalf of peer, hangup this
; key: *1nnnnn*
trigger=\*1\([0-9]\+\)\#$
target=\1
;trigger=*3\([0-9]\+\)\*$
;target=\1
First time script detects correctly, but after it detect both as caller.
I tryed regexroute with ^964$=external/nodata/fax.php
but it returns, that there is no called after making a transfer

<ExtModReceiver:WARN> Error: 'NUM 1366916013-1_022768482-022244340'
<pbxassist:CALL> Created assistant for 'sip/2'
<NOTE> Choosing started 'audio' format 'mulaw' [0x1959c1a0]
<sip:MILD> No formats for 'video', excluding from SDP [0x1958cff0]
<NOTE> Choosing started 'audio' format 'mulaw' [0x19591490]
<yrtp:WARN> Wrapper neither format nor payload specified [0x195ab360]
<pbxassist:NOTE> Chan 'sip/2' triggered operation 'transfer' in state 'new' holding '(null)'
<ExtModReceiver:WARN> Error: 'NUM 1366916013-1_022768482-964'

And log with ^964$=external/nodata/fax.php;called=${caller};

<pbxassist:CALL> Created assistant for 'sip/9'
Starting detection on sip/9
<ExtModReceiver:WARN> Error: 'NUM 1366913760-5_022768482-022244340'
<pbxassist:NOTE> Channel 'sip/9' already assisted!
<pbxassist:CALL> Created assistant for 'sip/10'
<NOTE> Choosing started 'audio' format 'mulaw' [0x116aac50]
<sip:MILD> No formats for 'video', excluding from SDP [0x116ae040]
<NOTE> Choosing started 'audio' format 'mulaw' [0x116baa70]
<yrtp:WARN> Wrapper neither format nor payload specified [0x116b17b0]
<sip:NOTE> Registered user '022768482' expires in 120 s
<pbxassist:NOTE> Chan 'sip/10' triggered operation 'transfer' in state 'new' holding '(null)'
Starting detection on sip/9
<ExtModReceiver:WARN> Error: 'NUM 1366913760-5_022768482-022768482'
PHP Installed: call.execute
PHP Answered: call.answered id: 1115985716517973d1de1b56.84525410
PHP: bye! Fax PHP

And here is fax.php

#!/usr/bin/php -q
<?php
/* Simple Fax2Mail Skript for the Yate PHP interface
   To test add in regexroute.conf

   ^NNN$=external/nodata/fax.php

   where NNN is the number you want to assign
*/
require_once("libyate.php");

/* Always the first action to do */
Yate::Init();
Yate::Debug(true);

date_default_timezone_set('Europe/Chisinau');

//$faxfile     = '/var/spool/fax/' . 'rx-file-' . date("Ymd_His") . '.tiff';
$faxfile     = '/var/spool/fax/rx-file-123.tiff';
$ourcallid   = 'fax/' . uniqid(rand(),1);
$partycallid = '';
$state       = 'call';

Yate::Install("call.execute",100);

/* The main loop. We pick events and handle them */
while ($state != "") {
    $ev=Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false)
        break;
    /* Empty events are normal in non-blocking operation.
       This is an opportunity to do idle tasks and check timers */
    if ($ev === true)
        continue;
    /* If we reached here we should have a valid object */
    switch ($ev->type) {
        case "incoming":
            switch ($ev->name) {
                case "call.execute":
                    $partycallid = $ev->params["id"];
                    $ev->params["targetid"] = $ourcallid;
                    $ev->handled = true;
                    // we must ACK this message before dispatching a call.answered
                    $ev->Acknowledge();
                    // we already ACKed this message
                    $ev = false;

                    $m = new Yate("call.answered");
                    $m->params["id"] = $ourcallid;
                    $m->params["targetid"] = $partycallid;
                    $m->Dispatch();

                    $m = new Yate("chan.attach");
                    $m->params["id"] = $ourcallid;
//                  $m->params["source"] = "wave/play//usr/share/yate/sounds/fax2mail/dialtone.sln";
                    //$m->params["source"] = "wave/play//usr/local/share/yate/sounds/ring.au";
                                        $m->params["source"] = "wave/play//home/rec.slin";

                    $m->id = ""; // don't notify about message result
                    $m->params["sniffer"] = "tone/*";
                    $m->params["fax_divert"] = 'fax/receive//' . $faxfile;
                                        //$m->params["fax_divert"] = 'fax/receive/var/spool/fax/rx-file-123.tiff';
                    $m->Dispatch();
                    //Yate::Output("PHP Incoming: call.execute id: " . $ev->id);

                    break;
                default:
                    Yate::Output("PHP Incoming: " . $ev->name . " id: " . $ev->id);
            }
            /* This is extremely important.
               We MUST let messages return, handled or not */
            if ($ev)
                $ev->Acknowledge();
            break;
        case "answer":
            Yate::Output("PHP Answered: " . $ev->name . " id: " . $ev->id);
            break;
        case "installed":
            Yate::Output("PHP Installed: " . $ev->name);
            break;
        case "uninstalled":
            Yate::Output("PHP Uninstalled: " . $ev->name);
            break;
        default:
            Yate::Output("PHP Event: " . $ev->type . $ev->name);
    }
}

Yate::Output("PHP: bye! Fax PHP");

/* vi: set ts=8 sw=4 sts=4 noet: */
?>