How to handle an unresponsive trunk

I’m using the iPad Zoiper app in IAX mode to dial in and want to be able to direct calls to it as well. I’ve got it working well provided the Zoiper app is running, but if I don’t have Zoiper running, what I’d like to do is automatically redirect to voicemail in the PBX. However, I’m not sure how this would be done. What happens now when the app is not running is a call coming into the PBX gets routed to the Zoiper trunk and at that point I relatively soon hear the hangup click, and if I wait long enough I’ll hear the off-hook alarm.

How should I go about catching this condition so I can do the transfer to voicemail? Is there some way to detect that the trunk is essentially dead before routing to it? Or detecting the hangup and handling it? Or that a connection wasn’t made? Some way of pinging the app or otherwise testing for its presence?

Add code immediately after the failing Dial application call.

(If using a GUI, ask on their support board.)