Asterisk Jabber Chinese

Jabber 是XMPP的前稱,它建立在XMPP的基礎上,是個即時通訊協定。

jabber 原生支援 Asterisk

Jabber module 在 Asterisk (res_jabber) 1.4 版開始有支援。因此,你可以連到Asterisk作為一個client(或組件)連線到你的 Jabber server。

範例 1

底下這個巨集(macro)會根據使用者的狀態,相應的安排撥打路由:若他在線上,則會撥打他桌上的話機,並經由IM通知他,否則就撥他的手機。



[macro-reach_user_with_presence]
; ${ARG1} 是目地,例:  SIP/jml-senecio
; ${ARG2} 是jabber地址, 例: jim@jabber.grabeuh.com
; ${ARG3} 是目地,例: SIP/whatever
exten => s,1,jabberstatus(asterisk,${ARG2},STATUS)
;狀態 數字是 1-6.
;順序為 : Online, Chatty, Away, XAway, DND, Offline
;若不在上述紀錄裡,則變數 = 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})




我們宣告了一個巨集,我們就可以在 context 裡根據我們的需要呼叫它,並指派相關的數值給這個巨集的變數使用。



[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);



譯者註:以上設定內容只適用於Asterisk 1.4 在 Asterisk 1.6 語法有所不同,請參考 wiki.asterisk

就這樣 ! 撥打的路由會根據你的狀態選擇合適的路由,很簡單啦!

範例 2

你無需讓Asterisk作為一個jabber client,我們一樣使用組件的方法:底下是 jabber.conf 的部份內容,它允許我們的 Asterisk server 連線到本地的 XMPP server (jabberd2),作為一個組件。

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

依據你的 XMPP server, port 位有所不同。

PHP 送 jabber 訊息

我寫了底下的 PHP 腳本來送訊息,經由 jabber IM 服務,通知來電。 可適用於 Asterisk 1.2 即使它仍未支援 Jabber。

系統環境需求:

寫在 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

第3方(out-of-tree) asterisk 應用程式, 是個jabber client端,使用在 dialplan (extensions.conf)。支援多重 jabber 帳號, SSL, 訊息傳送與接收。

範例 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 是設定在 jabber.conf 的名字和server (and as such the domain part of the JID).
此設定週期性的接收訊息, 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


我用Python寫了 Jabber AGI script 。 它很簡單, 使用了 sendxmpp 模組 送Jabber訊息. 你需要這個 pyst for this, 它是個AGI介面Python 模組.

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 modules for Asterisk

mod_asterisk

If you have Asterisk & ejabberd inside your company, make voice calls to a contact you chatting with, by sending special message in chat, e.g. '+'. You don't need to remember contact's phone number, it will be retrieved from contact's vcard, and command Originate sent to AMI.
download http://www.powerpbx.ru/mod_asterisk.erl

mod_client_asterisk

April 2010 we started an Ejabberd module which connect through the Asterisk Manager Interface. This module is looking for call events and updates the status of a known Jabber User. It sort of synchronize jabber users presence based on the phone status. Check it out :
Comments are welcome, please use LaunchPad to submit bugs and ask questions.

See also



Go back to Asterisk

Jabber 是XMPP的前稱,它建立在XMPP的基礎上,是個即時通訊協定。

jabber 原生支援 Asterisk

Jabber module 在 Asterisk (res_jabber) 1.4 版開始有支援。因此,你可以連到Asterisk作為一個client(或組件)連線到你的 Jabber server。

範例 1

底下這個巨集(macro)會根據使用者的狀態,相應的安排撥打路由:若他在線上,則會撥打他桌上的話機,並經由IM通知他,否則就撥他的手機。



[macro-reach_user_with_presence]
; ${ARG1} 是目地,例:  SIP/jml-senecio
; ${ARG2} 是jabber地址, 例: jim@jabber.grabeuh.com
; ${ARG3} 是目地,例: SIP/whatever
exten => s,1,jabberstatus(asterisk,${ARG2},STATUS)
;狀態 數字是 1-6.
;順序為 : Online, Chatty, Away, XAway, DND, Offline
;若不在上述紀錄裡,則變數 = 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})




我們宣告了一個巨集,我們就可以在 context 裡根據我們的需要呼叫它,並指派相關的數值給這個巨集的變數使用。



[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);



譯者註:以上設定內容只適用於Asterisk 1.4 在 Asterisk 1.6 語法有所不同,請參考 wiki.asterisk

就這樣 ! 撥打的路由會根據你的狀態選擇合適的路由,很簡單啦!

範例 2

你無需讓Asterisk作為一個jabber client,我們一樣使用組件的方法:底下是 jabber.conf 的部份內容,它允許我們的 Asterisk server 連線到本地的 XMPP server (jabberd2),作為一個組件。

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

依據你的 XMPP server, port 位有所不同。

PHP 送 jabber 訊息

我寫了底下的 PHP 腳本來送訊息,經由 jabber IM 服務,通知來電。 可適用於 Asterisk 1.2 即使它仍未支援 Jabber。

系統環境需求:

寫在 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

第3方(out-of-tree) asterisk 應用程式, 是個jabber client端,使用在 dialplan (extensions.conf)。支援多重 jabber 帳號, SSL, 訊息傳送與接收。

範例 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 是設定在 jabber.conf 的名字和server (and as such the domain part of the JID).
此設定週期性的接收訊息, 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


我用Python寫了 Jabber AGI script 。 它很簡單, 使用了 sendxmpp 模組 送Jabber訊息. 你需要這個 pyst for this, 它是個AGI介面Python 模組.

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 modules for Asterisk

mod_asterisk

If you have Asterisk & ejabberd inside your company, make voice calls to a contact you chatting with, by sending special message in chat, e.g. '+'. You don't need to remember contact's phone number, it will be retrieved from contact's vcard, and command Originate sent to AMI.
download http://www.powerpbx.ru/mod_asterisk.erl

mod_client_asterisk

April 2010 we started an Ejabberd module which connect through the Asterisk Manager Interface. This module is looking for call events and updates the status of a known Jabber User. It sort of synchronize jabber users presence based on the phone status. Check it out :
Comments are welcome, please use LaunchPad to submit bugs and ask questions.

See also



Go back to Asterisk

Created by: dominic16y, Last modification: Thu 17 of May, 2012 (16:49 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+