how to configure asterisk instant messaging
Asked Answered
B

2

6

Does asterisk support instant messages? I have tried to configure asterisk for IM (from this example), but when I'm trying to send IM to another sip account asterisk returns warning:

WARNING[20128]: chan_sip.c:16379 receive_message: Received message to sip:[email protected] from sip:[email protected]; tag=d9fdcc28313946c5a2a6ae1eae997c62, dropped it... Content-Type:text/plain Message: hahaha Additionally the SIP client returns message "method not allowed". This is my sip.conf file:

[general]
context=internal
allowguest=no
allowoverlap=no
bindport=5060
bindaddr=0.0.0.0
srvlookup=no
disallow=all
allow=ulaw
alwaysauthreject=yes
canreinvite=no
nat=yes
session-timers=refuse
localnet=192.168.21.153/255.255.255.0
accept_outofcall_message=yes
outofcall_message_context=internal

[test1]
type=friend
host=dynamic
secret=test1
context=internal

[test2]
type=friend
host=dynamic
secret=test2
context=internal

[test3]
type=friend
host=dynamic
secret=test3
context=internal

And this is my extensions.conf file:

[internal]
exten => test1,1,Answer()
exten => test1,2,Dial(SIP/test1,60)
exten => test1,3,Playback(vm-nobodyavail)
exten => test1,4,VoiceMail(test1@main)
exten => test1,5,Hangup()

exten => test2,1,Answer()
exten => test2,2,Dial(SIP/test2,60)
exten => test2,3,Playback(vm-nobodyavail)
exten => test2,4,VoiceMail(test2@main)
exten => test2,5,Hangup()

exten => test3,1,Answer()
exten => test3,2,Dial(SIP/test3,60)
exten => test3,3,Playback(vm-nobodyavail)
exten => test3,4,VoiceMail(test3@main)
exten => test3,5,Hangup()

exten => 8001,1,VoicemailMain(test1@main)
exten => 8001,2,Hangup()

exten => 8002,1,VoicemailMain(test2@main)
exten => 8002,2,Hangup()

exten => 8003,1,VoicemailMain(test3@main)
exten => 8003,2,Hangup()

exten => _.,1,NoOp(SMS receiving dialplan invoked) 
exten => _.,n,NoOp(To ${MESSAGE(to)}) 
exten => _.,n,NoOp(From ${MESSAGE(from)}) 
exten => _.,n,NoOp(Body ${MESSAGE(body)}) 
exten => _.,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)}) 
exten => _.,n,MessageSend(${ACTUALTO},${MESSAGE(from)}) 
exten => _.,n,NoOp(Send status is ${MESSAGE_SEND_STATUS}) 
exten => _.,n,GotoIf($["${MESSAGE_SEND_STATUS}" != "SUCCESS"]? 
sendfailedmsg) 
exten => _.,n,Hangup() 
exten => h,1,Hangup() 
; 
; Handle failed messaging 
exten => _.,n(sendfailedmsg),Set(MESSAGE(body)="[${STRFTIME(${EPOCH},, 
%d%m%Y-%H:%M:%S)}] Your message to ${EXTEN} has failed. Retry later.") 
exten => _.,n,Set(ME_1=${CUT(MESSAGE(from),<,2)}) 
exten => _.,n,Set(ACTUALFROM=${CUT(ME_1,@,1)}) 
exten => _.,n,MessageSend(${ACTUALFROM},ServiceCenter) 
exten => _.,n,Hangup() 
exten => h,1,Hangup() 
Brooksbrookshire answered 16/4, 2014 at 11:54 Comment(0)
H
9

Yes. Asterisk is supporting IM. Please Use Asterisk 11 or higher version. I think you are using old version. I had same problem in asterisk-10. I upgraded to Asterisk to Asterisk-11. Please see below Detail instruction for Asterisk IM.

Write below line in general section of sip.conf file.

[general]

accept_outofcall_message=yes 
outofcall_message_context=dialplan_name
auth_message_requests=yes

Write below lines in extensions.conf file. This is dialplan to send IM.

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

Add above lines in your respected files. Use Asterisk-11 for IM. I had same problem in older asterisk version. Hope you are using Asterisk-11.

Haggadist answered 16/4, 2014 at 13:27 Comment(2)
@kaushik parmar, can you tell us where we can get the chatplan.php file? Or can you share it if it is your private code? Thanks!Weakkneed
There is typo in declaring variable in ${ACTUALTOS} is actually ${ACTUALTO}Millibar
F
2

After messing a while Asterisk Version 13, got it to work from my celular to another celular. It depends also on the agent doing delivery. if the app or program is not capable of taking the message, there is nothing you can do and you will get this msg:

Unable to create channel of type 'SIP' (cause 58 - Bearer capability not available)

But if the units are capable of messaging then you will get an OK. The best way to test, is first doit on the same unit, you can send and receive a message to yourself. Once you get the msg on your same celular, then you know its working at least in your unit, then you can test in another unit using the same app or program. After you achieve that, then you need to try on a different app or program and unit then debug if does not work.

[MENSAGEIRO]

exten => _.,1,NoOp(SMS receiving dialplan invoked)
exten => _.,n,NoOp(To ${MESSAGE(to)})
exten => _.,n,NoOp(From ${MESSAGE(from)})
exten => _.,n,NoOp(Body ${MESSAGE(body)})
;exten => _.,n,AGI(chatplan.php,${MESSAGE(from)})
exten => _.,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)})
exten => _.,n,ExecIf($["${ACTUALTO}" != "sip:${EXTEN}"]?Set(ACTUALTO=sip:${EXTEN}))
exten => _.,n,MessageSend(${ACTUALTO},${MESSAGE(from)})
exten => _.,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
exten => _.,n,GotoIf($["${MESSAGE_SEND_STATUS}" != "SUCCESS"]?sendfailedmsg)
exten => _.,n,Hangup()
;; Handle failed messaging
exten => _.,n(sendfailedmsg),NoOp(Sending error to user)
exten => _.,n,Set(SRC=${MESSAGE(from)})
exten => _.,n,Set(DST=${MESSAGE(to)})
exten => _.,n,Set(MSG=${MESSAGE(body)})
exten => _.,n,Set(MESSAGE(body)="[${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)}] Sua mensagem para ${EXTEN} falhou. Destinatário não está on-line")
exten => _.,n,Set(ME_1=${CUT(MESSAGE(from),<,2)})
exten => _.,n,Set(ACTUALFROM=${CUT(ME_1,@,1)})
exten => _.,n,MessageSend(${ACTUALFROM},ServiceCenter)
;exten => _.,n,GotoIf($["${INQUEUE}" != "1"]?startq)
exten => _.,n,Hangup()

You need to add those lines in the file extensions.conf and reference in file sip.conf or user.conf using this context called MENSAGEIRO on /etc/asterisk folder.

You wil notice on CLI once you see the msg has gone thru successfully here

 NoOp("Message/ast_msg_queue", "Send status is SUCCESS") in new stack

Credits https://gist.github.com/jugaso/58d76fade445521d7fc15b9c82ee7a50

Flathead answered 20/2, 2020 at 23:26 Comment(2)
Just for safe coding, here the official example and instructions with a working sample code. Asterisk cmd MessageSend ... Take a note Asterisk 11.1.0 has a bug in SIPPEER(ip) that only shows the first two octets of the IP address voip-info.org/asterisk-cmd-messagesendFlathead
Hi, I tried to implement this into my server. It can send the message to server, and it prints as "succes" but i can not receive the message from other device.Landrum

© 2022 - 2024 — McMap. All rights reserved.