Call back if busy

Hi guys, i want setup call back if busy on asterisk, i got toturial form voip-info.org/wiki/index.php … nts_page=1, but it didn’t work.

Here my config in extension.conf :
[voip_trial]
exten => _5XXX,1,Dial(SIP/${EXTEN},10,t)
exten => _5XXX,2,ChanIsAvail(SIP/${EXTEN},s)
exten => _5XXX,3(s-BUSY),GotoIf($["${AVAILSTATUS}"<=“1”]?s-NOANSWER,1)
exten => _5XXX,n,Read(digit,callback,1)
exten => _5XXX,n,Gotoif($["${digit}"=“5”]?callback,1:5)
exten => _5XXX,n,Voicemail(${EXTEN},b)
exten => _5XXX,n,Hangup

exten => callback,1,AGI(callback,${EXTEN})
exten => callback,2,Hangup

exten => _cbXXXXXX,1,Set(FROM=${EXTEN}:2:3})
exten => _cbXXXXXX,2,Set(TO=${EXTEN}:5:3})
exten => _cbXXXXXX,3,ChanIsAvail(SIP/${TO},s)
exten => _cbXXXXXX,4,GotoIf($["${AVAILSTATUS}" <= “1”]?5:7)
exten => _cbXXXXXX,5,Set(CALLERID(all)=“CB ${TO} <${TO}>”)
exten => _cbXXXXXX,6,Dial(SIP/${FROM},10)
exten => _cbXXXXXX,n,Hangup

When i press 5 i got this error on my log CLI :
– Executing [5101@voip-trial:1] Dial(“SIP/5102-0000000c”, “SIP/5101,10,t”) in new stack
== Using SIP RTP CoS mark 5
– Called 5101
– Got SIP response 486 “Busy Here” back from 192.168.1.236
– SIP/5101-0000000d is busy
== Everyone is busy/congested at this time (1:1/0/0)
– Executing [5101@voip-trial:2] ChanIsAvail(“SIP/5102-0000000c”, “SIP/5101,s”) in new stack
– Executing [5101@voip-trial:3] GotoIf(“SIP/5102-0000000c”, “0?s-NOANSWER,1”) in new stack
– Executing [5101@voip-trial:4] Read(“SIP/5102-0000000c”, “digit,callback,1”) in new stack
– Accepting a maximum of 1 digits.
– <SIP/5102-0000000c> Playing ‘callback.gsm’ (language ‘en’)
– User entered ‘5’
– Executing [5101@voip-trial:5] GotoIf(“SIP/5102-0000000c”, “1?callback,1:5”) in new stack
– Goto (voip-trial,callback,1)
– Executing [callback@voip-trial:1] AGI(“SIP/5102-0000000c”, “callback,5101”) in new stack
– Launched AGI Script /usr/share/asterisk/agi-bin/callback
– <SIP/5102-0000000c>AGI Script callback completed, returning 0
– Executing [callback@voip-trial:2] Hangup(“SIP/5102-0000000c”, “”) in new stack
== Spawn extension (voip-trial, callback, 2) exited non-zero on ‘SIP/5102-0000000c’
– Attempting call on LOCAL/cb51025101 for 5101@voip-trial:1 (Retry 1)

[Dec 13 09:58:07] NOTICE[5146]: chan_local.c:534 local_call: No such extension/context cb51025101@default while calling Local channel
[Dec 13 09:58:07] NOTICE[5146]: channel.c:4042 __ast_request_and_dial: Unable to call channel LOCAL/cb51025101
[Dec 13 09:58:07] NOTICE[5146]: pbx_spool.c:339 attempt_thread: Call failed to go through, reason (0) C

And this is my call back file :

#!/usr/bin/php -q

<?php ob_implicit_flush(true); set_time_limit(0); $to = $argv[1]; $err=fopen("php://stderr","w"); $in = fopen("php://stdin","r"); while (!feof($in)) { $temp = str_replace("\n","",fgets($in,4096)); $s = split(":",$temp); $agi[str_replace("agi_","",$s[0])] = trim($s[1]); if (($temp == "") || ($temp == "\n")) { break; } } $cf = fopen("/var/spool/asterisk/outgoing/cb" . $agi["callerid"] . $to,"w+"); fputs($cf,"Channel: LOCAL/cb".$agi["callerid"].$to."\n"); fputs($cf,"Context: voip-trial\n"); fputs($cf,"Extension: ".$to."\n"); fputs($cf,"CallerID: CB ".$agi["callerid"]."<".$agi["callerid"]."> \n"); fputs($cf,"MaxRetries: 100\n"); fputs($cf,"RetryTime: 30\n"); fclose($cf); fclose($in); fclose($err); ?>

Where is the wrong in my script , please any suggest and advice, Thanks

Your cb extensions are not in the default context, or you failed to specifiy the context in the local channel address.

