Accept or reject call with IVR and transfer call upon acception

In the Advanced Settings for an extension, you’ll find an option Call Screening, which is very similar to what you are trying to implement. From the tool tip:

Call Screening requires external callers to say their name, which will be played
back to the user and allow the user to accept or reject the call. ...

I suggest you experiment with it. You won’t be able to use it directly, but making a copy of its code and modifying it to meet your needs may be an easy way to achieve your application.

However, can you please explain the overall goal? If you are just trying to filter out spam/scam callers, the simplest IVR will do that. However, desired callbacks from large organizations are often partly automated and will fail to operate the IVR. Unfortunately, asking a robot to say his name would have the same problem.

This thread may be useful:

If most of the calls you receive without CID are ‘straightforwardly’ blocked (by dialing a code or asking the carrier to hide caller ID), you may be able to reveal them with a DID that passes ANI information. Assuming that the number in question is in the Netherlands, take a look at AnveoDirect (US based but has a POP in Germany) and Voxbeam (UK based with a POP in the Netherlands).