Music on hold and background work

Hi folk,

i have to run an agi in the background and music on hold should be played untill i route the call to any other extension.

Kindly help

I’ve done this for one project…
Are you familiar with AMI? I have a listener that listen for varset event (this var holds the callerid) and then route the channel in the right extension.

exten => s,1,Set(my_custon_var=${CALLERID(num)})
exten => s,n,Answer()
exten => s,n,MusicOnHold(mymusic,300)
exten => s,n,Hangup()

Really? can you help me yes, i have worked in AMI. but i have to play music on hold untill i find an available extension to be routed. Please help me out.
ok lets say i login a manager, then how will i listen for var, can you guide me thank you i would really appreciate.

[quote=“shmaize”]I’ve done this for one project…
Are you familiar with AMI? I have a listener that listen for varset event (this var holds the callerid) and then route the channel in the right extension.

exten => s,1,Set(my_custon_var=${CALLERID(num)})
exten => s,n,Answer()
exten => s,n,MusicOnHold(mymusic,300)
exten => s,n,Hangup()[/quote]

You are very kind. Show Shmaize all of your knowledge about this issue. And don’t forget show the link to your project. I’ll highly appreciate your contribution.

Sorry for the delay, but “change email” is not working here and can’t see for new replies :confused:

So… you need the PHPAGI.

#!/usr/bin/php -q
<?php
require_once ('phpagi/phpagi-asmanager.php');

$manager_ip = "127.0.0.1";
$username = "XXX";
$secret = "XXX";
$my_var = "something";

$manager = new AGI_AsteriskManager ();
$con = $manager->connect ( $manager_ip, $username, $secret );
if (! $con) {
	logger ( "Can't connect to manager!" );
	exit ();
}

$manager->add_event_handler ( 'varset', 'my_function' );

$response = $manager->wait_response ( TRUE );

// this staff is if we lost the connection
while ( ! $response ) {
	sleep ( "1" );
	$con = $manager->connect ( $manager_ip, $username, $secret );
	while ( ! $con ) {
		sleep ( "1" );
		$con = $manager->connect ( $manager_ip, $username, $secret );
	}
	$response = $manager->wait_response ( TRUE );

}

function my_function($ecode, $data, $server, $port) {
	global $my_var, $manager;
	
	$variable = $data ['Variable']; // this is the variable name
	$value = $data ['Value']; // this is the variable value 
	
	// handle only our variable
	if ($variable != $my_var) {
		return;
	}
	
	// do some logic here
}

?>

When you have Set(something=${CALLERID(num)}) in the dialplan (callerid is just an example) the function “my_function” will be triggered. Do you need further assistance?

Thank you and really appreciated. but how to play music on hold in the background

this is a very nice and impressive web site which is one of the best source for using this impressive and entertaining source so i like to visit this impressive and entertaining web site to know about Mobile phone sources so this is one of the best site.