# How to know the extension number

**URL:** <https://community.asterisk.org/t/how-to-know-the-extension-number/40175>\
**Category:** Asterisk Support\
**Created:** [August 17, 2012, 2:48pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175 "2012-08-17T14:48:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 17, 2012, 2:48pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/1 "2012-08-17T14:48:27Z")

</div>

Hi,

I’m using .call files, to call for exemple an extension 1002.

In my extensions.conf, i want to know the extension i’m currently calling.

[code][appel-sortant]

exten =\> s,1,AGI(/var/lib/asterisk/agi-bin/getNext.php, ${EXTEN})  
; Do some stuff here, like a Dial  
exten =\> s,n,Hangup[/code]

The ${EXTEN} is equal to “s”, but i want to know which one i’m calling

[quote]-- Executing [s@appel-sortant:11] AGI(“SIP/1002-0000005f”, “/var/lib/asterisk/agi-bin/getNext.php,s”) in new stack  
[/quote]

Any way to get the variable containing my 1002 extension id ?

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [August 17, 2012, 3:04pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/2 "2012-08-17T15:04:16Z")

</div>

If the value is s, you are calling s.

If you want to know the destination extension number, you need to copy it into a variable before you call the s extension in your macro or subroutine.

I think you need to provide verbose CLI output so one can see what dialplan is actually being run.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 17, 2012, 3:25pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/3 "2012-08-17T15:25:35Z")

</div>

Yes, i’m calling s, but the dial line call the 1002 extension

`exten => s,n,Dial(SIP/${EXTEN}@forfait-ovh,30,gtr)
`

With my .call file :

[quote]  
Channel: SIP/1002@forfait-ovh  
Callerid: 09XXXXXXXX  
MaxRetries: 0  
RetryTime: 10  
WaitTime: 20  
Context: appel-sortant  
Extension: s  
Priority: 1[/quote]

Can i get a variable from my .call file in the extension.conf ?

I want to know in the extensions.conf file the number i’m calling, to execute a AGI script with the number in argument, to get the next number i have to call.

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [August 17, 2012, 3:37pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/4 "2012-08-17T15:37:04Z")

</div>

It doesn’t call an extension at all, it calls a device. You can get the device name by parsing ${CHANNEL}.

Other options exist if you know the device technology (SIP, IAX, DAHDI, etc.)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 17, 2012, 3:39pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/5 "2012-08-17T15:39:01Z")

</div>

[quote=“david55”]It doesn’t call an extension at all, it calls a device. You can get the device name by parsing ${CHANNEL}.

Other options exist if you know the device technology (SIP, IAX, DAHDI, etc.)[/quote]

Ok, thanks, i’ll parse the ${CHANNEL} to get the device name.

Thanks 😄

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 20, 2012, 1:47pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/6 "2012-08-20T13:47:41Z")

</div>

Hi,

Parsing the ${CHANNEL} works fine if the callee answer the call, but if he do nothing or decline, the ${CHANNEL} is egal to : OutgoingSpoolFailed

[quote] == Using SIP RTP CoS mark 5  
– Got SIP response 603 “Decline” back from 192.168.21.52  
\> Channel SIP/1002-00000025 was never answered.  
– Executing [failed@appel-sortant:1] NoOp(“OutgoingSpoolFailed”, “appel-sortant failed”) in new stack  
– Executing [failed@appel-sortant:2] Set(“OutgoingSpoolFailed”, “NEXT=0”) in new stack  
– Executing [failed@appel-sortant:3] AGI(“OutgoingSpoolFailed”, “/var/lib/asterisk/agi-bin/getNext.php,OutgoingSpoolFailed”) in new stack  
– Launched AGI Script /var/lib/asterisk/agi-bin/getNext.php  
– AGI Script /var/lib/asterisk/agi-bin/getNext.php completed, returning 0  
– Executing [failed@appel-sortant:4] System(“OutgoingSpoolFailed”, “/var/lib/asterisk/outbound/callPeople.sh 0”) in new stack  
– Executing [failed@appel-sortant:5] Hangup(“OutgoingSpoolFailed”, “”) in new stack  
== Spawn extension (appel-sortant, failed, 5) exited non-zero on ‘OutgoingSpoolFailed’  
[/quote]

I must know the number I call in order to determine the next number to call with my agi script

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [August 20, 2012, 1:50pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/7 "2012-08-20T13:50:36Z")

</div>

Use a local channel. You can then explicitly dial the target channel, and handle any failures.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 20, 2012, 1:56pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/8 "2012-08-20T13:56:19Z")

</div>

> [@david55](#):
>
> Use a local channel. You can then explicitly dial the target channel, and handle any failures.

Ok, then, i do not have to use the “s” extension, but something like “\_X.” ? (I have some number to call like 09XXXXXXXX or other like 06XXXXXXXX)

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [August 20, 2012, 1:59pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/9 "2012-08-20T13:59:00Z")

</div>

That’s what I woudl do for the part A side. You can probably keep the same B side logic.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 20, 2012, 2:36pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/10 "2012-08-20T14:36:36Z")

</div>

> [@david55](#):
>
> That’s what I woudl do for the part A side. You can probably keep the same B side logic.

I can’t figure out why i got the same problem with the \_X. extension

[quote][appel-sortant]  
exten =\> \_X.,1,Answer  
exten =\> \_X.,n,Set(LOOP=0)  
exten =\> \_X.,n,Set(MAX=3)  
exten =\> \_X.,n,Set(ACCEPT\_INTER=0)  
exten =\> \_X.,n,Set(NEXT=0)  
exten =\> \_X.,n,Goto(test,${EXTEN},1)

exten =\> failed,1,NoOp(appel sortant failed)  
exten =\> failed,n,NoOp(${EXTEN}) ; print “failed”

[test]  
exten =\> \_X.,1,NoOp(${EXTEN})  
exten =\> \_X.,n,Hangup[/quote]

[quote] == Using SIP RTP CoS mark 5  
– Executing [failed@appel-sortant:1] NoOp(“OutgoingSpoolFailed”, “appel sortant failed”) in new stack  
– Executing [failed@appel-sortant:2] NoOp(“OutgoingSpoolFailed”, “failed”) in new stack  
– Auto fallthrough, channel ‘OutgoingSpoolFailed’ status is ‘UNKNOWN’  
[Aug 20 16:30:37] NOTICE[10147]: pbx\_spool.c:339 attempt\_thread: Call failed to go through, reason (3) Remote end Ringing  
[/quote]

My generate .call file :

[quote]Channel: SIP/1002  
Callerid: 09XXXXXXXX  
MaxRetries: 0  
RetryTime: 10  
WaitTime: 20  
Context: appel-sortant  
Extension: 1002  
Priority: 1[/quote]

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [August 20, 2012, 2:48pm UTC](https://community.asterisk.org/t/how-to-know-the-extension-number/40175/11 "2012-08-20T14:48:42Z")

</div>

[quote]Channel: [color=#FF0000]Local/1002@OriginateContext[/color]  
Callerid: 09XXXXXXXX  
MaxRetries: 0  
RetryTime: 10  
WaitTime: 20  
Context: appel-sortant  
Extension: [color=#FF0000]s[/color]  
Priority: 1[/quote]
