Scripts for sending and receiving SMS between FreePBX and Telnyx
Add the dialplan blocks to /etc/asterisk/extensions_custom.conf
, adjusting them according to your environment:
Make a directory under (wwwroot) called sms
and ensure it can be reached by HTTPS from outside.
Place the out.php
and telnyx.php
scripts into sms
and adjust them according to your environment.
out.php:
telnyx.php:
Place the included php-sip
library in a directory of that name under sms
.
Set up a PJSIP trunk for 127.0.0.1 as follows:
Set the Message Context:
...
For each extension that will participate in SMS, set the Account Code to the normalized DID this extension will send and receive as, and set the Message Context:
...
...
Set up a Messaging Profile (APIv2) in Telnyx:
Specify the path to the telnyx.php
script in Inbound Settings:
Copy the Profile Secret from the Outbound Settings section and use it as the token in your out.php
script.
Save this profile and assign it to the DIDs you want to enable for SMS.
SMS from Telnyx will be delivered to the telnyx.php
script specifying a DID. Any extension whose Account Code has that DID will receive the SMS.
SMS from extensions will be sent to Telnyx using the caller ID in the extension's Account Code field. You can only send from numbers that are on your account.
Extensions can text among themselves through the Asterisk dialplan without engaging Telnyx.
These scripts are normalized for US/CAN 10-digit DIDs and would need to be adjusted for international SMS or handling of short codes.