I assumed that if a phone was not registered at the time a message was sent to it from another phone, the PBX would store the message until the next time the target phone registered, but that it not what I am finding. When the phone later registers, the message seems to be lost.
Do I have more work to do in order for the messages to be stored until the extension registers? Or is that the way it is under the most recent FreePBX release?
The way I am handling this is if a phone is unregistered, I send the text by e-mail to the user.
It’s not as elegant a solution as queuing up the messages but in reality phones don’t go unregistered that often.
[messages-in]
; Deliver to local 4-digit extension
exten => _XXXX,1,Set(FROMUSER=${CUT(MESSAGE(from),<,2)})
same => n,Set(FROMUSER=${CUT(FROMUSER,@,1)})
same => n,Set(FROMUSER=${CUT(FROMUSER,:,2)})
same => n,Set(DIALSTRING=${DB(DEVICE/${EXTEN}/dial)})
same => n,Set(TODEVICE=${TOLOWER(${STRREPLACE(DIALSTRING,"/",":")})})
same => n,MessageSend(${TODEVICE},${FROMUSER})
same => n,GotoIf($["${DEVICE_STATE(${DIALSTRING})}" == "UNAVAILABLE"]?messages-in,mail-${EXTEN},1)
same => n,GotoIf($["${MESSAGE_SEND_STATUS}" != "SUCCESS"]?messages-in,mail-${EXTEN},1)
same => n,Hangup()
exten => _mail-X.,1,NoOp(Sending mail to user if vm box exists, else send to catchall)
same => n,Set(MAILADDR=${VM_INFO(${EXTEN:5},email)})
same => n,ExecIf($["${MAILADDR}" == ""]?Set([email protected]))
same => n,System(echo "Text message from ${MESSAGE(from)} to ${EXTEN:5} - ${MESSAGE(body)}" | mail -s "New text received while offline" ${MAILADDR})
same => n,Hangup()
This does two checks to see whether the message was sent. The DEVICE_STATE test checks whether Asterisk knows the device is unregistered. The MESSAGE_SEND_STATUS test checks whether the send failed for any other reason. Oddly, MESSAGE_SEND_STATUS is “SUCCESS” even if I try to send a message to a nonexistant PJSIP contact. So that’s why it has to check twice.