File: jabber.txt

package info (click to toggle)
asterisk 1%3A1.8.13.1~dfsg1-3%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,336 kB
  • sloc: ansic: 497,975; sh: 11,763; cpp: 5,934; makefile: 3,065; perl: 3,019; yacc: 2,147; xml: 498; sql: 387; tcl: 113; php: 62; python: 42
file content (107 lines) | stat: -rw-r--r-- 3,874 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
XMPP (Jabber) is an xml based protocol primarily for presence and messaging.
It is an open standard and there are several open server implementations,
ejabberd, jabberd(2), openfire, and many others, as well as several open source
clients, Psi, gajim, gaim etc. XMPP differs from other IM applications as it
is immensly extendable.  This allows us to easily integrate Asterisk with
XMPP. The Asterisk XMPP Interface is provided by res_jabber.so.

res_jabber allows for Asterisk to connect to any XMPP (Jabber) server and
is also used to provide the connection interface for chan_jingle and
chan_gtalk.

Functions (JABBER_STATUS, JABBER_RECEIVE) and applications (JabberSend)
are exposed to the dialplan.

You'll find examples of how to use these functions/applications
hereafter. We assume that 'asterisk-xmpp' is properly configured in
jabber.conf.

**** JabberSend ****

JabberSend sends an XMPP message to a buddy. Example :

context default {
	_XXXX => {
	      JabberSend(asterisk-xmpp,buddy@gmail.com,${CALLERID(name)} is calling ${EXTEN});
	      Dial(SIP/${EXTEN}, 30);
	      Hangup();
	}
}

**** JABBER_STATUS ****

Note : as of version 1.6, the corresponding application JabberStatus is still
available, but marked as deprecated in favor of this function.

JABBER_STATUS stores the status of a buddy in a dialplan variable for
further use. Here is an AEL example of how to use it :

1234 => {
	Set(STATUS=${JABBER_STATUS(asterisk-xmpp,buddy@gmail.com)});
	if (${STATUS}=1) {
		NoOp(User is online and active, ring his Gtalk client.);
		Dial(Gtalk/asterisk-xmpp/buddy@gmail.com);
	} else {
		NoOp(Prefer the SIP phone);
		Dial(SIP/1234);
	}
}

**** JABBER_RECEIVE ****

JABBER_RECEIVE waits (up to X seconds) for a XMPP message and returns
its content. Used along with JabberSend (or SendText,
provided it's implemented in the corresponding channel type),
JABBER_RECEIVE helps Asterisk interact with users while calls flow
through the dialplan.

JABBER_RECEIVE/JabberSend are not tied to the XMPP media modules
chan_gtalk and chan_jingle, and can be used anywhere in the dialplan.
In the following example, calls targeted to extension 1234 (be it
accessed from SIP, DAHDI or whatever channel type) are controlled by
user bob@domain.com. Asterisk notifies him that a call is coming, and
asks him to take an action. This dialog takes place over an XMPP chat.

context from-ext {
	1234 => {
		Answer();
		JabberSend(asterisk-xmpp,bob@jabber.org,Call from $CALLERID(num) - choose an option to process the call);
		JabberSend(asterisk-xmpp,bob@jabber.org,1 : forward to cellphone);
		JabberSend(asterisk-xmpp,bob@jabber.org,2 : forward to work phone);
		JabberSend(asterisk-xmpp,bob@jabber.org,Default action : forward to your voicemail);
		Set(OPTION=${JABBER_RECEIVE(asterisk-xmpp,bob@jabber.org,20)});
		switch (${OPTION}) {
			case 1:
				JabberSend(asterisk-xmpp,bob@jabber.org,(Calling cellphone...);
				Dial(SIP/987654321);
				break;
			case 2:
				JabberSend(asterisk-xmpp,bob@jabber.org,(Calling workphone...);
				Dial(SIP/${EXTEN});
				break;
			default:
				Voicemail(${EXTEN}|u)
		}
	}
}

When calling from a GoogleTalk or Jingle client, the CALLERID(name)
is set to the XMPP id of the caller (i.e. his JID). In the
following example, Asterisk chats back with the caller identified by the
caller id. We also take advantage of the SendText implementation in
chan_gtalk (available in chan_jingle, and chan_sip as well), to
allow the caller to establish SIP calls from his GoogleTalk client :

context gtalk-in {
	s => {
	  NoOp(Caller id : ${CALLERID(all)});
	  Answer();
	  SendText(Please enter the number you wish to call);
	  Set(NEWEXTEN=${JABBER_RECEIVE(asterisk-xmpp,${CALLERID(name)})});
	  SendText(Calling ${NEWEXTEN} ...);
	  Dial(SIP/${NEWEXTEN);
	  Hangup();
	}
}

The maintainer of res_jabber is Philippe Sultan <philippe.sultan@gmail.com>.