Replying to my own post:
Here is how it can be done:
!
voice translation-rule 2
rule 1 /1001/ /1002/
!
!
voice translation-profile 2
translate called 2
!
!
application
service myapplication flash://myapplication.tcl
!
dial-peer voice 200 pots
destination-pattern 1002
port 2/0
!
dial-peer voice 300 voip
translation-profile outgoing 2
destination-pattern 1001
session target ipv4:172.16.2.2 <------------- This is the CME's IP address
dtmf-relay h245-alphanumeric
codec g711ulaw
no vad
!
dial-peer voice 301 voip
service myapplication
incoming called-number 1002
dtmf-relay h245-alphanumeric
codec g711ulaw
no vad