Manager Originate Questions

I’m working with the manager api originate command. I originate a call, the call answers, and then the call hangs up. The response I get back says ‘Originate successfully queued’. This is ok.

When I originate a call, ignore the call, and let the call timeout. The response I get back says ‘Originate failed’. How can I determine why this failed? I’m using SIP to deliver the calls, so is there a way to get the SIP response (3XX, 4XX, etc…)?

In some cases, ie busy, no answer it would be nice to attempt the call again later. In other cases, ie bad numbers, SIT tones, fast busy, I would not want to make the call again. Is there any way to find this out with the Manager API? I would rather not have to lookup CDR records to do this.

I have the same question.
If the originate action fails, how can I find out the reason? (Mainly I need to distinguish three cases: The other party didn’t pickup before timeout, the line was busy or the number was invalid.)
Does anybody have a clue?
Or is it impossible with the Manager API?
fyi: I don’t use sip, I use Asterisk-Java, Asterisk version is 1.2.1.

Thanks in advance

Biele

As of Asterisk v 1.2, there is no way to do this. This problem has been around for years, and is still an irritation to many Asterisk users. Fortunately for us there is a work around.

Here is what you can do. Use the Manager extension to dial a special local extension that you have setup. The local extension in your dialplan will simply execute the ‘Dial’ application. This works because the ‘Dial’ application actually does return the status of the call. The status will be set as the dialplan variable, voip-info.org/wiki-Asterisk+ … DIALSTATUS , ${DIALSTATUS}, which can be used to tell what happened as your call was dialed.

Here are the possible values that DIALSTATUS will contain. This is taken from the Wiki Link above.

“ANSWER: Call is answered. A successful dial. The caller reached the callee.
BUSY: Busy signal. The dial command reached its number but the number is busy.
NOANSWER: No answer. The dial command reached its number, the number rang for too long, then the dial timed out.
CANCEL: Call is cancelled. The dial command reached its number but the caller hung up before the callee picked up.
CONGESTION: Congestion. This status is usually a sign that the dialled number is not recognised.
CHANUNAVAIL: Channel unavailable. On SIP, peer may not be registered.”

None of this should be dependant on how the call is actually delivered, SIP / IAX / MGCP / POTS.

Let me know if you have any more questions, I’ll do what I can to help. I know how annoying this can be problem can be, and hopefully in future versions of Asterisk, the Originate Manager command will function just like the ‘Dial’ Application and return the dial status.

Good luck.
Dan

Hi,
I had also this problem with originate command. But yet get any solution. I would like to know how can we use the “ExtensionState” command which gives the status of the extension. Please experiment with this command and help me out
Thanks&Regards
ijb

I don’t know much about this command. From breifly researching it, it appears to return this information for a given ‘extension’.

-1 Channel is unavailable or does not exit
0 Channel is down and available
1 Channel is down, but reserved
2 Channel is off hook
3 Digits (or equivalent) have been dialed
4 Line is ringing
5 Remote end is ringing
6 Line is up
7 Line is busy

Please note that this is for an EXTENSION, not a channel. If you are trying to determine the status of a channel after a call has been originated, I don’t think this will work for you.

The solution I outlined in my previous post seems to be what most people are currently using as a solution. I know it isn’t the ideal solution, but it works and is stable.

Dan

Here are some more details on how to setup what I described in my previous posts.

In extensions.conf, create an extension like this.

[DIALER]
; Dial & Go
; Do NOT call the Answer application here, it will screw things up badly
exten => 5,1,Dial(SIP/${PHNUM}@XXXX,30)
exten => 5,n,Goto(s-${DIALSTATUS},1)

; Catch Different Conditions from Goto
exten => s-NOANSWER,1,NoOP(No Answer)
exten => s-BUSY,1,NoOP(Busy)
exten => s-CONGESTION,1,NoOP(Fast Busy / Congestion)
exten => s-CHANUNAVAIL,1,NoOP(SIT/ Line Unavailable)
exten => s-ANSWER,1,NoOP(Answered)
exten => s-CANCEL,1,NoOP(Exten Hung Up Early)
exten => _s-.,1,NoOP(Yikes! This shouldn’t happen!)

