[ previous ] [ next ] [ threads ]
 To :  "G. Alex" <radiopont@y...>
 From :  Monica Tepelus <monica@v...>
 Subject :  Re: [yate] Call from IVR
 Date :  Fri, 18 Jun 2010 11:28:01 +0300
Hi,

This is how a valid sip resource is like:    sip/sip:$called@ip:port
In your case (because you send calls to a gateway you are authentified 
to)  you will have:    line/$called  and then you need to add a 
parameter "line"  = "account name from acc file to use"

I made some modifications below.

Monica Tepelus

G. Alex wrote:
> Monica, thank you for the reply. But in any case I cannot make a call fom IVR. for example I took code from ivrsample:
>
> #!/usr/bin/php -q
>  /* Simple example for the object oriented IVR interface
>
>    To use it you must route a number to:
>    external/nodata/ivrsample.php
> */
> require_once("libyateivr.php");
>
> function callfromivr($route)
>   
// you need to pass the name of the account in accfile
function callfromivr($route, $account)
> 	{
> 	global $route;
> 	global $partycallid;
>   
// you don't have $partycallid
> 	$m = new Yate("chan.masquerade");
>                 $m->params["message"] = "call.execute";
>                 $m->params["id"] = $partycallid;
>                 $m->params["callto"] = $route;
>   
$m->params["line"] =  $account;
>                 $m->Dispatch();
> 	}
>
> class IVR1 extends IVR
> {
>
>     // do initialization when entering this IVR
>     function OnEnter($state)
>     {
> 	// initialize the operation table on entering the IVR
> 	$this->optable = array(
> 	    // key 0 - play back some DTMF keys inband
> 	    ":0" => "dtmf:123:inband",
> 	    // key 5 - call the 2nd IVR state 'b', allow it to return
> 	    ":5" => "call:ivr2:b",
> 	    // key 6 - jump to 2nd IVR state 'b', will not return to us
> 	    ":6" => "jump:ivr2:b",
> 	    // key 8 - leave this IVR, return to parent or exit IVR::Run
> 	    ":8" => "leave",
> 	    // key 9 - clear play queue, add 2 files and start playing
> 	    ":9" => "play:file1.au:file2.slin:clear",
> 	    // on call.execute immediately answer the call
> 	    ":execute" => "answered",
> 	    // when entering this IVR output a message to logs
> 	    ":enter" => "output:Entered 1st IVR"
> 	);
> 	parent::OnEnter($state);
> 	// call the 2nd IVR
> 	IVR::Call("ivr2");
>     }
>   
          // you need to get $partycallid from the call.execute that 
starts the script
          function OnExecute(&$event)
          {
                global $partycallid;
                $partycallid = $event->GetValue("id");
                return parent::OnExecute($event);
          }
>     // handle keypad tones while in this IVR
>     function OnDTMF($tone)
>     {
> 	$this->Output("Got $tone");
> 	if (parent::OnDTMF($tone))
> 	    return true;
> 	if ($tone == "#")
> 	    IVR::Call("ivr2");
> 	return true;
>     }
> }
>
> class TheIVR_2 extends IVR
> {
>     // do initialization when entering this IVR
>     function OnEnter($state)
>     {
> 	parent::OnEnter($state);
> 	// this will fail so we remain the current IVR
> 	IVR::Call("nosuch");
>     }
>
>     // handle keypad tones while in this IVR
>     function OnDTMF($tone)
>     {
> 	switch ($tone) {
> 	    case "*":
> 		// hang up the IVR channel and possibly the incoming call
> 		IVR::Hangup();
> 		break;
> 	    case "#":
> 		// return to calling IVR with value 'Got #'
> 		IVR::Leave("Got $tone");
> 		break;
> 	    case "0":$route="27372020"; callfromivr($route);break;
>   
  $route = "line/27372020"; callfromivr($route, 
"acount_name_in_accfile"); break;
> 	    case "1":$route="27371010"; callfromivr($route);break;
>   
// same as above
> 	    case "2":
> 		$this->Output("Got $tone");
> 		break;
> 	    default:
> 		return false;
> 	}
> 	return true;
>     }
> }
>
> // initialize the Yate PHP library with default values, enable debugging
> Yate::Init();
> Yate::Debug(true);
>
> // register the two IVR classes with some names
> IVR::Register("ivr1","IVR1");
> IVR::Register("ivr2","TheIVR_2");
>
> // and start running by entering the 1st IVR
> IVR::Run("ivr1");
>
> // if we reach here the IVR is terminated
> Yate::Output("PHP: bye!");
>
> /* vi: set ts=8 sw=4 sts=4 noet: */
> ?>
>
>
>
>
> I tried to appoint different "$called" and "sip2/called" codes. What I am doing wrong?
>
>
>
> 17.06.10, 15:35, "Monica Tepelus" :
>
>   
>> Hi,
>>  
>>  To make a call from ivr you need to send a call.execute inside a 
>>  chan.masquerade for your party.
>>  
>>  Ex in php:
>>  
>>              $m = new Yate("chan.masquerade");
>>              $m->params["message"] = "call.execute";
>>              $m->params["id"] = $partycallid;
>>              $m->params["callto"] = $route;
>>              $m->Dispatch();
>>  
>>  $route is where you send the call. You didn't specify who takes the 
>>  decision where to route the call.
>>  $route is normally the answer to a call.route message but you can build 
>>  it directly in the above code.
>>  
>>  To route  to an account defined in accfile:
>>  
>>  $route = "line/$called_number";
>>  $m->params["line"] = "sip1";    // send call to first account
>>  
>>  If you send call.route message and answer from another module then make 
>>  sure to add param "line" in the chan.masquerade example from the above.
>>  
>>  Monica Tepelus
>>  
>>  G. Alex wrote:
>>  > Hello,
>>  > There are some registered SIP-accounts in accfile.conf file:
>>  > [sip1]
>>  > username=2737000
>>  > .........
>>  > [sip2]
>>  > username=2737001
>>  > .........
>>  > [sip3]
>>  > username=2737003
>>  > .........
>>  > [sip4]
>>  > username=2737004
>>  >
>>  > In regexroute.conf file the route is adjusted from two numbers:
>>  > ^2737000$=external/nodata/myivr.php
>>  > ^2737001$=external/nodata/myivr.php
>>  >
>>  > How to make a call from IVR (which function should be used in order to make the call, after main Menu listening and the definite Submenu selection, come to the network using one of free SIPs (sip3, sip4)?
>>  >
>>  > G. Alex
>>  >   
>>  
>>  
>>