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 are one of my principal goals. The development of an realtime communication tool with open source software necessarily needs this, technologies and MA Ke It happens is one of my intents.
Nine years ago, since I started to work with Asterisk and OpenFire I ' m studying a-to-do it and when I discovered that Asterisk had improved XMPP support, I noticed that it is the time to make this real.
Using Agis scripts in Python, I started the development of a "tool" so allows users to run commands through their XMPP a Ccount 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 does you need?
You'll need this following items:
A running Asterisk (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 the Asterisk works with your XMPP server. Edit/etc/asterisk/xmpp.conf and create a sessions for you server. Example:
[Asterisk]
Type=client
Serverhost=yourjabberdomain
[Email protected]
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 do I use it?
To ' communicate ' with your Asterisk server just send messages to Asterisk JID configured in your xmpp.conf file example, [email protected]). The message is received in XMPP context (FROM_XMPP context) and stored in ${message} variable. The NoOP commands in the example context is used just to show 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) [Email protected]/meuresource:msg 5010 Issoéum teste
(02:53:01 PM) [Email protected]: Message sent. Status:success.
Asterisk Console:
-executing [[Email protected]_xmpp:1] NoOp ("Message/ast_msg_queue", "XMPP Message") in new stack
-executing [[Email Protected]_xmpp:2] NoOp ("Message/ast_msg_queue", "To:xmpp:[email Protected]") in new stack
-executing [[Email Protected]_xmpp:3] NoOp ("Message/ast_msg_queue", "From:xmpp:[email Protected]/meuresource") in new Stack
-executing [[Email Protected]_xmpp:4] NoOp ("Message/ast_msg_queue", "Message:msg 5010 Issoéum teste") in new stack
-executing [[Email protected]_xmpp:10] NoOp ("Message/ast_msg_queue", "Sending SIP Message") in new stack
-executing [[Email protected]_xmpp:11] Set ("Message/ast_msg_queue", "Message (body) =issoéum teste") in new stack
-executing [[Email Protected]_xmpp:12] Messagesend ("Message/ast_msg_queue", "Sip:5010,sip:5099″") in new stack
-executing [[Email protected]_xmpp:15] Jabbersend ("Message/ast_msg_queue", "Asterisk,[email Protected]/meuresource, Message sent. Status:success. ") In new stack
I Hope you enjoy this example. It's simple, but next I'll post another one, that's sends a XMPP message to all extensions logged on an Asterisk queue.
Any comments and suggestions, please contact me ([e-mail protected]) so we could discuss more possibilities for this Integr ation.
See you.
Continuing my posts of XMPP and VoIP (OpenFire + Asterisk) integration, and after Astdemo tests, it's time to release its Source code to allow others to use its features and maybe create new commands and functionalities.
Astdemo is developed in Python and require a few libs to run (xmpppy, Pyst e psycopg2). You'll need a running Asterisk one (or later) with XMPP support and a running OpenFire Server with ServerInfo Plugin too.
In this first public release, Astdemo have the following features:
- Calls:call to a specific number and plays Tt-monkeys file when the call is answered. This feature demands some permissions to run. Read more in CALLS.txt file.
- Show (Basic) Informations of Asterisk and OpenFire servers.
- Show SIP peers.
- Show IAX peers.
- Show (Basic) Informations of a SIP peer.
- Enable or disable the CallerID XMPP message on received calls to extension.
- Monitor SIP or IAX peers.
- Monitor queues.
- Show your monitoring items.
If you have Asterisk Realtime enabled, you'll have some extra features:
- Show user informations.
- Enable/disable or show status of Do Not Disturb.
- Send a message to all members of a queue.
- Join a queue.
- Leave a queue.
- Show Queue informations (members and statistics).
- Call a SIP extension and transfer it to your extension when answered.
Astdemo is available at GitHub, and I hope it helps their development, specially if more people joins this project. Download Astdemo here or Access project page on Github.
If you is interested in the help Astdemo development, please contact me.
And, if you just want to use it, feel free, but please leave your comments and suggestion in the this page.
Read Astdemo page for more informations.
See you!
XMPP and Asterisk Integration