Is it possible to catch any DTMF key pressed to stop a Record

Is it possible to catch any DTMF key pressed to stop a Record?

I have written a more Asterisk replacement for the home assistant voip assist. (control your home with voice commands over voip)
Now i wonder is it possible to catch all 0-9 key presses from the record and catch them to do actions based on the keys. (send key 0-9 pressed to home assistant)

 same => n,Set(NEW_FLAG_FILE=/tmp/assist_session_started_${FILE_ID})

; -----------------------------
; Start of loop
 same => n,Playback(${SHELL(/opt/sascha/genttslong.php en "Hello this is sascha")})

 same => n(loop),Set(RECORD_FILE=/tmp/rec_${UNIQUEID}.wav)
 same => n,Set(TRANSCRIPT_FILE=/tmp/stt_${UNIQUEID}.txt)
 same => n,Set(RESPONSE_FILE=/tmp/assist_response_${UNIQUEID}.txt)
 same => n,Set(TRANSCRIPT="")

; Record voice input
same => n,Record(${RECORD_FILE},3,45,ko)
same => n,Playback(${SHELL(/opt/sascha/genttslong.php en "processing")})

; Handle termination keys
same => n,ExecIf($["${RECORD_STATUS}" = "OPERATOR"]?System(echo "Key 0 pressed" > ${TRANSCRIPT_FILE}))

; Only run STT if no termination key was pressed
same => n,ExecIf($["${RECORD_STATUS}" != "OPERATOR"]?TrySystem(/opt/sascha/whisper/stt.py --lang nl ${RECORD_FILE} ${TRANSCRIPT_FILE} || echo '!null!' > ${TRANSCRIPT_FILE} &))


; Transcribe to text
; same => n,TrySystem(/opt/sascha/whisper/stt.py --lang en ${RECORD_FILE} ${TRANSCRIPT_FILE} || echo '!null!' > ${TRANSCRIPT_FILE} &)

; Wait for STT to complete
 same => n(wait_txt),TrySystem(test -s ${TRANSCRIPT_FILE})
 same => n,GotoIf($["${SYSTEMSTATUS}" = "SUCCESS"]?send_to_agent)
 same => n,Wait(0.5)
 same => n,Goto(wait_txt)


; Read transcript
 same => n(send_to_agent),Set(TRANSCRIPT=${SHELL(cat ${TRANSCRIPT_FILE})})
 same => n,NoOp(Transcript: ${TRANSCRIPT})
 same => n,GotoIf($[${REGEX("!null!" ${TRANSCRIPT})}]?loop)


; If NEW_FLAG_FILE doesn't exist, use --new, then create the flag
 same => n,ExecIf($["${STAT(e,${NEW_FLAG_FILE})}" = "1"]?TrySystem(/opt/sascha/cmdline-assist/assist.py --cli --new -a 01hjm970z6c28xctwvzv3vrgws "${TRANSCRIPT}" > ${RESPONSE_FILE}))
 same => n,ExecIf($["${STAT(e,${NEW_FLAG_FILE})}" = "1"]?TrySystem(touch ${NEW_FLAG_FILE}))
 same => n,ExecIf($["${STAT(e,${NEW_FLAG_FILE})}" = "0"]?TrySystem(/opt/sascha/cmdline-assist/assist.py --cli -a 01hjm970z6c28xctwvzv3vrgws "${TRANSCRIPT}" > ${RESPONSE_FILE}))

; Read assistant response and say it
 same => n,Set(ASSIST_OUT=${SHELL(cat ${RESPONSE_FILE} | tr -d '"'\''*[]')})
 same => n,NoOp(Assistant said: ${ASSIST_OUT})
 same => n,Playback(${SHELL(/opt/sascha/genttslong.php en "${ASSIST_OUT}")})

; Repeat loop
 same => n,Wait(1)
 same => n,System(rm ${RECORD_FILE} ${TRANSCRIPT_FILE} ${RESPONSE_FILE})

 same => n,Goto(loop)

same => n(hangup),Hangup()

The Record dialplan application has no such functionality. It just stops recording and doesn’t make the DTMF available for use after.

Oh. Thats a shame.

Note that the AGI command (‘topic?’) record file lets you specify the termination keys. For example:

record file foo wav #*0123456789 1800000 BEEP