There is actually a way to get the extension number based on DID but it’s a really long database query, see below.
mysql -u root -D ombutel -s -N -e "select ext.extension from ombu_extensions ext left join ombu_destinations dest on (dest.index = ext.extension_id) left join ombu_inbound_routes ir on (ir.destination_id = dest.id) left join ombu_destinations_category destcrid on (destcrid.id = dest.category_id) left join ombu_modules module on (destcrid.module_id = module.module_id ) where ir.did = '${var_containing_did}' and module.name = 'extensions';"
I have not tested this from within a dialplan, so I’m not sure if you’ll be able to use root or you’ll have to create a new user and password with access to the ombutel database.