You will need to customize the Dial command. If you are not using SIP to place your calls, set the channel type. I currently have the timeout set at 30 seconds, change that to your tastes. Also the extension is set to ‘5’, change that to whatever is convenient. I also put this in it’s own context, you can rename the context if you want as well. Lastly, you probably want to make each DIALSTATUS condition do something other than ‘NoOP’.

Here’s what happens when you want to place a call. Use Manager Originate command channel to ‘local/exten@context’. Set everything else as normal, except set a channel variable called ‘PHNUM’ and set it to the phone number you want to dial. The originate command will open a channel and immediatly dial the phone number set in ‘PHNUM’. The result of this is placed into ‘DIALSTATUS’ by Asterisk. We then use a goto to jump to the proper line to handle the condition set in DIALSTATUS. (Note the ANSWER status will never be called because when the channel is answered execution of this extension is halted, and control is transfered to the extension you specified in the Originate command.)

Good Luck,
Dan

Thank you very much, dmikusa, for the detailed instruction. I will try it out as soon as I have the time. At this time of the project it’s not highest priority, but it will be sooner or later.
Having read your instruction I’m pretty optimistic about this problem.

Biele

When you originate there are only 2 reasons why it wont fail to my knowledge,
1 success - someone picks up
2 success - voicemail BEEP is detected (machine)
all others are a fail…

Okay, the distinction seems to work.
But the place I need the information about why the call was unsuccessful is the application which uses the manager API (not the dialplan).
I guess I could set a global variable (identifed by the called number) from the dialplan fork which I read from the application after the originate action has finished. If anyone has a better idea, please let me know.

Biele

Since I don’t really know what your trying to do I can’t give you a definite answer. I do know in my case, which is sending outbound call messages, I just call Dial and then if Dial fails I call an AGI script which takes care of all my application logic like rescheduling the call, etc.

Dan

I am working on similar task.

I originate call via Manager Interface to Local extention and then do a DIAL ( via IAX channel) from there.
Once the called party picks up the phone it is transferred to the Context defined in the Originate Command
However, I can not detect when called party hangs up.

Sometimes the execution on the Context above continues to the end.

Can anyone help me?
Is there a way to handle hangup event ?

Thanks

I experience similar problems: The call initiated by the dial command doesn’t seem to trigger Manager Events.

My workflow is just like denizzz’s:
-Send a Manager OriginateAction with channel “local/5@DIALER” and extension “2”
-At extension 5 at context DIALER a “Dial” is initiated
-When the called person picks up, the call is forwarded to the extension specified in the OriginateAction (“2”)
-If the called person hangs up no Manager Event is triggered (Neither is a MeetmeLeaveEvent if the call was forwarded into a conference room)

When I start the call simply by using a Manager OriginateAction with a channel like “ZAP/g1/123456789” (without diving into the Dial Plan) I get these events.

The [DIALER] context in my test extensions.conf basically looks like this (don’t worry about my UserEvent “CallResult”):

[code][DIALER]
exten => 5,1,Dial(CAPI/ISDN1/${PHNUM},${RINGSECS})
exten => 5,n,UserEvent(CallResult|result: ${DIALSTATUS}!${PHNUM})
exten => 2,1,UserEvent(CallResult|result: ANSWER!${PHNUM})
exten => 2,2,Wait(10);

[/code]

Here comes some debug info.
This is what I get on the Manager Console:

