login | register
Sun 21 of Mar, 2010 [04:03 UTC]

voip-info.org

History

Asterisk Jabber

Created by: flavour,Last modification on Thu 17 of Sep, 2009 [00:13 UTC] by JustRumours

Jabber is a common name for XMPP-based instant-messaged and communication.

Native jabber support in Asterisk

The Jabber module in Asterisk (res_jabber) is available starting from the 1.4 series. Therefore, you can connect Asterisk as a client (or component) to your Jabber server after you've upgraded to 1.4.

Example 1

Here is a macro that takes a look at the user’s presence and routes the call accordingly : if he is online or chatty the call goes to his desk phone and alerts him over IM - otherwise it goes his mobile phone.


[macro-reach_user_with_presence]
; ${ARG1} is a destination such as SIP/jml-senecio
; ${ARG2} is a jabber address such as jim@jabber.grabeuh.com
; ${ARG3} is a destination such as SIP/whatever
exten => s,1,jabberstatus(asterisk,${ARG2},STATUS)
;presence in will be 1-6.
;In order : Online, Chatty, Away, XAway, DND, Offline
;If not in roster variable will = 7 
exten => s,2,gotoif($[$[${STATUS}]<3]?available:unavailable)
;GotoIf(condition?label_if_true:label_if_false) 
exten => s,3(available),jabbersend(asterisk,${ARG2},"Call from ${CALLERID(name)} at number ${CALLERID(num)} on ${STRFTIME(,GMT-1,%A %B %d %G at %l:%M:%S %p)}")
exten => s,4,Dial(${ARG1})
exten => s,5(unavailable),Dial(${ARG3})



Since we have declared a macro, we have to call it in the context of our choice and assign the relevant values to the macro’s variables:


[whatever_context]
; ${ARG1} is the destination when at desk such as SIP/jim-senecio
; ${ARG2} is a jabber address used at desk such as jim@jabber.grabeuh.com
; ${ARG3} is the destination when not at desk such as SIP/freephonie-out/0666758747
exten => 05600047590,1,Macro(reach_user_with_presence,SIP/jml-senecio,jim@jabber.grabeuh.com,SIP/freephonie-out/0666758747);



That’s all folks ! That is all it takes to have your calls routed to the right phone according to your presence status. It is really that easy.

Example 2

You don't need to run Asterisk as a jabber client, there's also the component way of things: Here's a snippte from the jabber.conf file that allows our Asterisk server to connect to our local XMPP server (jabberd2), as
a component.

 [asterisk-component]
 type=component
 serverhost=jabber.inria.fr
 username=asterisk
 secret=*******
 port=5347

Depending on your XMPP server, the port number may be different.

PHP script for sending jabber messages

I wrote the following PHP script to send a message via the jabber IM service to inform about an incoming call. This can be used for e.g. Asterisk 1.2 that doesn't yet come with native Jabber support.

To get it running you need:

To use it in extensions.conf:
exten => s,1,AGI,jabber.php ; Notify via jabber
exten => s,n,Wait,30        ; Wait thirty second
exten => s,n,Answer         ; Answer the line

Have fun,
-mat-



 #!/usr/bin/php -q
 <?php
 //error_reporting(E_ALL);
 ini_set('display_errors', 0 );
 ini_set('include_path', '.:/usr/share/pear');
 require_once('class.jabber.php');

 ob_implicit_flush(true);
 set_time_limit(0);

 $err=fopen("php://stderr","w");
 $in = fopen("php://stdin","r");
 while (!feof($in)) {
     $temp = str_replace("\n","",fgets($in,4096));
     $s = split(":",$temp);
     $agi[str_replace("agi_","",$s[0])] = trim($s[1]);
     if (($temp == "") || ($temp == "\n")) {
         break;
     }
 }

 $JABBER = new Jabber;

 $JABBER->server   = 'jabber.de.cw.net';
 $JABBER->port     = 5222;
 $JABBER->username = 'asterisk';
 $JABBER->password = 'xxxx';
 $JABBER->resource = 'ClassJabberPHP';

 $JABBER->Connect() or die('Could not connect!');
 $JABBER->SendAuth() or die('Could not authenticate!');

 $JABBER->SendPresence(NULL,NULL,'online');

// $JABBER->SendMessage('xxx@jabber.de.cw.net', 'chat', NULL, array( 'body' => 'Call from '.$agi['callerid'].' on '.$agi['dnid'] ));
 $JABBER->SendMessage('xxx@jabber.de.cw.net', 'chat', NULL, array( 'body' => 'Call from '.htmlspecialchars($agi['callerid']).' on '.$agi['dnid'] ));






 $JABBER->Disconnect();
 fclose($in);
 fclose($err);
 ?>




