# How to configure instant messaging in Asterisk SIP?

**URL:** <https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533>\
**Category:** Asterisk SIP\
**Created:** [July 31, 2017, 5:22pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533 "2017-07-31T17:22:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [July 31, 2017, 5:22pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/1 "2017-07-31T17:22:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [July 31, 2017, 5:24pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/2 "2017-07-31T17:24:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [July 31, 2017, 5:27pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/3 "2017-07-31T17:27:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [July 31, 2017, 5:30pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/4 "2017-07-31T17:30:11Z")

</div>

i am working on Asterisk 13 in Centos 7.

---

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [July 31, 2017, 5:36pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/5 "2017-07-31T17:36:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![navaismo](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/navaismo/32/2481_2.png) [@navaismo](https://community.asterisk.org/u/navaismo)\
**Post date:** [August 1, 2017, 8:54am UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/6 "2017-08-01T08:54:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [August 1, 2017, 10:45am UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/7 "2017-08-01T10:45:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [August 1, 2017, 2:44pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/8 "2017-08-01T14:44:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [August 1, 2017, 2:53pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/9 "2017-08-01T14:53:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [August 1, 2017, 5:03pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/10 "2017-08-01T17:03:52Z")

</div>

${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.

---

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [August 1, 2017, 6:52pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/11 "2017-08-01T18:52:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [August 1, 2017, 10:31pm UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/12 "2017-08-01T22:31:28Z")

</div>

That is explained by my last point above.

---

<div class="post-metadata">

**Author:** ![13054156-005](https://avatars.discourse-cdn.com/v4/letter/1/90db22/32.png) [@13054156-005](https://community.asterisk.org/u/13054156-005)\
**Post date:** [August 2, 2017, 6:41am UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/13 "2017-08-02T06:41:14Z")

</div>

now what should i do to cover it ?

---

<div class="post-metadata">

**Author:** ![pt039142](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@pt039142](https://community.asterisk.org/u/pt039142)\
**Post date:** [February 28, 2020, 5:02am UTC](https://community.asterisk.org/t/how-to-configure-instant-messaging-in-asterisk-sip/71533/14 "2020-02-28T05:02:54Z")

</div>

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
