Author Topic: Windows - Global Script  (Read 11706 times)

truetwc

  • Newbie
  • *
  • Posts: 3
    • View Profile
Windows - Global Script
« on: November 22, 2015, 10:09:10 AM »
I am very new to Yate and trying to create a php windows global script
since I believe that is the only type of script that will work on windows.

I have seen a former post that was trying to do the same thing:

http://forum.yate.ro/index.php?topic=401.msg1166#msg1166

It is a basic script using dumb channel to answer call and play a sound. 
The last post in that thread doesn't seem to be complete and working.
So I tried to add missing parts to get it working but still have problems.
I never seem to get past route and then execute messages.
(So I never get any chan.* message)

I think I am somehow missing getting back the dumb channel id
somewhere, but it is very confusing on where to get and add that.

I am sure with more reading through the documentation it will become clear.
But it seems the windows version differences are not always clear.
An example of how to do a global script for windows that performs like one
of the example channel scripts (voicemail, ivr, etc) would make things much clearer.

The code I have changed from the other post is below, but not working.
I put markings (***) next to comments where I changed the code.

Thank you for any info on what I may be missing or setting incorrectly.
And thanks to original poster jamie for the initial example code changes.


Code: [Select]
<?php

require_once("libyate.php");

//Start YATE
Yate::Init(true"localhost"5039"");
$eventCtr 0;

Yate::Debug(true);    
Yate::Output(true);

Yate::Install("call.route"80 );
Yate::Install("call.execute"70  );

Yate::Install("chan.notify");   //*** any priority needed other than default?

//*** added this
$ourcallid "example/" uniqid(rand(),1);
$chl_id    "";


/* The main loop. We pick events and handle them */
for (;;) {

    
$ev=Yate::GetEvent();

    
// To help see all events
    
if ($ev && $ev->name!='engine.timer' 
       
&& $ev->type!=='installed' && $ev->type!=='watched')
    {
        
Yate::Debug('   E --------' $ev->type ' -> ' $ev->name);
    };

    
/* 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) {
      
Yate::Output("PHP event: empty");
      continue;
    }

    
// Handling Functions

    /* If we reached here we should have a valid object */
    
switch ($ev->type) {

    case 
"incoming":

             
Yate::Debug'-EV-name ' $ev->name );
    
             
//***Changed below to chan.notify, but do not get it or chan.connected
     //if ( $ev && $ev->name == "chan.connected" && $ev->params["module"] == 'sip'  ) 
     if ( $ev && $ev->name == "chan.notify" 
     {
                 
Yate::Debug'CHAN CONNECTED ' $ev->getValue("called") );
                 
$peer_id $ev->params["peerid"];
                 
$m = new Yate("chan.masquerade");
                 
$m->params["message"] = "chan.attach";               
                 
$m->params["source"] = "wave/play/./sounds/record.gsm";  //*** not sure of path, but never get this far
                 
$m->params["id"] = $peer_id;
                 
$m->params["notify"] = $ourcallid;
                 
$m->Dispatch();
     }

             if ( 
$ev && $ev->name == "call.route"  
             {
         if ( $ev->getValue("called") == '600' )
                 {
                     
Yate::Debug'Route Called ' $ev->getValue("called") );
                     
$chl_id NULL;

                     
//*** removed this as it will overwrite ourcallid?
                     //$ourcallid   = $ev->params["id"];

                     // Not sure about this, it's all I can do to get it to start.

                     //$ev->retval = "tone/noise";
                     //*** changed from other post to the dumb channel
                     
$ev->retval "dumb/";
                     
$ev->handled true;
                     
$ev->Acknowledge();    
                     
$ev false;    
 } 
     }

             if ( 
$ev && $ev->name == "call.execute"  
             {
 Yate::Debug'Execute ' $ev->params["id"] );

 //*** added this section for Acknowledge, missing from other post
 $partycallid $ev->GetValue("id");
 $ev->params["targetid"] = $ourcallid;
 $ev->handled true;   //*** or should be false?
 $ev->Acknowledge();
 $ev false;
 //*** end of added section
 
                 
$m = new Yate("call.answered");
                 
//$m->params["id"] = $chl_id;
                 //*** changed from above NULL id
                 
$m->params["id"] = $ourcallid;
                 
//$m->params["targetid"] = $chl_id;
                 //*** changed from above NULL id
                 
$m->params["targetid"] = $partycallid;
 $m->Dispatch();
            }

     if ($ev)
 $ev->Acknowledge();

     break;

        case 
"answer":
            
Yate::Output("PHP Answered -: " $ev->name " time: " microtime(true) );
            break;

        case 
"installed":
            
Yate::Output("PHP Installed: " $ev->name " time: " microtime(true) );
    break;

        case 
"uninstalled":
            
Yate::Output("PHP Uninstalled: " $ev->name " time: " microtime(true) );
    break;

        case 
"setlocal":
            
Yate::Output("PHP Parameter: "$ev->name "=" $ev->retval . ($ev->handled " (OK)" " (error)")  . " time: " microtime(true)  );
    break;

        default:
            ( 
$ev->type != 'empty' Yate::Output("PHP Event: " $ev->type ", " $ev->name " time: " microtime(true) ) : NULL );
    }
}

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

?>



marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Windows - Global Script
« Reply #1 on: November 23, 2015, 04:14:27 AM »
If all you need is answer the call and play something you may route the call to wave module.

If not, here are some hints (NOTE: they are not specific to PHP. Any module wanting to implement the same behaviour should follow the same pattern):
- Don't use a single variable to track calling channel id: it will be overridden on the next call. Use an array instead. Remember incoming channel id when routing
- You'll need to track channels to release memory when they terminate
- Don't handle call.execute. If you need to answer the incoming call just set 'autoanswer'='true' when routing
- Check for chan.connected message. It will be sent by the incoming chan when connected to dumb. You may answer the call (if not already done) and start playing media

Some examples of channel tracking may be found in yate dir,
share/scripts/testpbx.php
share/scripts/postanm_dtmf.php

truetwc

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Windows - Global Script
« Reply #2 on: November 23, 2015, 08:35:11 AM »
So if I comment out the section where I check for "call.execute",
I should get a "channel.connect" message when the dumb channel connects.
Is that correct?

But I do not get this.

Is there more I am missing for set up of the dumb channel?


marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Windows - Global Script
« Reply #3 on: November 23, 2015, 08:45:16 AM »
You should post a yate log for incoming call not working.
Please enable the message sniffer. See http://docs.yate.ro/wiki/Debugging_and,_or_Investigation_of_messages

truetwc

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Windows - Global Script
« Reply #4 on: November 24, 2015, 07:12:22 AM »
Thanks.  The message sniffer let me see the chan.connected messages.
I just had to 'subscribe' to them.  The original code had:
Yate::Install("chan.notify")
So I changed it to chan.connected and received them.

I can now see how the calling channel id has to be tracked.

I don't want to just play a sound file, but would like to create some
simple ivr capability on windows.
Modifying the example scripts would do what I want.
But I see there is a bit of changing to do this.
Since most of them are channel scripts.

thanks again for the hints.