FreePBX | Register | Issues | Wiki | Portal | Support

Freepbx sip messaging


(Imitearc) #1

Hello,
I am looking for an individual who can help me with a freepbx sip messaging and xmpp module configure to send and receive chat between freepbx sip users by Linphone softphone application. I have voice call but I have trouble for text messaging.
I’m using FreePBX 14 and Asterisk 15.5.0

Please let me know. Thanks,


(Dave Burgess) #2

IIRC, the Linphone messaging protocol is proprietary,


(Imitearc) #3

I’m using FreePBX 15 with Asterisk 16.3.0, FreePBX 14 with Asterisk 15.7.2 and Asterisk 15.5.0
I’m using following dialplan and AGI for SIP and the messaging working perfectly for online and offline SIP messaging but when switch to PJSIP does not work at all.
I would appreciate if you can help me to change the dialplan and AGI file for PJSIP.

Thanks in advance for your help.

extensions_custom.conf :

[messages]
exten => _X.,1,NoOp(SMS receiving dialplan invoked)
exten => _X.,n,NoOp(To ${MESSAGE(to)})
exten => _X.,n,NoOp(From ${MESSAGE(from)})
exten => _X.,n,NoOp(Body ${MESSAGE(body)})
exten => _X.,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)})
exten => _X.,n,ExecIf($["${ACTUALTO}" != “sip:${EXTEN}”]?Set(ACTUALTO=sip:${EXTEN}))
exten => _X.,n,MessageSend(${ACTUALTO},${MESSAGE(from)})
exten => _X.,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
exten => _X.,n,GotoIf($["${MESSAGE_SEND_STATUS}" != “SUCCESS”]?sendfailedmsg)
exten => _X.,n,Hangup()
;
; Handle failed messaging
exten => _X.,n(sendfailedmsg),NoOp(Sending error to user)
exten => _X.,n,Set(SRC=${MESSAGE(from)})
exten => _X.,n,Set(DST=${MESSAGE(to)})
exten => _X.,n,Set(MSG=${MESSAGE(body)})
exten => _X.,n,Set(MESSAGE(body)="[${STRFTIME(${EPOCH},%d%m%Y-%H:%M:%S)}] Your message to ${EXTEN} has failed. Sending when available")
exten => _X.,n,Set(ME_1=${CUT(MESSAGE(from),<,2)})
exten => _X.,n,Set(ACTUALFROM=${CUT(ME_1,@,1)})
; Line below disabled for privacy
;exten => _X.,n,MessageSend(${ACTUALFROM},ServiceCenter)
exten => _X.,n,GotoIf($["${INQUEUE}" != “1”]?startq)
exten => _X.,n,Hangup()
;
exten => _X.,n(startq),NoOp(Queueing messaging for offline)
exten => _X.,n,Set(MSGTIME=${STRFTIME(${EPOCH},%d%m%Y-%H:%M:%S)})
exten => _X.,n,System(/var/lib/asterisk/agi-bin/astqueue.sh -SRC ‘${SRC}’ -DST ‘${DST}’ -MSG ‘${MSG}’)
exten => _X.,n,Hangup()
exten => _X.,n(hang),Hangup()

;exten => _X.,n,Hangup()[app-fakeanswer]
;exten => _X.,1,NoCDR
;exten => _X.,n,Set(DESTDEV=${EXTEN})
;exten => _X.,n,Set(THISDEVSTATE=${DEVICE_STATE(SIP/${DESTDEV})})
;exten => _X.,n,GotoIf($["${THISDEVSTATE}" = “UNAVAILABLE”]?hang)
;exten => _X.,n,GotoIf($["${THISDEVSTATE}" = “UNKNOWN”]?hang)
;exten => _X.,n,Answer
exten => _X.,n,Hangup()
exten => _X.,n(hang),Hangup()

[app-fakeanswer]
exten => _X.,1,NoCDR
exten => _X.,n,Set(DESTDEV=${EXTEN})
exten => _X.,n,Set(THISDEVSTATE=${DEVICE_STATE(SIP/${DESTDEV})})
exten => _X.,n,GotoIf($["${THISDEVSTATE}" = “UNAVAILABLE”]?hang)
exten => _X.,n,GotoIf($["${THISDEVSTATE}" = “UNKNOWN”]?hang)
exten => _X.,n,Answer
exten => _X.,n,Hangup()
exten => _X.,n(hang),Hangup()

and
/var/lib/asterisk/agi-bin/astqueue.sh :

