Retrieve the status of a PSTN trunk from Asterisk AMI

I am trying to use ExtensionState action to retrieve the status of a PSTN trunk via Asterisk AMI:

Action: ExtensionState Context: trunks-hintcontext Exten: pstn1

And the response I got is:

Response: Success Message: Extension Status Exten: pstn1 Context: trunks-hintcontext Hint: DAHDI/1 Status: 4

According the AMI documentation, status=4 means “unavailable” but the trunk should be “Idle” as it is available for user to dial and receiving calls.

No matter how I use the pstn trunk, dialing or answering. The Status value is always 1 (In-Use) or 4 (Unavailable).

I expect the status to be “Idle”, “Unavailable”, “In-Use”.

Is there any other AMI action that allow me to retrieve the status of PSTN trunks?

That uses devicestate, which I don’t believe is going to work for DAHDI channels. You might have to use DAHDIShowChannels instead.

DAHDIShowChannels doesn’t show the channel status.