Associate an extension to the related channel/context?


I would like to know of there is a way to get the association of a channel with the extension/context (that would be valid for SIP phones and Zap).
Since I have got only the extension number to initiate a Originate action on behalf of it, I need the channel and context for it. Is the command “show dialplan” the only way to do so or is there a better way?

Thanks for your ideas about that.


Not sure what you want to do exactly. Within dial plan, you have access to a handful of predefined variables such as EXTEN, CONTEXT, PRIORITY. You can display them occasionally. From CLI, Asterisk usually displays the context and extension when it first enters this extension.

To clarify my question :
Suppose I have got a zap channel zap/1 and that the dialplan sets extension 100 so that it Dials (zap/1).
Now suppose that I am listening to the manager events and receive a NewChannelEvent for channel zap/1. And that I only know that my extension is 100 (usually when a person uses a phone on a PBX he only knows it internal number). How would I know that the NewChannelEvent for zap/1 concerns my phone?
That is why I am looking for a clean way to get the association between the channel and the extension/context that is used to Dial that channel. I guess that this can only be known through the dialplan but I also guess that it is not so simple because the dialplan may use macro or variables…

Just so i understand what your getting at (I must not be reading what your saying properly) do you want to do the following?

Say i have an IP phone and my Extension is say 200, you want to actually bind that extension [200] to only use Zap Channel 1-1?

For Instance if you have 4 lines, and 4 Internal phones [SIP, IAX or What ever], you want to bind each one of those Extensions to its own dedicated channel?

Have i got it right?



No that’s not what I want to do.
I am using the Manager API without knowing how the PBX is configured (not knowing the dialplan, sip.conf, zap.conf…). I just know the extension numbers assigned to the phones.
The question is :

  • when I receive an event indicating a channel (NewChannelEvent) : how do I know the phone concerned by that event
  • if I want to use the Originate action, how should I fill the channel and context? If I know the context, I can use Local/extension@context.

I would like to know if there is a clean way to get the channel/context with only an extension number. If using the show dialplan, it means that the result should be parsed which is not simple.



Perhaps you could explain what you want to do.

but iax2 show users and sip show users will show all the info you need for them. write it to a table and do with it what you want.