-- Executing Dial("Local/5@DIALER-2b7d,2", "CAPI/ISDN1/13|20") in new stack -- Called ISDN1/13 -- CAPI/ISDN1/13-2f is making progress passing it to Local/5@DIALER-2b7d,2 -- CAPI/ISDN1/13-2f is ringing -- CAPI/ISDN1/13-2f answered Local/5@DIALER-2b7d,2 > Channel Local/5@DIALER-2b7d,1 was answered. -- Executing UserEvent("Local/5@DIALER-2b7d,1", "CallResult|concatParams: ANSWER!13") in new stack -- Executing Wait("Local/5@DIALER-2b7d,1", "10") in new stack == Spawn extension (DIALER, 5, 1) exited non-zero on 'Local/5@DIALER-2b7d,2' WARNING[8477]: pbx.c:2405 __ast_pbx_run: Timeout, but no rule 't' in context 'DIALER' == ISDN1: CAPI Hangingup > CAPI INFO 0x3490: Normal call clearing

Especially the line " == Spawn extension (DIALER, 5, 1) exited non-zero on " looks suspicious to me, but I don’t really understand it. It looks like after the Dial command I have 2 calls walking through the Dial Plan. Well, since the Dial command is described as “establish a new outgoing connection on a channel, and then link it to the existing input channel” this makes sense, but this just isn’t what I want to do: I want to start a call and if it’s answered I want to forward it to a conference room, if it’s unsuccessful I want to know the Dial status. So far that works but it looks like from the moment with the suspicious line above, the initiated call doesn’t trigger Manager Events anymore. The Timeout at the end is not the problem, the problem is that I hung up the call before and did not receive the corresponding Manager Event.

Here are the Manager Events I receive from pickung up the call until hanging up (the latter unfortunately not triggering an event). Again, just ignore the UserEventCallResult:

[code]DEBUG - Got name [event], value: [Newstate]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel], value: [CAPI/ISDN1/13-2f]
DEBUG - Got name [state], value: [Up]
DEBUG - Got name [callerid], value: [5]
DEBUG - Got name [calleridname], value: []
DEBUG - Got name [uniqueid], value: [1148916742.157]

DEBUG - Got name [event], value: [Newstate]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel], value: [Local/5@DIALER-2b7d,2]
DEBUG - Got name [state], value: [Up]
DEBUG - Got name [callerid], value: []
DEBUG - Got name [calleridname], value: []
DEBUG - Got name [uniqueid], value: [1148916742.156]

DEBUG - Got name [event], value: [Link]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel1], value: [Local/5@DIALER-2b7d,2]
DEBUG - Got name [channel2], value: [CAPI/ISDN1/13-2f]
DEBUG - Got name [uniqueid1], value: [1148916742.156]
DEBUG - Got name [uniqueid2], value: [1148916742.157]
DEBUG - Got name [callerid1], value: [(null)]
DEBUG - Got name [callerid2], value: [5]

DEBUG - Got name [event], value: [Newchannel]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel], value: [Local/5@DIALER-2b7d,1]
DEBUG - Got name [state], value: [Up]
DEBUG - Got name [callerid], value: []
DEBUG - Got name [calleridname], value: []
DEBUG - Got name [uniqueid], value: [1148916742.155]

DEBUG - Got name [event], value: [OriginateSuccess]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [actionid], value: [31278839_3#actionID1]
DEBUG - Got name [channel], value: [local/5@DIALER]
DEBUG - Got name [exten], value: [2]
DEBUG - Got name [reason], value: [4]
DEBUG - Got name [uniqueid], value: [1148916742.155]

DEBUG - Got name [event], value: [Newexten]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel], value: [Local/5@DIALER-2b7d,1]
DEBUG - Got name [context], value: [DIALER]
DEBUG - Got name [extension], value: [2]
DEBUG - Got name [priority], value: [1]
DEBUG - Got name [application], value: [UserEvent]
DEBUG - Got name [appdata], value: [CallResult|result: ANSWER!13]
DEBUG - Got name [uniqueid], value: [1148916742.155]

DEBUG - Got name [event], value: [UserEventCallResult]
DEBUG - Got name [privilege], value: [user,all]
DEBUG - Got name [channel], value: [Local/5@DIALER-2b7d,1]
DEBUG - Got name [uniqueid], value: [1148916742.155]
DEBUG - Got name [result], value: [ANSWER!13]

