I don’t have my code for Twilio anymore. I use Telnyx now and have code for that. The APIs are very similar.
I worked out a way to use an otherwise unused field in FreePBX extension config to indicate which phones can send and receive SMS and the DID they will send/receive as.
The scripts are a bit much to paste here so I will put them on github.
The components are essentially:
- a php script to receive SMS from the provider’s web API
- another php script to send SMS to the provider’s web API
- some dialplan in the /etc/asterisk/extensions_custom.conf file for routing SMS
- a “loopback” SIP trunk to receive SIP MESSAGEs from the script
- updates to each extension in FreePBX that will use SMS
This will give you the ability to send and receive SMSes from SIP phones that implement the MESSAGE method of sending text. What it doesn’t give you is SMS from the User Control Panel, which is a nice feature but only available now using SIPStation or Clearly IP SIP trunks.
I’ll come back and update the post after I’ve cleaned up my code and put it on github somewhere.