# Re-routing failed calls

**URL:** <https://community.asterisk.org/t/re-routing-failed-calls/80463>\
**Category:** Asterisk Dialplan\
**Created:** [August 1, 2019, 4:52pm UTC](https://community.asterisk.org/t/re-routing-failed-calls/80463 "2019-08-01T16:52:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego.Espinoza](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/diego.espinoza/32/3811_2.png) [@Diego.Espinoza](https://community.asterisk.org/u/Diego.Espinoza)\
**Post date:** [August 1, 2019, 4:52pm UTC](https://community.asterisk.org/t/re-routing-failed-calls/80463/1 "2019-08-01T16:52:12Z")

</div>

Hello community!,

I was trying to figure out if there is a way to re-route **failed calls** instead of just hanging up them

I know that there is a specific variable: DIALSTATUS that takes part of the DIAL command, but i dont know how to use it correctly ☹. _(Maybe i am wrong…)_

A exten =\> example would help **a lot**

**Best regards!**

---

<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:** [August 1, 2019, 5:06pm UTC](https://community.asterisk.org/t/re-routing-failed-calls/80463/2 "2019-08-01T17:06:52Z")

</div>

There is an example, in the sample extensions.conf, of rerouting to voice mail. SImply replace voice mail by Dial.

In practice, you may want to look at HANGUPCAUSE, as well.

---

<div class="post-metadata">

**Author:** ![Diego.Espinoza](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/diego.espinoza/32/3811_2.png) [@Diego.Espinoza](https://community.asterisk.org/u/Diego.Espinoza)\
**Post date:** [August 1, 2019, 9:09pm UTC](https://community.asterisk.org/t/re-routing-failed-calls/80463/3 "2019-08-01T21:09:55Z")

</div>

@david551  
I found the example:

[stdexten]  
${ARG1} - Device(s) to ring

exten =\> \_X.,n,Set(LOCAL(dev)=${ARG1})

exten =\> \_X.,n,Dial(${dev},20)

I dont really get the idea ☹ _(Maybe this wasn’t the example)_

If my first post was not clear, then let me give a example

Lets say that i have 2 gateways,  
GW 1 = Less cost but less prefixes to dial  
GW 2 = High cost and dials everything

You know where this goes

Im trying to Dial always to GW1, but, if it does not take the call, then, i need to re-route the call to GW2

---

<div class="post-metadata">

**Author:** ![johnkiniston](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/johnkiniston/32/28_2.png) [@johnkiniston](https://community.asterisk.org/u/johnkiniston)\
**Post date:** [August 1, 2019, 10:04pm UTC](https://community.asterisk.org/t/re-routing-failed-calls/80463/4 "2019-08-01T22:04:26Z")

</div>

This code isn’t tested, it’s just an example.

```auto
exten => s,1,dial(gateway1/${ARG1)
same => n,Gotoif($[${DIALSTATUS} : "CONGESTION|CHANUNAVAIL"])?GATEWAY2
same => n,playtones(busy)
same => n,busy(16)
same => n,Hangup()
same => n(GATEWAY2),Dial(gateway2/${ARG1})

```

---

<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 31, 2019, 10:04pm UTC](https://community.asterisk.org/t/re-routing-failed-calls/80463/5 "2019-08-31T22:04:38Z")

</div>

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