!/bin/bash

#VARIABLES
maxretry=525600 #Number of Atempts for sending the sms
retryint=60 #Number of Seconds between Retries
#CONSTANTS
ERRORCODE=0
d_unique=date +%s
d_friendly=date +%T_%D
astbin=which asterisk
myrandom=$[ ( $RANDOM % 1000 ) + 1 ]

function bail()
{
echo “SMS:[$ERRORCODE] $MSGOUT. Runtime:$d_friendly. UniqueCode:$d_unique”
exit $ERRORCODE
}
function gencallfile(){

filename=$1
destexten=$2
source=$3
dest=$4
message=$5
mydate=date +%d%m%y
logdate=date
#dest=echo $dest | grep -d

echo -e "Channel: Local/$destexten@app-fakeanswer
CallerID: $source
Maxretries: $maxretry
RetryTime: $retryint
Context: astsms
Extension: $destexten
Priority: 1
Set: MESSAGE(body)=$message
Set: MESSAGE(to)=$dest
Set: MESSAGE(from)=$source
Set: INQUEUE=1 "> /var/spool/asterisk/temp/$filename

#move files
chown asterisk:asterisk /var/spool/asterisk/temp/$filename
chmod 777 /var/spool/asterisk/temp/$filename
sleep 30
mv /var/spool/asterisk/temp/$filename /var/spool/asterisk/outgoing/

#exit $ERRORCODE
bail
}

while test -n “$1”; do
case “$1” in
-SRC)
source="$2"
echo $source
shift
;;
-DST)
dest="$2"
echo $dest
shift
;;
-MSG)
message="$2"
echo $message
shift
;;
-TIME)
originaltime="$2"
echo $originaltime
shift
;;
esac
shift
done

#[checking for appropriate arguments]
if [[ “$source” == “” ]]; then
echo “ERROR: No source. Quitting.”
ERRORCODE=1
bail
fi

if [[ "$dest" == "" ]]; then
		echo "ERROR: No usable destination. Quitting."
		ERRORCODE=1
		bail
fi

if [[ "$message" == "" ]]; then
		echo "ERROR: No message specified.Quitting."
		ERRORCODE=1
		bail
fi

#[End Argument checking]

#Check to see if extension exist

destexten=echo $dest | cut -d\@ -f1 | cut -d\: -f2
ifexist=$astbin -rx "sip show peers" | grep -c $destexten

if [[ “$ifexist” == “0” ]]; then
echo “Destination extension don’t exist, exiting…”
ERRORCODE=1
baduser=$destexten
destexten=echo $source | cut -d\@ -f1 | cut -d\: -f2
temp=$source
source=$dest
dest=$temp
message=“The user $baduser does not exist, please try your message again using a different recipient.:(”
filename="$destexten-$d_unique.$myrandom.NoSuchUser.call"
gencallfile “$filename” “$destexten” “$source” “$dest” “$message”
bail
fi
#End of Check

#If that conditions pass, then we will queue,
#you can write other conditions too to keep the sanity of the looping
destexten=echo $dest | cut -d\@ -f1 | cut -d\: -f2
filename="$destexten-$d_unique.$myrandom.call"
gencallfile “$filename” “$destexten” “$source” “$dest” “$message”
bail

I’m using these dialplan and AGI for SIP and the messaging working perfectly for online and offline messaging but when switch to PJSIP does not work.
I would appreciate if you can help me to change the dialplan and AGI file for PJSIP.

I would appreciate if you can help me.

Thanks in advance for your help.
I’ll accept if any charges apply.


(Tom Ray) #4

Well first you need to update the dialplan to look and use PJSIP. sip: and SIP/ are for Chan_SIP. To send a message to a PJSIP endpoint it has to be pjsip:${TOUSER} (or xmpp:$(TOUSERURI} for xmpp). As well DEVICE_STATE() needs to be DEVICE_STATE(PJSIP/${DEVICE}) for it to check the proper tech driver for the state.

As you pointed out this is from Asterisk 10/11 well before PJSIP was around so this needs to be adjusted for that.


(Imitearc) #5

Thank you Tom,
I’m using asterisk 15.7.2 and 16.3. I’ll test your suggestion and back to you.
Regards,


(Imitearc) #6

Dear Tom,
I made changes, but still not working. Do you have time to fix it for me. I’ll accept if any charges apply.


(Tom Ray) #7

I’m going to say the same thing I said on the Asterisk forum, post a verbose log of the request being processed.