Execute custom code on beginning of call (inbound route for internal calls)

You do this with a dialplan hook: Hooking for fun and income