Check the dialstatus variable

Hello everyone,
I am trying to setup a message if the number does not exist or if the line is busy.
When the number doesn’t exist, the dialstatus variable returns CHANUNAVAIL, and when the line is busy it returns BUSY.
There is my dialplan, but the condition does not apply :

[all]
exten => _+.,1,Dial(PJSIP/${EXTEN}@voipms)
same => n,GotoIf($["${DIALSTATUS}" = “BUSY”]?400)
same => n,GotoIf($["${DIALSTATUS}" = “CHANUNAVAIL”]?500)

exten => _+.,400,agi(googletts.agi,"Ligne occupée.",fr,any,1.5)
exten => _+.,500,agi(googletts.agi,"Le numéro n'est pas attribué.",fr,any,1.5)

Is my syntax correct ?
Thanks for the help

Please provide the logs, at at least verbosity 5, and including “pjsip set logger on” output. voipms may not he returning status codes which are recognized as these conditions, or may even be providing them as media rather than SIP codes - which is what you are trying to do!

Also, I’m never quite sure how quoting is handled in Asterisk, so I would avoid spaces around the “=”, although that might not really cause a problem.

It is best practice to use symbolic priorities, rather than hard coding the priority numbers.

If I do :

same => n,agi(googletts.agi,"Statut de l'appel : "${DIALSTATUS},fr,any,1.5)

the TTS is saying the dialstatus variable. If it’s busy it says “BUSY” and if the number does not exist it says “CHANUNAVAIL”, so I guess the value returned by voip.ms is correct.
There is my new syntax I found from the official asterisk doc:

[all]
exten => _+.,1,Dial(PJSIP/${EXTEN}@voipms)
same => n,GotoIf($[ ${DIALSTATUS} = “BUSY”]?400)
same => n,GotoIf($[ ${DIALSTATUS} = “CHANUNAVAIL”]?500)
same => n,agi(googletts.agi,"Statut de l'appel : "${DIALSTATUS},fr,any,1.5)
exten => _+.,400,agi(googletts.agi,"Ligne occupée.",fr,any,1.5)
exten => _+.,500,agi(googletts.agi,"Le numéro n'est pas attribué.",fr,any,1.5)

And there is a part of log, we can see that the GotoIf is testing “0”, but why?

    -- Executing [+xxxxxxxxxxx@Tout:1] Dial("PJSIP/1067-00000df4", "PJSIP/+xxxxxxxxxxx@voipms") in new stack
    -- Called PJSIP/+xxxxxxxxxxxxx@voipms
  == Everyone is busy/congested at this time (1:1/0/0)
    -- Executing [+xxxxxxxxxxxxxxxx@Tout:2] GotoIf("PJSIP/1067-00000df4", "0?400") in new stack
    -- Executing [+xxxxxxxxxx@Tout:3] GotoIf("PJSIP/1067-00000df4", "0?500") in new stack
    -- Executing [+xxxxxxxxxxx@Tout:4] AGI("PJSIP/1067-00000df4", "googletts.agi,"Statut de l'appel : "BUSY,fr,any,1.5") in new stack

We can also see that GoogleAGI got the variable without problem, so it’s the syntax of my gotoif who’s not working

Any chance you actually have 'typographic" or “smart” quotes on the literal?

Tossing in

verbose(1,[${EXTEN}@${CONTEXT}!${DIALSTATUS}]

after the dial may yield a clue.

Gotoif should work, but in case you can try this,

same=>n,Goto(${DIALSTATUS})
same=>hangup()

and of course creating each dial plan line for each possible DIALSTATUS value

Have you tried removing the spaces?

Thanks for the suggestion, finally got it!
There is my dialplan by dial status :

[DialStatus]
exten => n-CHANUNAVAIL,1,agi(googletts.agi,"Le numéro que vous avez composé n'est pas attribué.",fr,any,1.4)
same = n,Hangup()
exten => n-CONGESTION,1,agi(googletts.agi,"Le numéro que vous avez composé n'est pas attribué.",fr,any,1.4)
same = n,Hangup()
exten => n-BUSY,1,agi(googletts.agi,"Toutes les lignes de votre correspondant sont occupées.",fr,any,1.5)
same = n,Hangup()

And there is my dialplan :

exten => _+.,1,Dial(PJSIP/${EXTEN}@voipms)
same = n,Goto(n-${DIALSTATUS},1)
include => DialStatus

I don’t think spaces are the issue. This is from a 17 year old dialplan:

        exten = s,n,                    gotoif($["${ANI}" = "5555555555"]?permit-ani)

It was a long shot, but the dialplan code doesn’t parse down to individual words, but relies on individual applications and functions to do that, so I’m always a bit wary of quotes

I wonder if there is something invisible, like a byte order mark, in the string. The string comparison will not be very intelligent.

However turning the status values into extensions names is the method that I remember seeing in several examples.

Ditto, and I’ve used it as well.

I’d suggest (to the OP) a trip through the source code to enumerate all ${DIALSTATUS} values to flush out the dialplan for reliability.