I do the occasional consult on emergency dialing. This is the framework I start with. It does not require that you anticipate dialed digits it only requires that the outbound call use a route that is marked as an emergency route:
[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf)
exten => s,n,GoSubIf($["${EMERGENCYROUTE}"="YES"]?to-emerg-custom,s,1)
exten => s,n,MacroExit
[to-emerg-custom]
exten => s,1,Noop(Entering user defined context to-emerg-custom in extensions_custom.conf)
; exten => s,n,dumpchan ; uncomment for debug
; additional dialplan lines as req'd
exten => s,n,Return