there is a guy here in canada that has this pretty much built.
he own's pennytel.ca Name is Phillip Mullis. Awesome guy. He might lend some code. PM me if you want his contact info.
kazoo uses freeswitch and kamailio so its more stable than freepbx, its meant for larger deployments though with multiple nodes. would rank as fairly heavy for a rasberry pi or small device. still a good option though.