Thanks for your help david, i have edited my srcipt like this :
[callback]
include => voip-trial
exten => _cbXXXXXXXX,1,Set(FROM=${EXTEN}:2:4})
exten => _cbXXXXXXXX,2,Set(TO=${EXTEN}:6:4})
exten => _cbXXXXXXXX,3,ChanIsAvail(SIP/${TO},s)
exten => _cbXXXXXXXX,4,GotoIf($[“${AVAILSTATUS}” <= “1”]?5:7)
exten => _cbXXXXXXXX,5,Set(CALLERID(all)=“CB ${TO} <${TO}>”)
exten => _cbXXXXXXXX,6,Dial(SIP/${FROM},10)
exten => _cbXXXXXXXX,7,Hangup

AND i got file cb51025101 on /var/spool/asterisk/outgoing
Channel: SIP/cb51025101
Context: callback
Extension: 5101
CallerID: CB 5102<5102>
MaxRetries: 100
RetryTime: 30

StartRetry: 1187 1 (1355384971)
EndRetry: 1187 1 (1355384941)
StartRetry: 1187 2 (1355385001)
EndRetry: 1187 2 (1355384971)

But i got still error, here this error :
Spawn extension (voip-trial, 5101, 9) exited non-zero on ‘SIP/5102-00000041’
– Attempting call on SIP/cb51025101 for 5101@callback:1 (Retry 1)
== Using SIP RTP CoS mark 5
[Dec 13 14:49:01] WARNING[11414]: chan_sip.c:5467 create_addr: No such host: cb51025101
[Dec 13 14:49:01] NOTICE[11414]: channel.c:4020 __ast_request_and_dial: Unable to request channel SIP/cb51025101

Where is my wrong in my script and what the solution david, thanks

If you use SIP/ addresses, you need a host name or a sip.conf section name.

If you use Local/ addresses you need both an extension and context or you need to put your extensions in the default context.

[quote=“david55”]If you use SIP/ addresses, you need a host name or a sip.conf section name.

If you use Local/ addresses you need both an extension and context or you need to put your extensions in the default context.[/quote]

Ok, thanks david for your help, I Found solution. i edited my callback.php , like this :
$cf = fopen("/var/spool/asterisk/outgoing/cb" . $agi[“callerid”] . $to,“w+”);
fputs($cf,“Channel: SIP/”.$to."\n");
fputs($cf,“Context: callback\n”);
fputs($cf,“Extension: “.$to.”\n”);
fputs($cf,“CallerID: CB “.$agi[“callerid”].”<”.$agi[“callerid”]."> \n");
fputs($cf,“MaxRetries: 100\n”);
fputs($cf,“RetryTime: 30\n”);

i dial ext 5102 to 5101, when ext 5101 is busy , 5102 press 5 to want call back from 5101. I did it, but when i saw CLI log before 5101 hangup the telephone, it show :

  • Got SIP response 486 “Busy Here” back from 192.168.1.236
    [Dec 14 08:26:25] NOTICE[3089]: pbx_spool.c:339 attempt_thread: Call failed to go through, reason (5) Remote end is Busy

What is meant ? And when ext 5101 is hangup, ext 5101 ringing but it show in CLI log:
== Starting SIP/5101-0000000a at callback,5101,1 failed so falling back to exten ‘s’
== Starting SIP/5101-0000000a at callback,s,1 still failed so falling back to context ‘default’
– Executing [s@default:1] Wait(“SIP/5101-0000000a”, “1”) in new stack
– Executing [s@default:2] Answer(“SIP/5101-0000000a”, “”) in new stack
– Executing [s@default:3] Set(“SIP/5101-0000000a”, “TIMEOUT(digit)=5”) in new stack
– Digit timeout set to 5.000
– Executing [s@default:4] Set(“SIP/5101-0000000a”, “TIMEOUT(response)=10”) in new stack
– Response timeout set to 10.000
– Executing [s@default:5] BackGround(“SIP/5101-0000000a”, “demo-congrats”) in new stack
– <SIP/5101-0000000a> Playing ‘demo-congrats.gsm’ (language ‘en’)

  • <SIP/5101-0000000a> Playing ‘demo-moreinfo.gsm’ (language ‘en’)
    == Spawn extension (default, 2, 1) exited non-zero on ‘SIP/5101-0000000a’
    [Dec 14 08:28:28] NOTICE[3106]: pbx_spool.c:349 attempt_thread: Call completed to SIP/5101

What is meant to? sorry i am a newbie in asterisk. Thanks in advice

Hi, if you are using asterisk 1.8 you can try this wiki.asterisk.org/wiki/display/ … %28CCSS%29

Rather than try to do this based on someone else’s question (not a tutorial), itself based on a broken dialplan, when you don’t understand dialplan basics, why not look at the built in capabilities, described in wiki.asterisk.org/wiki/x/2ABQ (as referenced from the CHANGES file, in the source).

You may still need to understand dialplans.

I haven’t used this facility.