Sriram
Sriram

Reputation: 10558

Getting the extension number on which a call was received within a function - asterisk

I have an asterisk server set up as a telephone exchange. I have, on it, a 100 extensions, from 00 - 99. I am running specific functions on each of those extensions. Some of these functions may need the extension on which the call was received to be available. How can I access the same? For example,

Say a call comes in on extension 55.
55 has a function associated with it. That function must take in 55 as an input parameter. How do I do this?

I have tried the following:

exten => 0,n,Verbose(1, "Call on ${EXTEN}-${CHANNEL}")  

Output is : Call on 0-DAHDI/20-1

Thanks,
Sriram Shankar.

Upvotes: 1

Views: 1207

Answers (1)

YWCA Hello
YWCA Hello

Reputation: 3059

The answer you are looking for is dependent upon the path that the call is taking through your system. The easiest way to determine the answer to your question is to place the call and then run the following commands from within the Asterisk CLI:

> core show channels

This will show you what channels are active. Find the channel name of your call.

core show channel [channel-name]

This will output an array of channel details, including different variables that are set and their corresponding values. Look for the extension number you are trying to grab in the value fields and then look to see what the corresponding variable name is. It could be ${CALLERID(num)}, ${CALLERID(dnid)}, something under the ${CDR} variable, or even elsewhere.

If you don't find it in the output produced by "core show channel [channel-name]", you may have to trace the dialplan path that the call is taking and try setting the variable early on when the DID information is still available.

Upvotes: 1

Related Questions