Telegram: Sanitizing command payload

I use telegram to control my heating. /heat or /cold turn on or off. Now I would like to allow optional arguments like /heat 22 to set it to 22°C. I have this working too (see “{{ trigger.event.data.args[0] }}”). But what if I mistype /heat 2Z? The command fails silently. How can I sanitize the payload from telegram. A pseudo-code would be like

case "{{ trigger.event.data.args[0] }}"
  integer between 5 & 25: return '/heat args[0]'
  missing: return '/heat 22'
  else: answer with 'error'