Hello,
Thought this might be useful for some… I use FreePBX at home and have a single DID with VoIP.ms. I wanted incoming text messages to be re-broadcast to all the extensions in the house so everyone can see the message. When someone then replies to the incoming text message, I wanted the reply to be re-broadcast to all the extension so everyone knows a reply was sent. I also prefix the reply with the sending extension when it gets re-broadcast to the internal extensions.
To set this up:
- Set the
Message Context
tosms-in
for the VoIP.ms trunk. - Set the
Message Context
tosms-out
for each extension that you want to send text messages from. - Add the following code to the
extensions_custom.conf
file (Found in the Admin → Config Edit page).
a. Note that you will need to skim through the code and update your pbx address, which extensions you want to forward too and your voip.ms server.
[sms-in]
exten => _.,1,NoOp(Inbound SMS dialplan invoked)
exten => _.,n,NoOp(To ${MESSAGE(to)})
exten => _.,n,NoOp(From ${MESSAGE(from)})
exten => _.,n,NoOp(Body ${MESSAGE(body)})
exten => _.,n,Set(HOST_TO=${CUT(MESSAGE(to),@,2)})
exten => _.,n,Set(ACTUAL_FROM=${MESSAGE(from)})
;;;;;;;;;;;;;;; UPDATE EXTENSION NUMBERS HERE ;;;;;;;;;;;;;;;;;;;
; I am using extension 103, 105, 112 and 114. Update as necessary.
exten => _.,n,Gosub(sms-in-broadcast,s,1(${ACTUAL_FROM},103,105,112,114))
exten => _.,n,Hangup()
[sms-out]
exten => _.,1,NoOp(Outbound Message dialplan invoked)
exten => _.,n,NoOp(To ${MESSAGE(to)})
exten => _.,n,NoOp(From ${MESSAGE(from)})
exten => _.,n,NoOp(Body ${MESSAGE(body)})
exten => _.,n,Set(NUMBER_FROM=${CUT(CUT(MESSAGE(from),@,1),:,2)})
exten => _.,n,NoOp(sms-out NUMBER_FROM ${NUMBER_FROM})
exten => _.,n,Set(NUMBER_TO=${CUT(CUT(MESSAGE(to),@,1),:,2)})
exten => _.,n,NoOp(sms-out NUMBER_TO ${NUMBER_TO})
exten => _.,n,Gosub(sms-out-external,s,1(${NUMBER_TO}))
; Prepend the message body with the "From" extension.
; This just makes it easier to notice that these messages
; are re-broadcasts and not from the external sender.
same => n,Set(ORIGINAL_MESSAGE=${MESSAGE(body)})
same => n,Set(NEW_MESSAGE=${NUMBER_FROM}: ${ORIGINAL_MESSAGE})
same => n,Set(MESSAGE(body)=${NEW_MESSAGE})
; Broadcast the sms message to the rest of the phones.
; The "From" address will actually need to be the external phone
; number so the message shows up in the right spot.
;;;;;;;;;;;;;;; UPDATE EXTENSION NUMBERS HERE ;;;;;;;;;;;;;;;;;;;
; I am using extension 103, 105, 112 and 114. Update as necessary.
exten => _.,n,Gosub(sms-out-broadcast,s,1(${NUMBER_TO},${NUMBER_FROM},104,105,112,114))
exten => _.,n,Hangup()
[sms-in-broadcast]
exten => s,1,NoOp(Broadcasting sms to all devices)
same => n,Set(ACTUAL_FROM=${ARG1})
same => n,NoOp(broadcast actual from ${ACTUAL_FROM})
same => n,Set(i=2)
same => n,While($[${i} <= ${ARGC}])
same => n,NoOp(Argument ${i}: ${ARG${i}})
;;;;;;;;;;;;;;; UPDATE PBX ADDRESS HERE ;;;;;;;;;;;;;;;;;;;
same => n,MessageSend(pjsip:${ARG${i}}@pbx.example.com,${ACTUAL_FROM})
same => n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
same => n,Set(i=$[${i} + 1])
same => n,EndWhile
same => n,NoOp(Completed sms incoming broadcast)
same => n,Return()
[sms-out-external]
exten => s,1,NoOp(Sending sms to external number)
;;;;;;;;;;;;;;; UPDATE YOUR PHONE NUMBER HERE ;;;;;;;;;;;;;;;;;;;
exten => _.,n,Set(EXTERNAL_NUMBER_FROM=5555555555)
;;;;;;;;;;;;;;; UPDATE VOIP.MS SERVERS HERE ;;;;;;;;;;;;;;;;;;;
exten => _.,n,Set(ACTUAL_FROM=sip:${EXTERNAL_NUMBER_FROM}@toronto1.voip.ms)
exten => _.,n,Set(ACTUAL_TO=pjsip:VoIP.ms/sip:${ARG1}@toronto1.voip.ms)
exten => _.,n,MessageSend(${ACTUAL_TO},${ACTUAL_FROM})
exten => _.,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
exten => _.,n,NoOp(sms sent externally)
exten => _.,n,Return()
[sms-out-broadcast]
exten => s,1,NoOp(Broadcasting sms to all other devices)
; ACTUAL_FROM is actually the external number we are sending too
; so that the sms shows up in the correct spot on the other devices
; Example formatting:
; "broadcast actual from "5555555555" <sip:[email protected]>"
;;;;;;;;;;;;;;; UPDATE VOIP.MS SERVERS HERE ;;;;;;;;;;;;;;;;;;;
same => n,Set(ACTUAL_FROM="${ARG1}" <sip:${ARG1}@toronto1.voip.ms>)
same => n,Set(i=3)
same => n,While($[${i} <= ${ARGC}])
same => n,NoOp(Argument ${i}: ${ARG${i}})
; Check if the "from extension" is the same we are about to send too.
; If so, skip over this one
same => n,GotoIf($[${ARG${i}} = ${ARG2}]?from_same_extension)
; Send the message:
;;;;;;;;;;;;;;; UPDATE PBX ADDRESS HERE ;;;;;;;;;;;;;;;;;;;
same => n,MessageSend(pjsip:${ARG${i}}@pbx.example.com,${ACTUAL_FROM})
same => n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
same => n(from_same_extension),Set(i=$[${i} + 1])
same => n,EndWhile
same => n,NoOp(Completed sms outgoing broadcast)
same => n,Return()