Twilio essentially provides the phone number. Calls to and from are sent over the internet using the SIP protcol. Twilio can talk to Asterisk or Freeswitch or any similar project. Asterisk has incredible customizability, so that's where I do everything.