Hi all, i'm using Asterisk as a media box for a VoIP network based on OpenSIPS. When an user phone is busy, call was forwarded to an asterisk ext: ; ==========================================; Voicemail on NOT AVAILABLE ; ==========================================exten => _VMR_.,1,Noop("from-voip: ${CALLERID(num)} ${EXTEN}") exten => _VMR_.,n,Set(DID=${EXTEN:4}) exten => _VMR_.,n,Answer() exten => _VMR_.,n,Wait(1) exten => _VMR_.,n,GotoIf(${VM_INFO(${DID},exists)}?avail:unavail) exten => _VMR_.,n(avail),Voicemail(${DID},u) exten => _VMR_.,n,Hangup() exten => _VMR_.,n(unavail),Playback(vm-theperson) exten => _VMR_.,n,SayDigits(${DID}); exten => _VMR_.,n,Playback(vm-isunavail) exten => _VMR_.,n,Read(digit,vm-tocallback,1,,1,5) exten => _VMR_.,n,Gotoif($["${digit}" = "2"]?:skip,1,5) exten => _VMR_.,n,Noop("Add callback for ${DID} from ${CALLERID(num)}") exten => _VMR_.,n,AGI(callback,${DID},${CALLERID(num)}) exten => _VMR_.,n,Playback(goodbye) exten => _VMR_.(skip),n,Hangup() when a vocal message asks to press "2" to add a callback when called users return free, using an AGI script that create a .call file: #!/usr/bin/php -q <?php ob_implicit_flush(true); set_time_limit(0); $called = $argv[1]; $caller = $argv[2]; $cf fopen("/var/spool/asterisk/outgoing/cb".$called."-".$caller.".call","w+"); fputs($cf,"Channel: LOCAL/CB_$called\n"); fputs($cf,"Context: default\n"); fputs($cf,"Extension: $caller\n"); fputs($cf,"CallerID: CallBack $caller <$caller>\n"); fputs($cf,"MaxRetries: 100\n"); fputs($cf,"RetryTime: 30\n"); fputs($cf,"Archive: Yes\n"); fputs($cf,"SetVar: CALLER=$caller\n"); fputs($cf,"SetVar: CALLED=$called\n"); fclose($cf); ?> periodically, Asterisk try to call CALLED user using CB_ routine: ; ==========================================; Callback ; ==========================================exten => _CB_.,1,Set(FROM=${CALLER}) exten => _CB_.,n,Set(TO=${CALLED}) exten => _CB_.,n,Noop("callback: from ${FROM} to ${TO}") exten => _CB_.,n,Set(CALLERID(all)="CB ${FROM} <${FROM}>") exten => _CB_.,n,Dial(SIP/voip-trunk/${TO},10) ; Check if called is available and, if answer, transfer to caller (TODO)... exten => _CB_.,n,Hangup() But, as you can see, Callback routine wasn't done because i'm unable to figure out how i can do that. I need that Asterisk call CALLED user and, when answered, start calling CALLER. It's possibile ? Thanks, Michele -- Michele Pinassi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 181 bytes Desc: OpenPGP digital signature URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20170127/d4db219b/attachment.pgp>
On Fri, 27 Jan 2017, Michele Pinassi wrote:> i'm using Asterisk as a media box for a VoIP network based on OpenSIPS. > When an user phone is busy, call was forwarded to an asterisk ext: > > ; ==========================================> ; Voicemail on NOT AVAILABLE > ; ==========================================> exten => _VMR_.,1,Noop("from-voip: ${CALLERID(num)} ${EXTEN}") > exten => _VMR_.,n,Set(DID=${EXTEN:4}) > exten => _VMR_.,n,Answer() > exten => _VMR_.,n,Wait(1) > exten => _VMR_.,n,GotoIf(${VM_INFO(${DID},exists)}?avail:unavail) > exten => _VMR_.,n(avail),Voicemail(${DID},u) > exten => _VMR_.,n,Hangup() > exten => _VMR_.,n(unavail),Playback(vm-theperson) > exten => _VMR_.,n,SayDigits(${DID}); > exten => _VMR_.,n,Playback(vm-isunavail) > exten => _VMR_.,n,Read(digit,vm-tocallback,1,,1,5) > exten => _VMR_.,n,Gotoif($["${digit}" = "2"]?:skip,1,5) > exten => _VMR_.,n,Noop("Add callback for ${DID} from ${CALLERID(num)}") > exten => _VMR_.,n,AGI(callback,${DID},${CALLERID(num)}) > exten => _VMR_.,n,Playback(goodbye) > exten => _VMR_.(skip),n,Hangup() > > when a vocal message asks to press "2" to add a callback when called > users return free, using an AGI script that create a .call file:> #!/usr/bin/php -q > <?php > > ob_implicit_flush(true); > set_time_limit(0); > > $called = $argv[1]; > $caller = $argv[2]; > > $cf > fopen("/var/spool/asterisk/outgoing/cb".$called."-".$caller.".call","w+"); > fputs($cf,"Channel: LOCAL/CB_$called\n"); > fputs($cf,"Context: default\n"); > fputs($cf,"Extension: $caller\n"); > fputs($cf,"CallerID: CallBack $caller <$caller>\n"); > fputs($cf,"MaxRetries: 100\n"); > fputs($cf,"RetryTime: 30\n"); > fputs($cf,"Archive: Yes\n"); > fputs($cf,"SetVar: CALLER=$caller\n"); > fputs($cf,"SetVar: CALLED=$called\n"); > fclose($cf); > > ?>0) This is not an AGI script. It does not read the AGI environment from STDIN and does not make any AGI requests. You could execute it using the system() application and it should execute the same -- maybe a couple of nanoseconds faster because Asterisk does not need to create the AGI environment or fiddle with file descriptors. 1) You should not create the call file in the spool directory. Doing so introduces a 'race condition' where Asterisk could start to read the file before your script is finished writing it. You should create the call file in another directory on the same file system and 'mv' it to the spool directory. /tmp/ or /var/tmp/ are usually suitable. ('mv' is 'atomic' -- it happens all at once.) 2) Visit http://www.voip-info.org/wiki/view/Asterisk+auto-dial+out to learn more about the call file format. Think of call files in terms of legs. The first leg uses the 'channel' argument to originate the call. If that call is answered, 'leg 2' execution continues either in the dialplan at 'context:extension:priority' or the 'application:data' is executed. Visit http://www.voip-info.org/wiki/view/Asterisk+local+channels to learn more about local channels. I think the syntax section will be most helpful.> I need that Asterisk call CALLED user and, when answered, start calling > CALLER.Yes, but the concept of 'answered' is vague if you are using analog channels. Visit http://www.voip-info.org and search for 'asterisk call back' for examples of how others have approached this problem. -- Thanks in advance, ------------------------------------------------------------------------- Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST https://www.linkedin.com/in/steve-edwards-4244281