Reversing the Outgoing Call Order

Hey All,

New to Asterisk, and this forum.

I have a question that seems simple, but I’m not sure if it is.

When making an outgoing call through Asterisk, to a external number, the call happens like this:

  1. Outgoing Channel is called. (Set as Channel)
  2. Outgoing Channel is answered.
  3. Internal Extension is called. (Set an Extension)

I want to reverse this order, and have the Extension called, before the Channel is called. So it ends up like this:

  1. Internal Extention is called. (Set as Extension)
  2. Extension picks up.
  3. Outgoing Channel is called. (Set as Channel)

What is the best way to go about this?


Reading between the lines, you are using Originate or call files, not making ordinary calls.

To make an extension into a channel, use a Local channel. To make a channel into an extension, wrap it in the Dial application.

The behaviour you described:

is normal when you use call files. Are you sure that you are switching the source and destination channel/number of a call?

He was describing the behavour correctly. A channel is needed in order to call the extension/run the application. That is only available once the outgoing call is answered.

With my setup, first the extension (source) is rung. After the extension answers, the outgoing call (destination) is initiated.

int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel) .... chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh); .... if (chan) { if (chan->_state == AST_STATE_UP) { res = 0; ast_verb(4, "Channel %s was answered.\n", chan->name); .... if (ast_pbx_run(chan)) { ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name);

Only when it runs pbx_run is the dialplan, and therefore the extension, being processed. Note that this id predicated on the channel being UP, i.e. answered. I wonder if you are using an analogue channel without answer supervision?


How do you have your Asterisk set up to dial the Extension first? Where would I set this up?


Just to expand on my situation.

I’m using asterisk-java to connect to Asterisk. To API works fine, I just need to reverse the order of the call.

Here is the code:

originateAction = new OriginateAction();

originateAction.setCallerId("Wumbus Corporation <8009308333>");
originateAction.setPriority(new Integer(1));
originateAction.setTimeout(new Integer(30000));

This call works just fine.

I’ve tried just switching the values for Channel and Exten. I used “SIP/102” as the Channel, and the Channel as Exten. I also tried different combinations of values for Exten (e.g. SIP/2068527662, GnC/2068527662). I tried added “@outgoing” to the end of the Exten, as well, for our outbound route.

Extension 102 rings, but when I answer, it just says “Goodbye”, and hangs up.

The channel should be a local channel, referencing the original extension. The extension should be a new extension that includes Dial(original channel).

Thanks david55, I’ll talk with the Asterisk Server Manager, and let you know how it goes.

david55, could you please explain how to set this up within free pbx? I think i understand the concept, but i’m not sure how to implement it.

I’ve no idea; I don’t use Asterisk GUIs.


thanks for your answer, I guess I don’t have to use the GUI, but what would i need to do to implement this without the GUI?

Context: callcontext
Extension: 2068527662
Channel: Local/102@default

exten => _X.,1,Dial(SIP/GnC/${EXTEN})

I really consider this Asterisk/101, once you know to use local channels. On a general purpose installation, you will already have a context and extension that are close to doing the job.

My feeling is that, if you need help at this level, you should really be paying for a consultant.

Thanks for all the help. it turns out that all we needed to use the context “from-internal” rather than the “default”. i know this is the case with freepbx, it’s possible that it needs to be defined manually if freepbx is not used.