Can be done with custom dialplan, but not a trivial exercise. You will find an example in this post which you may be able to adapt: