How to configure instant messaging in Asterisk SIP?

i am facing problems in configuring IM in Asterisk SIP kindly help me to solve it.

You haven’t provided enough information, such as what you are trying to accomplish, the clients you are using, or what you’ve tried to do.

i am doing my final year project using SIP asterisk .Now i am stucked in IM .i am using x-lite soft phone for communication. After typing message it does’nt send message.

i am working on Asterisk 13 in Centos 7.

i am doing my final year project using SIP asterisk .Now i am stucked in IM .i am using x-lite soft phone for communication. After typing message it does’nt send message.

Show us your configuration of the handling context, sip.conf and the output of the CLI when you send it.

Does X-Lite even support this? It’s a loss leader product, so I wouldn’t expect any bells and whistles.

As others have said, you cannot expect an answer to such an open question on a peer support forum.

here is my configurations
sip.conf:
[astsms]
bindaddr=0.0.0.0
host=dynamic
context=astsms
nat=no
secret=1234
disallow=all
allow=ulaw
allow=alaw
notifycid=yes
outofcall_message_context=astsms
accept_outofcall_message=yes

ahmad
defaultuser=ahmad
secret=1234
subscribecontext=default
allowsubscribe=yes

sharaq
defaultuser=sharaq
secret=1234
subscribecontext=default
allowsubscribe=yes

and i found this code for exensions
extensions.conf::

exten => 200,hint,SIP/201&SIP/202&SIP/203
exten => 200,1,NoOp(SMS receiving dialplan invoked)
exten => 200,n,NoOp(To ${MESSAGE(to)})
exten => 200,n,NoOp(From ${MESSAGE(from)})
exten => 200,n,NoOp(Body ${MESSAGE(body)})
exten => 200,n,AGI(chatplan.php,${MESSAGE(from)})
exten => 200,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)})
exten => 200,n,ExecIf($["${ACTUALTO}" != “sip:${EXTEN}”]?Set(ACTUALTO=sip:${EXTEN}))
exten => 200,n,MessageSend(${ACTUALTOS},${MESSAGE(from)})
exten => 200,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
exten => 200,n,GotoIf($["${MESSAGE_SEND_STATUS}" != “SUCCESS”]?sendfailedmsg)
exten => 200,n,Hangup()
;
; Handle failed messaging
exten => 200,n(sendfailedmsg),NoOp(Sending error to user)
exten => 200,n,Set(SRC=${MESSAGE(from)})
exten => 200,n,Set(DST=${MESSAGE(to)})
exten => 200,n,Set(MSG=${MESSAGE(body)})
exten => 200,n,Set(MESSAGE(body)="[${STRFTIME(${EPOCH},%d%m%Y-%H:%M:%S)}] Your message to ${EXTEN} has failed. Sending when available")
exten => 200,n,Set(ME_1=${CUT(MESSAGE(from),<,2)})
exten => 200,n,Set(ACTUALFROM=${CUT(ME_1,@,1)})
exten => 200,n,MessageSend(${ACTUALFROM},ServiceCenter)
exten => 200,n,GotoIf($["${INQUEUE}" != “1”]?startq)
exten => 200,n,Hangup()
;;
exten => 200,n(startq),NoOp(Queueing messaging for offline)
exten => 200,n,Set(MSGTIME=${STRFTIME(${EPOCH},%d%m%Y-%H:%M:%S)})
exten => 200,n,SYSTEM(/var/lib/asterisk/agi-bin/astqueue.sh –SRC ‘${SRC}’ –DST ‘${DST}’ –MSG ‘${MSG}’)
exten => 200,n,Hangup()[app-fakeanswer]
exten => 200,n,NoCDR
exten => 200,n,Set(DESTDEV=${EXTEN})
exten => 200,n,Set(THISDEVSTATE=${DEVICE_STATE(SIP/${DESTDEV})})
exten => 200,n,GotoIf($["${THISDEVSTATE}" = “UNAVAILABLE”]?hang)
exten => 200,n,GotoIf($["${THISDEVSTATE}" = “UNKNOWN”]?hang)
exten => 200,n,Answer
exten => 200,n,Hangup()
exten => 200,n(hang),Hangup()

same code for other exensions.
in CLI it shows the following warning.
[Aug 1 19:40:51] WARNING[2266][C-00000000] message.c: A ‘to’ URI is required for MessageSend()
While in x-lite 4.9 it shows this :"[01082017-19:40:51] Your message to 200 has failed. Sending when available" but user is available on other PC.

here is my configurations
sip.conf:
[astsms]
bindaddr=0.0.0.0
host=dynamic
context=astsms
nat=no
secret=1234
disallow=all
allow=ulaw
allow=alaw
notifycid=yes
outofcall_message_context=astsms
accept_outofcall_message=yes

ahmad
defaultuser=ahmad
secret=1234
subscribecontext=default
allowsubscribe=yes

sharaq
defaultuser=sharaq
secret=1234
subscribecontext=default
allowsubscribe=yes

and i found this code for exensions
extensions.conf::

exten => 200,hint,SIP/201&SIP/202&SIP/203
exten => 200,1,NoOp(SMS receiving dialplan invoked)
exten => 200,n,NoOp(To ${MESSAGE(to)})
exten => 200,n,NoOp(From ${MESSAGE(from)})
exten => 200,n,NoOp(Body ${MESSAGE(body)})
exten => 200,n,AGI(chatplan.php,${MESSAGE(from)})
exten => 200,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)})
exten => 200,n,ExecIf($["${ACTUALTO}" != “sip:${EXTEN}”]?Set(ACTUALTO=sip:${EXTEN}))
exten => 200,n,MessageSend(${ACTUALTOS},${MESSAGE(from)})
exten => 200,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
exten => 200,n,GotoIf($["${MESSAGE_SEND_STATUS}" != “SUCCESS”]?sendfailedmsg)
exten => 200,n,Hangup()
;
; Handle failed messaging
exten => 200,n(sendfailedmsg),NoOp(Sending error to user)
exten => 200,n,Set(SRC=${MESSAGE(from)})
exten => 200,n,Set(DST=${MESSAGE(to)})
exten => 200,n,Set(MSG=${MESSAGE(body)})
exten => 200,n,Set(MESSAGE(body)="[${STRFTIME(${EPOCH},%d%m%Y-%H:%M:%S)}] Your message to ${EXTEN} has failed. Sending when available")
exten => 200,n,Set(ME_1=${CUT(MESSAGE(from),<,2)})
exten => 200,n,Set(ACTUALFROM=${CUT(ME_1,@,1)})
exten => 200,n,MessageSend(${ACTUALFROM},ServiceCenter)
exten => 200,n,GotoIf($["${INQUEUE}" != “1”]?startq)
exten => 200,n,Hangup()
;;
exten => 200,n(startq),NoOp(Queueing messaging for offline)
exten => 200,n,Set(MSGTIME=${STRFTIME(${EPOCH},%d%m%Y-%H:%M:%S)})
exten => 200,n,SYSTEM(/var/lib/asterisk/agi-bin/astqueue.sh –SRC ‘${SRC}’ –DST ‘${DST}’ –MSG ‘${MSG}’)
exten => 200,n,Hangup()[app-fakeanswer]
exten => 200,n,NoCDR
exten => 200,n,Set(DESTDEV=${EXTEN})
exten => 200,n,Set(THISDEVSTATE=${DEVICE_STATE(SIP/${DESTDEV})})
exten => 200,n,GotoIf($["${THISDEVSTATE}" = “UNAVAILABLE”]?hang)
exten => 200,n,GotoIf($["${THISDEVSTATE}" = “UNKNOWN”]?hang)
exten => 200,n,Answer
exten => 200,n,Hangup()
exten => 200,n(hang),Hangup()

same code for other exensions.
in CLI it shows the following warning.
[Aug 1 19:40:51] WARNING[2266][C-00000000] message.c: A ‘to’ URI is required for MessageSend()
While in x-lite 4.9 it shows this :"[01082017-19:40:51] Your message to 200 has failed. Sending when available" but user is available on other PC.

${ACTUAL_TOS} is an undefined variable.

Setting ${ACTUAL_TO} and then changing it to something else if it wasn’t set to same something else seems a waster of effort.

The synopsis of MessageSend requires a URI, ${ACTUAL_TO} is not a URI, so, even if you passed the right variable, I can’t see its working.

1 Like

now it is showing this msg:
WARNING[2294][C-00000000]: chan_sip.c:6277 create_addr: Purely numeric hostname (200), and not a peer–rejecting!
i am confused and i have short time for it .kindly if someone else have any other solution for it kindly share with me.

That is explained by my last point above.

now what should i do to cover it ?

I want after call hangup asterisk automatically send message on same no where call comes from
Here is my AGI scipt in php
#!/usr/bin/php -q

<?php declare(ticks = 5000); set_time_limit(60); include("phpagi.php"); include("sql.php"); include("promotion.php"); $AGI = new AGI(); $db = new AGIDB($AGI); pcntl_signal(SIGHUP,"sig_handler"); $isPromotionIsCorrect = false; switch ($AGI->request[promotion_code]) { case 'promotion_code': $keyPress = $AGI->request[agi_extension]; list($featuresCode,$promotionCode) = explode("*",$keyPress); // validatePromotionCode is a function in promotion.php that return true of false $isPromotionIsCorrect = validatePromotionCode($promotionCode); if($isPromotionIsCorrect) { $streamFile = 'promotion-code-correct'; } else { $streamFile = 'promotion-code-incorrect'; } $AGI->stream_file($streamFile); $AGI->hangup(); exit; break; } function sig_handler($signo) { global $isPromotionIsCorrect,$promotionCode; if($isPromotionIsCorrect) { // updateCode is a function in promotion.php that will update the code updateCode($promotionCode); } exit; } ?>

Here is Extensions.conf
[SMS]

exten => 5000,1,Answer
exten => 5000,n,AGI(promotion_checking.php)
exten => 5000,n,Hangup

exten => 5000,1,Answer()
exten => 5000,n,Playback(/var/lib/asterisk/sounds/custom/tt-monkeys)
exten => 5000,Dial(SIP/5000)
same => n,NoOp(before hangup)
exten => h,1,AGI(promotion_checking.php)
same => n,Hangup

exten => 4000,1,Answer()
exten => 4000,n,Playback(/var/lib/asterisk/sounds/custom/tt-monkeys)
exten => 4000,Dial(SIP/4000)
same => n,NoOp(before hangup)
exten => h,1,AGI(promotion_checking.php)
same => n,Hangup

exten => 4000,1,Set(ACTUALTO={CUT(MESSAGE(to),@,1)}) same => 4000,n,MessageSend({ACTUALTO},${MESSAGE(from)})
same => 4000,n,Hangup
exten => h,1,AGI(promotion_checking.php)

exten => 5000,1,Set(ACTUALTO={CUT(MESSAGE(to),@,1)}) same => 5000,n,MessageSend({ACTUALTO},${MESSAGE(from)})
same => 5000,n,Hangup
exten => h,1,AgI(promotion_checking.php)

Here is Sip.conf
[4000]
username=4000
secret=asdf@#$4000
type=friend
context=SMS
host=dynamic
dtmfmode=rfc2833
insecure=invite,port
canreinvite=no
nat=yes
qualify=yes

[5000]
username=5000
secret=asdf@#$5000
type=friend
context=SMS
host=dynamic
dtmfmode=rfc2833
insecure=invite,port
canreinvite=no
nat=yes
qualify=yes

I don,t Know why message is not sending please help me out