# Special dial plan most probably needs AGI

**URL:** <https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374>\
**Category:** Asterisk Support\
**Created:** [May 14, 2025, 6:02pm UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374 "2025-05-14T18:02:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tenacious](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/tenacious/32/9115_2.png) [@Tenacious](https://community.asterisk.org/u/Tenacious)\
**Post date:** [May 14, 2025, 6:02pm UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/1 "2025-05-14T18:02:15Z")

</div>

I need help with a dial plan can do the belows call flow

1. _Call from Extension_: An voip phone user dials `*123*(number)#`, where `(number)` is the desired phone number.

2. _PBX Receives Call_: The PBX receives the call and checks the dialed number pattern.

3. _Pattern Match_: The PBX matches the pattern `*123*(number)#` and triggers a specific dialplan.

4. _Hangup_: The PBX hangs up the call.

5. _Callback_: The PBX initiates a new call to the voip phonethat made the original call.

6. _Extension Answers_: The voip phone user answers the callback.

7. _Dial Outbound Call_: The PBX dials the `(number)` that was specified in the original call.

8. _Bridge Calls_: Once the outbound call is answered, the PBX bridges the two calls, connecting the extension user with the called party.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [May 14, 2025, 6:36pm UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/2 "2025-05-14T18:36:39Z")

</div>

Whilst this sounds strangely similar to another recent question, this variation doesn’t make sense, as, assuming extension means a local VoIP phone (extension, in the Asterisk sense, makes no sense here), there is really no advantage over just skipping steps 4, 5, and 6.

Generally though you need to show what you have done and ask specific questions about areas of difficulty; people are not going to design complete dialplans for free.

The main technical difficulty here is that the dialplan matching can’t really cope with an arbitrary number length in matching your pattern.

---

<div class="post-metadata">

**Author:** ![Tenacious](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/tenacious/32/9115_2.png) [@Tenacious](https://community.asterisk.org/u/Tenacious)\
**Post date:** [May 15, 2025, 6:50am UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/3 "2025-05-15T06:50:50Z")

</div>

I am willing to pay cause i am tired of trying and i am out of time

---

<div class="post-metadata">

**Author:** ![Tenacious](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/tenacious/32/9115_2.png) [@Tenacious](https://community.asterisk.org/u/Tenacious)\
**Post date:** [May 15, 2025, 9:35am UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/4 "2025-05-15T09:35:31Z")

</div>

Hi Community i am straggling to implement this dial plan when i implement the cal is properly rejected but doesn’t trigger a call back no errors check the log below

asterisk\*CLI\> dialplan reload

Dialplan reloaded.

```
    > Time to scan old dialplan and merge leftovers back into the new: 0.000081 sec

    > Time to restore hints and swap in new dialplan: 0.000039 sec

    > Time to delete the old dialplan: 0.000136 sec

    > Total time merge_contexts_delete: 0.000256 sec

    > pbx_config successfully loaded 3 contexts (enable debug for details).

-- Executing [*123*0677256155@from-internal:1] NoOp("PJSIP/troxy-00000005", "Received call transfer request") in new stack

-- Executing [*123*0677256155@from-internal:2] Set("PJSIP/troxy-00000005", "TARGET_NUMBER=0677256155") in new stack

-- Executing [*123*0677256155@from-internal:3] NoOp("PJSIP/troxy-00000005", "Target number is 0677256155") in new stack

-- Executing [*123*0677256155@from-internal:4] Set("PJSIP/troxy-00000005", "ORIGINATING_CHANNEL=PJSIP/troxy-00000005") in new stack

```

[2025-05-09 19:22:02] WARNING[1388][C-00000006]: pbx.c:2943 pbx\_extension\_helper: No application ‘AGI’ for extension (from-internal, _123_0677256155, 5)

== Spawn extension (from-internal, _123_0677256155, 5) exited non-zero on ‘PJSIP/troxy-00000005’

Dial plan  
[from-internal]  
; Local extension dialing  
exten =\> 201,1,Dial(PJSIP/troxy,20)  
exten =\> 209,1,Dial(PJSIP/tinashe,20)

; Feature code for call transfer  
exten =\> \__123_X.,1,NoOp(Received call transfer request)  
same =\> n,Set(TARGET\_NUMBER=${EXTEN:5}) ; Extract the number after _123_  
same =\> n,NoOp(Target number is ${TARGET\_NUMBER})  
same =\> n,Set(ORIGINATING\_CHANNEL=${CHANNEL}) ; Store the originating channel  
same =\> n,AGI(call\_transfer.agi,${ORIGINATING\_CHANNEL},${TARGET\_NUMBER}) ; Execute the AGI script  
same =\> n,Hangup() ; Drop the initial call

; Outbound dialing via SIP trunk  
exten =\> \_0ZXXXXXXXX,1,Set(CALLERID(num)=27871889742)  
same =\> n,Dial(PJSIP/${EXTEN}@${TRUNKOUT})  
same =\> n,Hangup()

; Handle numbers with leading ‘+’  
exten =\> \_+X.,1,Set(STRIPPED=${EXTEN:1})  
same =\> n,Set(CALLERID(num)=27871889742)  
same =\> n,Dial(PJSIP/${STRIPPED}@${TRUNKOUT})  
same =\> n,Hangup()

[from-vphone]  
exten =\> s,1,NoOp(Incoming call from vphone trunk)  
same =\> n,Dial(PJSIP/troxy&PJSIP/tinashe,30)  
same =\> n,Hangup()

[call-transfer-logic]  
exten =\> s,1,Answer() ; Answer the originating call to the extension  
same =\> n,Set(CALLERID(num)=27871889742) ; Set the outbound Caller ID  
same =\> n,Dial(PJSIP/${TARGET\_NUMBER}@${TRUNKOUT},30) ; Dial the target number  
same =\> n,Hangup()

PYTHON AGI SCRIPT  
#!/usr/bin/env python  
import sys  
from asterisk.agi import AGI

agi = AGI()  
originating\_channel = sys.argv[1]  
target\_number = sys.argv[2]

agi.verbose(f"Originating channel: {originating\_channel}, Target number: {target\_number}")

# Get the extension number from the originating channel name (assuming a pattern like PJSIP/201-…)

extension = originating\_channel.split(‘/’)[1].split(‘-’)[0]  
agi.verbose(f"Originating extension: {extension}")

# Originate call to the internal extension

agi.verbose(f"Originating call to {extension}“)  
call1 = agi.originate(f"PJSIP/{extension}”, “call-transfer-logic”, “s”, “1”, async=True)  
agi.verbose(f"Originate call 1 result: {call1}")

# No need to originate the second call here if the dialplan in [call-transfer-logic] handles it.

# The dialplan will be executed when the call to the extension in originate() is answered.

agi.hangup()

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [May 15, 2025, 9:36am UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/5 "2025-05-15T09:36:38Z")

</div>

> [@Tenacious](#):
>
> [2025-05-09 19:22:02] WARNING[1388][C-00000006]: pbx.c:2943 pbx\_extension\_helper: No application ‘AGI’ for extension (from-internal, _123_0677256155, 5)

Presumably res\_agi is not loaded, so you can’t run AGIs.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [May 15, 2025, 10:57am UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/6 "2025-05-15T10:57:50Z")

</div>

@Tenacious I moved your latest post into here, as it is the same fundamental underlying issue/discussion.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [May 15, 2025, 3:23pm UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/7 "2025-05-15T15:23:44Z")

</div>

> [@Tenacious](#):
>
> `same => n,Dial(PJSIP/${TARGET_NUMBER}@${TRUNKOUT},30) ; Dial the target number`

This won’t work, as this is not being run on the channel with the variable (which probably no longer exists at this point), and the variable has not marked to be inherited by created channels, when it was set (I don’t know how well inheritance works for AGI originate, even when properly requested).

---

<div class="post-metadata">

**Author:** ![Tenacious](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/tenacious/32/9115_2.png) [@Tenacious](https://community.asterisk.org/u/Tenacious)\
**Post date:** [May 15, 2025, 3:47pm UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/8 "2025-05-15T15:47:14Z")

</div>

Can you help with a solution to achieve the goal

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [May 15, 2025, 3:56pm UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/9 "2025-05-15T15:56:21Z")

</div>

> **[Variable Inheritance - Asterisk Documentation](https://docs.asterisk.org/Configuration/Dialplan/Variables/Channel-Variables/Variable-Inheritance/)**

---

<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:** [June 14, 2025, 3:57pm UTC](https://community.asterisk.org/t/special-dial-plan-most-probably-needs-agi/108374/10 "2025-06-14T15:57:19Z")

</div>

Closed on June 14, 2025, 3:57pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
