Script sets fromExten in following order: "FROMEXTEN", "FROM_DID", "REALCALLERIDNUM"
The file name is set as follows: $callFileName = "ondemand-$thisExtension-$fromExten-$timestr-$uniqueid"
The $callFileName file name is then stored in CALLFILENAME variable on the channel and bridge.
When the channel passed to the script is the callers channel FROMEXTEN incorrectly equals THISEXTEN. This logic only works if the callee's channel was passed in, in which case FROMEXTEN and THISEXTEN would be populated correctly. This results in the recording file incorrectly have source extension equal to destination extension.
There are also issues recording calls coming in from a DID, in these cases, recording from the receiving channel results in source extension being the DID. This is incorrect the source should be the external callers number. This is resulting due to $fromExten using FROM_DID.