app_jabber - jabber client as asterisk application

This 3rd party (out-of-tree) asterisk application is a jabber client for use in the dialplan (extensions.conf). It supports multiple jabber accounts, SSL, message send and receive.

sample extensions.conf:
exten => 8013,1,Set(jid=arbeitszimmer/bef@arbeitszimmer)
exten => 8013,2,Set(JABBER_ACK_MSG=you are being called by ${CALLERIDNUM}.)
exten => 8013,3,JabberReceive(${jid},${JABBER_ACK_MSG})
exten => 8013,4,agi(speak.tcl,${JABBER_MSG})
exten => 8013,5,Set(JABBER_ACK_MSG="${JABBER_MSG}" read. please go ahead.)
exten => 8013,6,Goto(3)
exten => 8013,7,Hangup

arbeitszimmer is the name of the configuration section in jabber.conf and also the name of the jabber server (and as such the domain part of the JID).
This configuration is periodically trying to receive a message, which is then acknowledged after it has been read aloud by the festival spech synthesizer.

URL: http://fuhrmannek.de/projects/asterisk/app_jabber.bef


jabber.agi in Python


I've written a Jabber AGI script in Python. It is very simple, using sendxmpp to actually send the Jabber message. You also need pyst for this, which is an AGI interface Python module.

URL: http://www.stuvel.eu/asterisk

OpenFire and Asterisk-IM

The Openfire XMPP server (http://www.igniterealtime.org/) has an asterisk plugin called Asterisk-IM (readme)which uses the manager interface to send 'On the phone' status to XMPP clients. It also has the capability to Pause and Unpause queue members depending on idle status, but that can quickly become. At this moment only the Spark client appears to support this.

ejabberd integration

If you use Asterisk & ejabberd in you company, with this module you can call someone just by sending him short special message, during conversation, e.g. '+'. Phone numbers are retrieved from vcard and command 'originate' is send to AMI.
http://latysheff.googlepages.com/mod_asterisk.erl
Comments are appreciated.


See also



Go back to Asterisk


Comments

Comments Filter
222

333Re: Sending caller ID as a message?

by pmrtvcom, Friday 22 of August, 2008 [10:20:14 UTC]
Of course, that's easy in itself. My particular problem is more "can I send to one or two people depending on the extension being called, and send a supplementary message if, say, a message is left?".
222

333Sending caller ID as a message?

by pmrtvcom, Monday 18 of August, 2008 [08:54:01 UTC]
Is there a way I could send caller ID from Asterisk to the intended recipients of phone calls? Basically, I seek a message of the format:

Call to ${EXTEN} from ${CALLERID(all)}.

(the Jabber client can be set to show the time of the message anyway.)
222

333Routing calls using Jabber presence status

by liotier, Thursday 05 of June, 2008 [23:01:30 UTC]
I was curious so I went playing with it... It works : http://serendipity.ruwenzori.net/index.php/2008/06/05/routing-asterisk-calls-using-jabber-presence-status

222

333Jabber Client + SIP Support

by thetek, Saturday 26 of January, 2008 [01:11:16 UTC]
I would love to see the Jabber client offer SIP support.
222

333Re: windows messenger live support?

by geoff.jacobs, Wednesday 18 of July, 2007 [06:36:28 UTC]
No, MSN is a proprietary protocol and doesn't support jabber. However you can connect to MSN using a jabber client via a jabber server that is running an MSN gateway (such as PyMSNt).
222

333windows messenger live support?

by scarykidsscaringkids, Saturday 14 of October, 2006 [05:20:06 UTC]
Does messenger server support jabber? If so how do i authenticate myself to msn network using jabber.conf?
222

333thank you very much !

by sjobeck, Thursday 25 of August, 2005 [00:21:46 UTC]
Thank you for this. This is a wonderful little piece of code. And an even more wonderful idea.

I hate AIM & MSN & Y!. I prefer ICQ, but even that runs over AOL's network, so, the only real option is to use jabber, and hopefully even an in-house jabber server.

Keep up the great work.

We all look very forward to any possible new versions & features. Keep it up.

Awesome.

Peace.

Jason

222

333Syntax error

by dusty, Thursday 31 of March, 2005 [20:54:26 UTC]
There is a syntax error, can you fix the display please?

Also, is there any way to test the script from the command line?