I'm trying to build an IVR system using Raspberry Pi. See following diagram
I'm not sure which hardware to use for blue and green boxes.
For the blue box maximum number of phones will be 3. They are just normal phones not IP phones. It should work on both ways.
When dialing into the phone number it will play a message and based on user selection (ivr) call will forward to a one of the connected telephones. If user pressed 1 call will goto only "Telephone 1" ect.
Also when someone dialed from "Telephone 1" it should go thru raspberry pi as a normal call.
Can someone suggest hardware (adapter?) to archive this.