how to disconnect the caller but still continue the process - asterisk

I'm kinda new at asterisk and i have to do a process after hangup, i have a code that is something like this:
exten => 12345,1,wait(1)
same => n,agi(myagi.php)
same => n,hangup()
exten => h,1,noop("hangup")
same => n,System(sleep 1m)
same => n,agi(sendemail.php)
so, the call wont hangup when it goes to the h extension because of the sleep, but i need the delay before sending the email, how do i disconnect the caller but still continue the process in the h extension? or is there another way to do this?
Thank You

You'll need to change your setup to send the email asynchronously. Basically in your dialplan you will call a shell script that only executes the email script in the background and returns immediately. You'll add the delay into the email script using PHP's sleep() function. I've not done this before so don't have any sample code to offer, but this looks like a good place to start.

Best way is mark cdr,for example CDR(userfield)=EMAILTO:address.
After that check all cdrs every few seconds/minutes and do action you needed.
Please never use h-extension for task that can take more then 0.5 sec, that can cause issues.

Related

What is the Asterisk Dial() Option to Call Subroutine on "Ringing" Status Received from Called Party?

I need to execute AGI scripts when following events occur:
An incoming call (it is simple just call AGI() function).
When a call is "Ringing" (I cannot figure it out!). <-- Problem, how to do this?
When a call is "Answered" (I do it using U(answer^${CALLID}) option in Dial()).
When a call hangs up (I do it using h special extension).
My dialplan looks like this:
[from_origin]
exten => _X.,1,NoOp(${CALLER_USERNAME} from ${CHANNEL(pjsip,remote_addr)})
same => n,AGI(agi://127.0.0.1/incoming)
same => n,Dial(${DIALSTR},45,U(answer^${CALLID}))
exten => h,1,AGI(agi://127.0.0.1/hangup,${CDR(uniqueid)})
[answer]
exten => s,1,Set(theCallID=${ARG1})
same => n,AGI(agi://127.0.0.1/answered)
same => n,Return()
Look, I have called 3 fast-agi scripts: incoming, answered and hangup. Now I need to call similar script like ringing when the called party is "ringing". How to achieve this ?
Ringing status is status of the channel(chan_pjsip.so) and it not sent outside channel code.
So no, you can't get it in Dial app. Because it can't be get for some channels types and Dial still should work for those types.
For some channels you can get it via AMI in event listening loop in NewState event. But there are no garantee it will be exactly at same time when you got ringing sip message.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerEvent_Newstate

Asterisk - Make a call inside a conference with ringtone

I'm trying to make a call inside a running conference and hear the ringtone.
*Note: the conference is already running I have only the admin inside.
I already tried different approaches to make the call without success
1) Originate:
channel originate SIP/000000000#provider application ConfBridge ConferenceName
This works, makes the call and when its answered it joins the conference, but no ringtone
2) ConfBridge Menu, dialplan_exec
[default_menu]
type=menu
1=dialplan_exec(addcaller,000000000,1)
[addcaller]
exten => _XXXXXXXXXX,1,Originate(SIP/${EXTEN}#provider,app,ConfBridge,ConferenceName)
This works, makes the call I have ringtone, but when answer, no audio inside conference
3) Options 2 + a macro to join call after answer
same => n,Dial(SIP/${EXTEN}#provider,,M(joinconf))
[macro-joinconf]
exten => s,1,NoOp()
same => n,ConfBridge(ConferenceName)
same => n,Hangup()
This works, I can hear the ringtone and then I can see the user inside the conference but again, no audio!
4) All versions with variants
I have tryied all sort of variants using
same => n,Answer()
same => n,Progress()
same => n,Wait(1)
cause maybe was the channel not answered, but I'm stuck.
the final goal is a simple
conference with the power of calling and hanging other phones.
No matter if I need to use:
AMI with multiple commands
channelredirect
chanspy
meetme
AGI
whatever just need to make it work
Do originate into Local channel, in dialplan use Ringing(r param in dial command) or moh with ringing sound

Continue Asterisk Dial Plan after Wild Card Match

I have a working Asterisk 13 Dialplan where a call goes into extensions.conf and then within extensions.conf into a switch statement:
switch => Realtime
That works. The call completes based on the content of the database table.
Now what I want to do is a little filtering before the call goes to the Realtime table. Something like this:
exten => _X.,1,Set(GROUP()=${ACCOUNTCODE:0:4})
exten => _X.,n,GotoIf($[${GROUP_COUNT(ABCD)} > 2]?tooMany,1)
exten => _X.,n,Log(VERBOSE,Call Continuing. ${ACCOUNTCODE} is not a limited group)
switch => Realtime
exten => tooMany,1,Congestion(4)
exten => tooMany,n,hangup(503)
BUT, what seems to happen is that once the extension matches (the _X.) the processing continues through the match but does not continue and process the "switch => Realtime" line (it never executes the database component of the dialplan)
How do I get the Realtime dialplan to execute after going through the filter?
Second somewhat related question
Incidentally, I can have a similar problem in an all-text extensions.conf where I want all calls to have something done to them, and then do something specific to certain calls. e.g.
exten => _X.,1,<do something>
exten => 1122,1,<do some more stuff to the same call>
This is treated in the documentation and 1122 is the more specific line and will be the one executed. BUT, what is the correct way of doing something to all calls AND then do the specific thing?
I think you not understand how switch Realtime works.
It is not possible do switch for one extensions(or pattern) only. It is possible do for CONTEXT. When asterisk engine see switch=>realtime it works like include, i.e include database search in this WHOLE context.
You also seams like not understanding how dialplan works(otherwise will be no question 2). Please read book like ORelly's "Asterisk the future of telephony", it have step-by-step description of how that works.

get the caller number after call is answered

I have a php script that run when call is answered it's in [macro-blkvm-clr]
macro. the php get 3 parms the first param should be the caller number this is my line
exten => s,n,AGI(/var/lib/asterisk/agi-bin/alertcalls.php,${CALLERID(num)},1,${MASTER_CHANNEL(CONNECTEDLINE(num))})
I don't know why but when it asterisk send the parameter to php it set it to the answered phone. for example ext 300 call to ext 200 and in the log that what I see
Executing [s#macro-blkvm-clr:2] AGI("PJSIP/200-00000253", "/var/lib/asterisk/agi-bin/alertcalls.php,200,1,200") in new stack
why is that. and how can I send the real ext that call (in this case 300)
thks for all helper and sorry for my English I hope I was clear
You can save the
exten => s,n,SET(VAR1=${CALLERID(num)})
exten => s,n,AGI(/var/lib/asterisk/agi-bin/alertcalls.php,${VAR1},1,${MASTER_CHANNEL(CONNECTEDLINE(num))})
Becuase macro executed for CALLED party channel(it was invented to do privacy) before connect called and calling channel.
You can see all variables by do Dumpchan as first priority in macro.
Save the caller ID number into a channel variable before you Answer() the call, and then reference that.
You should always be able to reference ${CALLERID(num)}, but if it's not working for you at that point, the above is an easy work around.

Not able to connect incoming caller to th dialed calee in meetme function in asterisk

My code is simple A calls to B the they both entered into meetme conference
[from-pstn]
exten=> _X.,n,Answer()
same => n,dial(DAHDI/g0/0${9xxxxxxxxx},20,mM(MYCONFO))
[macro-MYCONFO]
exten => s,n,Meetme(1234,sdrM)
But when A calls to B only B enters the conference and A is not able to enter conference , A only hears musiconhold
yes i have read meetme and n way dialout
Can anybody help me with that
I think for this you should use option G from DIAL command:
http://www.voip-info.org/wiki/view/Asterisk+cmd+Dial
G(context^exten^pri): If the call is answered, transfer both parties to the specified context and extension. The calling party is transferred to priority x, and the called party to priority x+1. This allows the dialplan to distinguish between the calling and called legs of the call (new in v1.2). You cannot use any options that would affect the post-answer state if this option is used.
So dialplan should be:
[from-pstn]
exten=> _X.,n,Answer()
same => n,dial(DAHDI/g0/0${9xxxxxxxxx},20,mG(MYCONFO,s,1))
[MYCONFO]
exten => s,1,Meetme(1234,sdrM)
exten => s,2,Meetme(1234,sdr)
You code is incorrect.
Please read again documentation about in-call-macro. It have alot of limits
Try use goto.
If not work, try use transfer from external application with UserEvent
ps. yes, it work as described in n-way-howto too.

Resources