How to check the Originate Action in the AMI?

Gentlemen, the next question. Write a utility that will send to AMI Originate request to Asterisk, so he called on my cell. Gave me then the information to connect to the Asterisk via the AMI. I namutil on the Internet library Asterisk-Java. Doing the query this way:
final ManagerConnection managerConnection;

Logger globalLogger = Logger.getLogger(java.util.logging.Logger.GLOBAL_LOGGER_NAME);

ManagerConnectionFactory managerConnectionFactory = new ManagerConnectionFactory("XXXXX", XXXXX, "XXXXX", "XXXXX");
managerConnection = managerConnectionFactory.createManagerConnection();
OriginateAction originateAction;
ManagerResponse originateResponse;

originateAction = new OriginateAction();
originateAction.setVariable("customernum", "XXXXX");
originateAction.setTimeout(new Long(30000));

try {
 originateResponse = managerConnection.sendAction(originateAction);
 System.out.println("ORIGINATE RESPONSE is:" + originateResponse.getResponse());
 System.out.println("ORIGINATE MESSAGE:" + originateResponse.getMessage());
 System.out.println("ACTION ID:" + originateAction.getActionId());
} catch (IOException e) {
} catch (AuthenticationFailedException e) {
} catch (TimeoutException e) {
} finally {

In the end, all call, all settings are correct. But ORIGINATE always SUCCESS RESPONSE, but the MESSAGE always ORIGINATE Originate successfully queued.
But the problem is that I need to know how the user responded to the call (was available or not, answered or not, etc...). How can I change the way of sending a message (maybe something to suggest to improve the settings of asterisk, I was in the config, not boom-boom, but the admins have access) to get some fitback in a given situation? Help mi pliz, the project illuminated )
September 19th 19 at 12:43
2 answers
September 19th 19 at 12:45
Need to send a request asynchronously (async=true) and catch OriginateResponse in which the variable Reason contains the result code of the call. Code values you can look here: If you plan to send requests in parallel, then in the query you need to add the variable actionid and catch originateresponse with the correct actionid.
OriginateResponse I returned once, when you call sendAction(), it always SUCCESS. - Kurtis.Kirlin commented on September 19th 19 at 12:48
When async=true originateresponse comes in the form in which I wrote, just to catch need to listen to events, not to disconnect after the request is successful. For example in Python Liebe pyst to do this, hang on colback need a message like this:

manager = asterisk.manager.Manager()
manager.connect(host, port)
manager.login(user, password)
manager.register_event("OriginateResponse", handle_event)

def handle_event(event):
reason = event.headers["Reason"]
... - Payton.Smith40 commented on September 19th 19 at 12:51
: I did the Async=true and capture events, specifically OriginateResponseEvent:
managerConnection.addEventListener(new ManagerEventListener() {
public void onManagerEvent(ManagerEvent managerEvent) {
if(managerEvent instanceof OriginateResponseEvent) {
OriginateResponseEvent event = (OriginateResponseEvent)managerEvent;
System.out.println("Originate Response Event: "+event.getResponse()+" "+event.getReason());

In the console, again, is always displayed: "Originate Response Event: Success 4" (4==answered). Regardless, I picked up the handset on the phone, receiving it, or not. - Kurtis.Kirlin commented on September 19th 19 at 12:54
I use originate on the asterisk+freepbx. Channel indicate Local/nomernogo@from-internal. Reason always comes correct. Look at your dialplan, it is possible there is something wrong. - Payton.Smith40 commented on September 19th 19 at 12:57
: That way, exactly the same architecture. That is Asterisk+freepbx and channel Local/room . Perhaps Asterisk-java as something special catches this answer? - Kurtis.Kirlin commented on September 19th 19 at 13:00
: Just now switched to sending a phone number via Variables - Kurtis.Kirlin commented on September 19th 19 at 13:03
no, asterisk-java has nothing to do with it. First call goes to mobile, and then the recording/ivr/phone ? - Payton.Smith40 commented on September 19th 19 at 13:06
Will call does not go further. The need only is to make sure that the client is now on the phone, and responded to the call. He is the dialer is playing a music file. The dial is 20 seconds. Anywhere nothing written. Just as soon as the customer picked up (or dropped), you need to react by sending him a text. This kind of notification scheme in turn. As soon as someone answered is to send data to it. If not - call the following. For this, all conatel - Kurtis.Kirlin commented on September 19th 19 at 13:09
I have a feeling that first, in context, you pick up the phone, and then already starting to call mobiles. Show the context - Payton.Smith40 commented on September 19th 19 at 13:12
OriginateResponse comes immediately after sending the request or after accept/reject a call on your mobile? - Payton.Smith40 commented on September 19th 19 at 13:15
: Immediately - Kurtis.Kirlin commented on September 19th 19 at 13:18
: I have the configs of asterisk, not really, I understand they are written in extensions.conf ? If Yes, then here:
exten => 777,1,Answer()
exten => 777,2,MusicOnHold()
exten => 222,1,Dial(SIP/${customernum}@myvoip,20) - Kurtis.Kirlin commented on September 19th 19 at 13:21
My Skype: ugine.teplodar
so it will be faster - Payton.Smith40 commented on September 19th 19 at 13:24
who this will help me for programming Asterisk in C#. can't get the field reason for OriginateResponse
Sequence of events: first the Channel is rung. Then, when that answers, the Extension is dialled within the Context to initiate the other end of the call. Note that the Timeout only applies to the initial connection to the Channel; any timeout for the other end can be specified, for instance in a Dial command in the definition of the Context.

Using Async leads to an OriginateResponse event which contains the failure reason if any. Reason may be one of the following:

0 = no such extension or number. Also bad dial tech ie. name of a sip trunk that deosn't exist
1 = no answer
4 = answered
5 = busy
8 = congested or not available (Disconnected Number)

See the ast_control_frame_type enum in frame.h for a complete (and up to date) list of possible reasons.
The fallowing was derived from the Asterisk source:

1 = Other end has hungup
2 = Local ring
3 = Remote end is ringing
4 = Remote end has answered
5 = Remote end is busy
6 = Make it go off hook
7 = Line is off hook
8 = Congestion (circuits busy) - emmanuelle_Purdy commented on September 19th 19 at 13:27
September 19th 19 at 12:47
by changing the query, this is not achieved

you need to listen to event s and to disassemble them

Find more questions by tags JavaAsterisk