Upgrade 3CX to v18 and get it hosted free!

Asterisk cmd GosubIf

Author image

GosubIf

Conditionally jump to a particular priority, extension, or context, saving the return address.

Synopsis

  GosubIf(condition?[label1][:label2])

Asterisk 1.6 and up (?):

  GosubIf(condition?[labeliftrue[(arg1[,...][,argN])]][:labeliffalse[(arg1[,...][,argN])]])

Description

If condition is true and label1 points to a existing context|extension|priority or extension|priority or priority, then jump to that location, saving the return address. If condition is false, the same applies for label2.

Labels take the form ‘[context,]extension,]priority’, so they can be (a) a priority, (b) an extension and a priority, or (c) a context, an extension and a priority.

Return Codes

Returns 0, or -1 if the given context, extension, or priority is invalid.

Example

exten => maincid,1,Set(CALLERID(all)=Some Company <6153824758>)
exten => maincid,2,Return
exten => faxcid,1,Set(CALLERID(all)=Some Company <6153847735>)
exten => faxcid,2,Return

; External local
exten => _9NXXXXXX,1,GosubIf($[${CHANNEL:4:2} = 43]?faxcid,1:maincid,1)
exten => _9NXXXXXX,n,Dial(${TRUNK}/${EXTEN:1},,T)
; External long distance
exten => _91NXXXXXXXXX,1,GosubIf($[${CHANNEL:4:2} = 43]?faxcid,1:maincid,1)
exten => _91NXXXXXXXXX,n,Dial(${TRUNK}/${EXTEN:1},,T)
; External international
exten => _9011.,1,GosubIf($[${CHANNEL:4:2} = 43]?faxcid,1:maincid,1)
exten => _9011.,n,Dial(${TRUNK}/${EXTEN:1},,T)

; New/extended syntax:
GosubIf($[“${CALLERID(num)}” =~ “1234567$”]?dial-some-special,${EXTEN},1(arg1,arg2):dial-as-usually,${EXTEN},1(arg1,arg2))

See also

  • Gosub: Jump to a context/extension/priority (new in v1.2)
  • Return: Return from a subroutine (new in v1.2)
  • Goto: Jump to a context/extension/priority
  • GotoIf: Conditional jump to a context/extension/priority

Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.