Call forward to an external number

If you want a local redirection, you just need to make sure that the target number is in the context used to dial, or in the transfer context (set with a channel variable, I think, but I don’t remember the details). promiscredir is for when you want the new contact URI to be used literally.

1 Like

In the way it’s being used, it’s so that someone can put a call forward to a mobile from the phone if they’re going to be away from the desk; for this reason we won’t be able to keep all the numbers in the context. It appears any number that is put into the phone that has @trunkdomain after it, with promiscredir enabled will work, however, I’m just hoping for a way the suffix of @trunkdomain could be appended after the number?

Could there be a way of appending it to any number coming through the PBX perhaps, as this won’t affect outbound traffic to my knowledge?

1 Like

In that case, the correct way is with the forwarding context, rather then promiscuous redirection:

1 Like

@meightee

Hi Meightee,

I’m giving the config you shared here a go, but I’m coming across errors with the macro part? Was this designed for a specific use? I’m just trying to get a simple unconditional call forward working so users can turn it on and off at will, which I believe will solve this without needing to go any further?

I’m using Asterisk v13.19.0 if this helps.

Many thanks,

Richard

1 Like

No specific use, Ive used the following information:

https://www.voip-info.org/wiki/view/Asterisk+call+forwarding

You do need to check if there is a callforward on an extension before routing an incomming call to that extension.

1 Like

Hi Meightee,

Thanks for getting back to me.

Sorry for being a bit nooby, what what did you mean by the below?

Does this need to be set up in extensions.conf before I attempt to then add in the call forwarding script?

1 Like

When there is an call for an extension, you have to check if there is callforward set on that extension.

1 Like

The callforwarding script is noramaly called by dialing 21callforward_number

But when you call an extension, you have to check if a callforward is set on the extension that is called.

1 Like

Thank you, that makes more sense now - just had to read it right!

I’ll give this more of a go, I’ve got in touch with the gent who originally wrote the doc at https://www.voip-info.org/wiki/view/Asterisk+call+forwarding, so hopefully it’ll come together. Just need to get the syntax in version 13 working with the examples :smiley:

1 Like

I got it resolved! I used the code that @meightee used before and got it working with the platform, thank you so much!

Just if anyone else runs into a similar issue, I have the following:

exten => NUMBER,n,Macro(callforwarding,EXT)

For example:

[incoming]
exten => NUMBER,1,SIPAddHeader(Alert-Info: )
exten => NUMBER,n,Playback(/var/lib/asterisk/sounds/custom/Mainline)
exten => NUMBER,n,Macro(callforwarding,100)
exten => NUMBER,n,Dial(SIP/100,30)
exten => NUMBER,n,Voicemail(100)

Then with a context:

[macro-callforwarding]
;Unconditional call forward
exten => s,1,Set(temp=${DB(CFIM/${ARG1})})
exten => s,n,GotoIf(${temp}?cfi:nocfi)
exten => s,n(cfi),NoOp( CFI Found)
exten => s,n,Dial(SIP/${temp}@tr-gamma)
exten => s,n,Hangup()
exten => s,n(nocfi),NoOp(No CFI found)

Within sip-main:

exten => _21.,1,Answer()
same => n,Set(DB(CFIM/${CALLERID(NUM)})=${EXTEN:4})
same => n,Playback(vm-saved)
same => n,SayDigits(${EXTEN:4})
same => n,Hangup()

exten => _**21,1,Answer()
same => n,DBdel(CFIM/${CALLERID(num)})
;same => n,Playback(call-fwd-cancelled)
same => n,Hangup()

include => macro-callforwarding

Thank you so much for all your help :smiley:

1 Like

You should be using subroutines and not Macro’s

[incoming]
exten => NUMBER,1,SIPAddHeader(Alert-Info: )
exten => NUMBER,n,Playback(/var/lib/asterisk/sounds/custom/Mainline)
exten => NUMBER,n,Gosub(sub-callforwarding,s,1(100))
exten => NUMBER,n,Dial(SIP/100,30)
exten => NUMBER,n,Voicemail(100)


[callforwarding]
exten => _21.,1,Answer()
same => n,Set(DB(CFIM/${CALLERID(NUM)})=${EXTEN:4})
same => n,Playback(call-forwarding&enabled&to-extension)
same => n,SayDigits(${EXTEN:4})
same => n,Hangup()

exten => _**21,1,Answer()
same => n,DBdel(CFIM/${CALLERID(num)})
same => n,Playback(call-forwarding&disabled)
same => n,Hangup()

[sub-forwarding]
exten => s,1,NoOP()
 same => n,GotoIf($[${DB_EXISTS(CFIM/${ARG1})}]?cfi:nocfi)
 same => n(cfi),Dial(SIP/${DB(CFIM/${ARG1})}@tr-gamma)
 same => n,Hangup()
 same => n(nocfi),Return()

You can just

include => callforwarding
for this one to work.

1 Like