DEBUG - Got name [event], value: [Newexten]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel], value: [Local/5@DIALER-2b7d,1]
DEBUG - Got name [context], value: [DIALER]
DEBUG - Got name [extension], value: [2]
DEBUG - Got name [priority], value: [2]
DEBUG - Got name [application], value: [Wait]
DEBUG - Got name [appdata], value: [10]
DEBUG - Got name [uniqueid], value: [1148916742.155]

DEBUG - Got name [event], value: [Rename]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [oldname], value: [CAPI/ISDN1/13-2f]
DEBUG - Got name [newname], value: [CAPI/ISDN1/13-2f]
DEBUG - Got name [uniqueid], value: [1148916742.157]

DEBUG - Got name [event], value: [Rename]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [oldname], value: [Local/5@DIALER-2b7d,1]
DEBUG - Got name [newname], value: [CAPI/ISDN1/13-2f]
DEBUG - Got name [uniqueid], value: [1148916742.155]

DEBUG - Got name [event], value: [Unlink]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel1], value: [Local/5@DIALER-2b7d,2]
DEBUG - Got name [channel2], value: [CAPI/ISDN1/13-2f]
DEBUG - Got name [uniqueid1], value: [1148916742.156]
DEBUG - Got name [uniqueid2], value: [1148916742.157]
DEBUG - Got name [callerid1], value: [(null)]
DEBUG - Got name [callerid2], value: [5]

DEBUG - Got name [event], value: [Rename]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [oldname], value: [CAPI/ISDN1/13-2f]
DEBUG - Got name [newname], value: [Local/5@DIALER-2b7d,1]
DEBUG - Got name [uniqueid], value: [1148916742.157]

DEBUG - Got name [event], value: [Hangup]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel], value: [Local/5@DIALER-2b7d,1]
DEBUG - Got name [uniqueid], value: [1148916742.157]
DEBUG - Got name [cause], value: [0]
DEBUG - Got name [cause-txt], value: [Unknown]

DEBUG - Got name [event], value: [Hangup]
DEBUG - Got name [privilege], value: [call,all]
DEBUG - Got name [channel], value: [Local/5@DIALER-2b7d,2]
DEBUG - Got name [uniqueid], value: [1148916742.156]
DEBUG - Got name [cause], value: [0]
DEBUG - Got name [cause-txt], value: [Unknown]
[/code]
I hope somebody can enlighten me. TIA.

Are denizzz and me really the only ones experiencing this problem?
It is probably merely a result of not understanding properly how the Dial command works. I hope somebody can help me, when I put it like this:

What can be the reason if a call initiated by a Dial command doesn’t trigger manager events in realtime? Are there any conditions to the “calling user”?

I’m not really seeing any problems. What is the behaviour that you are expecting from the Dial command and how is it different from what you are getting?

                         -------------------------------------

If you are trying to use specific manager events to trigger events in your program, I wouldn’t recommend it. They are not always what you think. It’s much safter to trigger things from the dial plan.

Here’s an example. Say I’m using Asterisk as an outdialer and I want to increment a counter every time a call is completed. (Don’t ask why, this is just an example) It is far safer to do this in the dialplan either with AGI/FASTAGI or through a custom dial plan command, than it is to do so by watching manager events. Something like this in your dial plan will get the job done easier and safer than watching manager events.

[DIALER]
exten => 1,1,Answer()
exten => 1,n,Dial(Local/5,10)

exten => h,1,NoOP(Dialer Hungup)
exten => h,n,DeadAGI(decrement.agi)

[LISTENER]
exten => 5,1,Answer()
exten => 5,n,Wait(100)
exten => 5,n,Hangup()

Dan

Well, the problem is like I described above:

[quote=“Biele”]-Send a Manager OriginateAction with channel “local/5@DIALER” and extension “2”
-At extension 5 at context DIALER a “Dial” is initiated
-When the called person picks up, the call is forwarded to the extension specified in the OriginateAction (“2”)
-If the called person hangs up no Manager Event is triggered (Neither is a MeetmeLeaveEvent if the call was forwarded into a conference room)

