I did something similar for myself nearly 20 years ago with Asterisk, and it was amazingly effective for my home phone. I'd whitelist numbers of friends and family, everyone else had to dial a number to get the phones in the house to ring.
I stopped doing it when I basically switched over to a cell phone as my only phone.
For a while 5 years ago I was getting a ton of spam calls, mostly the "Rachel from Credit Card Services" ones. One to two a day.
After trying the "Press 1 to be put on our do not call" and speaking to a person and asking to be put on their do not call, filing those FTC complaints, and still getting a few a day, I started using a "fake person generator" and just stringing them along. After a couple weeks of this I got one that went along with me for a few minutes and then said "Thank you for playing <my phone number>, you will continue to get calls." and hung up.
This was fantastic, because at the time I had 3 phone numbers associated with my cell phone, and I didn't know which one was getting the calls. I shortly after switched to Google Fi, and ditched the number that they had been calling, and the calls dropped way off.