[AGI] Checking if POTS off-hook?

Hello

At some point in extensions.conf, I need to check if the FXO card is off-hook.

It seems like I need to use CHANNEL STATUS for this, but I didn’t find an example on how how to call this from extensions.conf, and read the result.

Here’s what the script looks like:

exten => s,1,Wait(2)
;If no CID, goto "nocid", else goto "cid"
exten => s,n,GotoIf($[${LEN(${CALLERID(num)})} = 0]?nocid,1:cid,1)
       
;Go off-hook, and prompt user for CID number
exten => nocid,1,Answer()
exten => nocid,n,Read(CALLERID(num),no_cid,10)
exten => nocid,n,GotoIf($[${LEN(${CALLERID(num)})} < 10]?cid,1)
exten => nocid,n,Wait(1)
exten => nocid,n,Hangup()

;If found in DB, rewrite CID name
exten => cid,1,AGI(check_cid.phpcli|${CALLERID(num)}|${CALLERID(name)})
exten => cid,n,Goto(main_menu,s,1)

[main_menu]
;HERE : Need to check status: If on-hook, go off-hook, and answer()

;Play menu to prompt user for extension to call
exten => s,1,Background(main_menu)
exten => s,n,WaitExten(5)
exten => s,n,Hangup()
[...]

Thank you.