Skip to content

Asterisk and FreePBX SMS

HSMM edited this page Nov 5, 2026 · 1 revision

Asterisk and FreePBX: SMS through chan_dongle

Warning. This recipe follows the Asterisk and chan_dongle documentation and has not yet been tried on a live PBX. Treat it as a starting point and watch the Asterisk console (asterisk -rvvv) while you test.

How it works

  1. chan_dongle starts a dialplan channel for an incoming SMS in the context named by context= in dongle.conf, extension sms. The sender number is in CALLERID(num), the text in ${SMS}.
  2. The dialplan turns it into a SIP MESSAGE with MessageSend to the PJSIP endpoint (the extension number).
  3. Asterisk sends the MESSAGE to the Contact that the extension registered, the same path an INVITE takes. So it reaches MacroSIP while MacroSIP is registered as that extension.
  4. A reply from MacroSIP arrives at the PBX as a MESSAGE and lands in the endpoint's message_context. There the dialplan either forwards it to another extension or sends it out through the modem with DongleSendSMS.

FreePBX

FreePBX has no GUI for this. Put the dialplan into /etc/asterisk/extensions_custom.conf and the endpoint option into /etc/asterisk/pjsip.endpoint_custom_post.conf, then run fwconsole reload.

Configuration

; extensions_custom.conf
; incoming SMS from the modem -> extension 1001
[from-dongle-sms]            ; the same name as context= in dongle.conf
exten => sms,1,NoOp(SMS from ${CALLERID(num)}: ${SMS})
 same => n,Set(MESSAGE(body)=${SMS})
 same => n,MessageSend(pjsip:1001,${CALLERID(num)})
 same => n,Hangup()

; messages from MacroSIP: to other extensions, or out through the modem
[messages]
exten => _XXXX,1,MessageSend(pjsip:${EXTEN},${MESSAGE(from)})
 same => n,Hangup()
exten => _+X.,1,DongleSendSMS(dongle0,${EXTEN},${MESSAGE(body)})
 same => n,Hangup()
; pjsip.endpoint_custom_post.conf
[1001](+)
message_context=messages

Replace 1001, dongle0 and the number pattern with your own.

What to expect in MacroSIP

  • The SMS appears as a message from the phone number. Messages must be on in Settings › General › Messages.
  • A reply goes back through the same account.
  • Sent means the PBX accepted the message; the modem and the carrier decide the rest.
  • Without message_context, a message sent from MacroSIP lands in the extension's normal context and is usually refused. MacroSIP then shows Not sent with the SIP code.

Known limits

  • If the extension is registered from two devices, which one receives the MESSAGE depends on the Asterisk version and the AOR settings. Test it.
  • Messages are plain text only.
  • Long SMS are not joined.

See also Messages and Troubleshooting.

Clone this wiki locally