When I start the call simply by using a Manager OriginateAction with a channel like “ZAP/g1/123456789” (without diving into the Dial Plan) I get these events.
[…][/quote]
What confuses me is that when using the Dial command from the dial plan I have a counterpart to the called party (the calling party), which I don’t have when I use the Manager API Originate command.

Our software architecture relies heavily on the Manager API, I can’t change that now. So far we experienced no problems, it all started with the workaround to find out why a call fails (see beginning of this thread). Of course it would be best if the Manager API simply received this information.

It may be possible that you have found a bug. I would suggest checking the bug tracker for an existing bug, and if one doesn’t exist posting one.

The other thing you could try would be to look at an existing project that uses the Manager Interface heavily and see how they are handling things. You could also see if the problem you are experiencing afflicts the other project, which would almost certainly indicate a bug.

The Asterisk Manager Proxy might be a good project to look at. voip-info.org/wiki-Asterisk+Manager+Proxy.

Dan

Biele, do you still encounter those problems?

Would you mind having a look at the new live package in Asterisk-Java and the originateAsync methods in its AsteriskServer class?

Link: asteriskjava.org/0.3-SNAPSHOT/

If Orginate is executed with async one will receive orginate events. Within these events there is a reason code. I thought this is what we are looking for, but the reason code is 1 for any type of failure (no such number, call rejected, did not pick up, etc) and its always 4 in the event that the call was picked up. I ask around on the asterisk users list about this a while ago.

This was the reply I got back from Moises Silva:

[quote]…Unfortunately, Originate is somehow a mess. Answering your
question, the “reason” is not really a reason, at least not in release
1.2.12.1, that is the one im using. The reason is set according to the
last communication frame read from the originated channel. Let me
explain. When you originate a channel, asterisk starts creating the
internal C structure, and then trying to reach the peer. So, one first
common control frame received from our originated channel is
AST_CONTROL_RING, defined in include/asterisk/frame.h with a value of
2. If originate terminated in that very moment, the reason would be 2.
But in your scenario, when the callee does not pick up, the channel is
hangup, so the control frame AST_CONTROL_HANGUP is the last frame
read, and YES, is defined with a value of 1, the 1 you always receive.
The 4 you receive is defined as AST_CONTROL_ANSWER, because that was the last control frame received once the call was answered and the
event OriginateSuccess sent…[/quote]

I waited for version 1.4 in the hope that this would have been addressed but the reason code still returns the last “communication frame” and not a actual cause code (as with the hangup codes) for 1.4. I don’t know if the asterisk developers actually sees this as a bug or not (or chance for enhancement). It would have been great if the reason code within the orginate event was a sort of cause code (as with the hangup codes) from which one can determine the reason why the call failed.

Does anybody know if there is plans to fix/enhance this?

Well it still doesn’t work, does it?

The originate command still does not return a proper status.
It is in the system somewhere - if you make an outgoing call from a phone and the remote line is busy, it will say “busy” or “Talking”. But can you get that status out of the system - ou cannot.

Or at least I cannot.
I have fiddled with the Asterisk-Java stuff for a long time - I note with amusement the documented result code for the Live entry has been removed (it’s in the Javadoc but not in the code).
I have tried the trick of making the dial plan do it and return a status - but I cannot even make that work (I was using AsteriskNow - is that a mistake?).

I am going crazy. All I want is to know if the outgoing call has failed, and if so, what the failure was. Busy, Fast busy, bad number, no answer. Seems so easy. But I have been grappling with this problem for weeks.

Ok. How about a bribe? I will pay US$50 to the person who can help me find a way to do this that actually runs on my system here (I am using Asterisk-Java and quite like it - except for this). (No, I am not a script kiddy. Yes, I do have considerable IT experience. Decades, even).

Simon (in Sydney and getting very frustrated)