http://www.mundoopensource.com.br/en_page_xmpp_asterisk_pratical_example/
www.mundoopensource.com.br/xmpp-asterisk-integration-practical-example-part-2/
In past few years integrate XMPP and Asterisk is one of my principal goals. The development of an realtime communication tool with open source software necessarily needs this two technologies and make it happens is one of my intents.
Nine years ago, since I started to work with Asterisk and Openfire I’m studying a way to do it and when I discovered that Asterisk 11 had improved xmpp support, I noticed that it was the time to make this real.
Using AGIs scripts in python, I started the development of a “tool” that allows users to run commands through their xmpp account in their preferred xmpp client (Pidgin, for example). The current version of my software permits:
Send SIP messages to an extension
Send text messages (SMS)
Enable/disable DND for extension
Enable/disable divert for extension
Queue logon/logoff
Show extension informations
Show queue informations
Send XMPP message to all extensions logged in a queue
Show SIP and IAX peers informations
And other resources under development
For it works you’ll need to create a column in your SIP table to store the extension’s JID. I created a column named JID in my sippeers table.
Now I’ll show you a practical example of this integration.
What do you need?
You’ll need this following items:
A running Asterisk 11 (at least) with res_xmpp support configured.
A running XMPP server (Openfire 3.9.3 is a good one)
A JID account for your Asterisk (to use in res_xmpp)
And now ?
First you need to make Asterisk works with your XMPP server. Edit /etc/asterisk/xmpp.conf and create a sessions for you server. Example:
[asterisk]
type=client
serverhost=yourjabberdomain
username=asterisk@yourjabberdomain
secret=password
priority=1
usetls=yes
port=5222
usesasl=yes
status=available
statusmessage="Asterisk Server"
endtodialplan=yes
context=from_xmpp
keepalive=yes
After, edit /etc/asterisk/extensions.conf and create from_xmpp context with the following content:
[from_xmpp]
exten => s,1,NoOp(XMPP Message)
same => n,NoOp(To: ${MESSAGE(to)})
same => n,NoOp(From: ${MESSAGE(from)})
same => n,NoOp(Message: ${MESSAGE(body)})
same => n,NoOp(Sending SIP message)
; AGI that process message and get the following variables
; ${XMPP_MSG} - message text
; ${XMPP_SIPDEST} - to extension
; ${XMPP_SIPORIG} - from extension
same => n,agi(process_xmpp_msg.agi)
; Set ${XMPPRESOURCE} = session name in xmpp.conf file (can be a global variable)
same => n,Set(XMPPRESOURCE=asterisk)
same => n,Set(MESSAGE(body)=${XMPP_MSG})
same => n,MessageSend(sip:${XMPP_SIPDEST},sip:${XMPP_SIPORIG})
same => n,JabberSend(${XMPPRESOURCE},${MESSAGE(from):5},"Message sent. Status:${MESSAGE_SEND_STATUS}). )
How to use it?
To “communicate” with your Asterisk server just send messages to Asterisk JID configured in your xmpp.conf file (in this example, asterisk@yourjabberdomain). The message will be received in xmpp context (from_xmpp context) and stored in ${MESSAGE} variable. The NoOP commands in the example context are used just to show you how Asterisk processes the message.
UPDATE: some readers ask me to send my process_xmpp_msg.agi. You can get it here. It was adapted from my original script, so I hope it is working.