xmpp asterisk

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:

statusmessage="Asterisk Server"

After, edit /etc/asterisk/extensions.conf and create  from_xmpp context with the following content:


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. 😉

Obs: this post is intended just to discuss XMPP and Asterisk integration so I didn’t list the process_xmpp_msg.agi script contents, because it’s basically used to process the message and search data in DB.

Examples and logs 

Message sent(Pidgin):

(02:53:00 PM) marcelo@xmpp.meudominio.com.br/meuresource: msg 5010 Isso é um teste
(02:53:01 PM) asterisk@xmpp.meudominio.com.br: Message sent. Status: SUCCESS.

Asterisk console:

— Executing [s@from_xmpp:1] NoOp(“Message/ast_msg_queue”, “XMPP Message”) in new stack
— Executing [s@from_xmpp:2] NoOp(“Message/ast_msg_queue”, “To: xmpp:asterisk@xmpp.meudominio.com.br”) in new stack
— Executing [s@from_xmpp:3] NoOp(“Message/ast_msg_queue”, “From: xmpp:marcelo@xmpp.meudominio.com.br/meuresource”) in new stack
— Executing [s@from_xmpp:4] NoOp(“Message/ast_msg_queue”, “Message: msg 5010 Isso é um teste”) in new stack
— Executing [s@from_xmpp:10] NoOp(“Message/ast_msg_queue”, “Sending SIP message”) in new stack
— Executing [s@from_xmpp:11] Set(“Message/ast_msg_queue”, “MESSAGE(body)=Isso é um teste”) in new stack
— Executing [s@from_xmpp:12] MessageSend(“Message/ast_msg_queue”, “sip:5010,sip:5099”) in new stack
— Executing [s@from_xmpp:15] JabberSend(“Message/ast_msg_queue”, “asterisk,marcelo@xmpp.meudominio.com.br/meuresource,Message sent. Status: SUCCESS.”) in new stack

I hope you enjoy this example. It is simple, but next I’ll post another one, that sends a XMPP message to all extensions logged in an Asterisk queue.

Any comments and suggestions, please contact me (mhterres@yahoo.com) so we could discuss more possibilities for this integration.

See you.


You should read too:

Animated Social Media Icons by Acurax Responsive Web Designing Company
Visit Us On FacebookVisit Us On TwitterCheck Our FeedVisit Us On Linkedin