<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2180" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Bom dia,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Estive tentando acessar um servidor Asterisk a 
partir de uma máquina Windows&nbsp;realizar uma ligação e transferir&nbsp;para 
um atendente.</FONT></DIV>
<DIV><FONT face=Arial size=2>Com isso descubri várias facilidades do Asterisk e 
resolvi enviar para a lista algumas coisas interessantes na minha opinião para 
resolver o problema.</FONT></DIV>
<DIV><FONT face=Arial size=2>A primeira coisa que me apareceu foi o Asterisk 
Manager API. Uma interface que disponibiliza acesso&nbsp;ao Asterisk via 
protocolo TCP/IP.</FONT></DIV>
<DIV><FONT face=Arial size=2>Para utilizar o Asterisk Manager basta habilitar o 
serviço editando o arquivo de configuração 
<STRONG>"/etc/asterisk/manager.conf</STRONG>" como no exemplo 
abaixo:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><STRONG><SPAN style="FONT-FAMILY: monospace">; </SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;;&nbsp;Asterisk&nbsp;Call&nbsp;Management&nbsp;support 
</SPAN><BR><SPAN style="FONT-FAMILY: monospace">&nbsp;; </SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;[general] </SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;enabled&nbsp;=&nbsp;yes </SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;port&nbsp;=&nbsp;5038&nbsp; 
</SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;bindaddr&nbsp;=&nbsp;0.0.0.0 
</SPAN><BR><BR><SPAN style="FONT-FAMILY: monospace">&nbsp;[mark] 
</SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;secret&nbsp;=&nbsp;mysecret 
</SPAN><BR><SPAN style="FONT-FAMILY: monospace">&nbsp;deny=0.0.0.0/0.0.0.0 
</SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;permit=209.16.236.73/255.255.255.0 
</SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;permit=127.0.0.1/255.255.255.0 
</SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;read&nbsp;=&nbsp;system,call,log,verbose,command,agent,user 
</SPAN><BR><SPAN 
style="FONT-FAMILY: monospace">&nbsp;write&nbsp;=&nbsp;system,call,log,verbose,command,agent,user</SPAN></STRONG></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Para verificar 
se tudo funcionou basta acessar o servidor Asterisk através de outra máquina com 
Windows entrando via Telnet. Com um comando como o abaixo:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>telnet 192.168.0.1 
5038</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Irá aparecer a 
seguinte mensagem:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Asterisk Call 
Manager/1.0</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Agora basta 
digitar:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN><SPAN 
style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Action: 
login</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Username: 
mark</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Secret: 
mysecret</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Obs: Lembrando 
que qualquer caracter digitado errado, mesmo sendo apagado depois e corrigido 
faz com que o comando não funcione. Por isso não se preocupe se digitar uma 
palavra errada e depois apagar e o comando não funcionar. Basta digitar de novo 
sem errar nada. Para que isso não ocorra aconselho que tudo seja digitado em um 
bloco de notas e depois copiado para o prompt do DOS. Evitando erros e gardando 
para futura utilização dos comandos.</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>E dar dois 
[<STRONG>enter</STRONG>].</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>E irá aparecer 
a mensagem:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Response: 
Success</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Message: Authentication 
accepted</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG></STRONG></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Para realizar 
uma ligação e tranferir para um ramal pode-se usar o comando 
<STRONG>originate</STRONG>. Como no exemplo:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Action: Originate<BR>Channel: 
SIP/123<BR>Context: default<BR>Exten: 123</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Priority: 
1</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN><SPAN 
style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Neste exemplo 
eu liguei para meu próprio softphone e transferi a ligação para mim 
também.</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Para sair 
basta digitar:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>action: 
logoff</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>E terá como 
resposta:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Response: Goodbye<BR>Message: 
Thanks for all the fish.</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>Conexão ao host 
perdida.</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Blz, mas e ai 
toda vez q eu for ligar vou precisar ir no telnet?</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Com isso 
cheguei ao <STRONG>Asterisk-Java</STRONG>. Uma biblioteca de classes em java 
para facilitar o acesso ao Asterisk Manager.</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Para utilizar 
o Asterisk-Java basta criar um projeto em java e importar o arquivo .jar do 
Asterisk-Java para o projeto.</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Após isso é só 
criar uma classe utilizando essa biblioteca. Como no exemplo 
abaixo:</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>import 
java.io.IOException;</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>import 
org.asteriskjava.manager.AuthenticationFailedException;<BR>import 
org.asteriskjava.manager.ManagerConnection;<BR>import 
org.asteriskjava.manager.ManagerConnectionFactory;<BR>import 
org.asteriskjava.manager.ManagerEventListener;<BR>import 
org.asteriskjava.manager.TimeoutException;<BR>import 
org.asteriskjava.manager.action.StatusAction;<BR>import 
org.asteriskjava.manager.event.ManagerEvent;</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>public class HelloEvents 
implements ManagerEventListener<BR>{<BR>&nbsp;&nbsp;&nbsp; private 
ManagerConnection managerConnection;</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp; public 
HelloEvents() throws IOException<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ManagerConnectionFactory factory 
= new 
ManagerConnectionFactory(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
"192.168.0.1", "mark", "mysecret");</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN 
style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
this.managerConnection = 
factory.createManagerConnection();<BR>&nbsp;&nbsp;&nbsp; }</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp; public void 
run() throws IOException, 
AuthenticationFailedException,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
TimeoutException, InterruptedException<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // register for 
events<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
managerConnection.addEventListener(this);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // connect to Asterisk and log 
in<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
managerConnection.login();</STRONG></SPAN></DIV>
<DIV><SPAN 
style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<FONT size=2>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
    <P align=left></FONT><FONT size=3>OriginateAction originateAction = <B><FONT 
    color=#7f0055>new</B></FONT></FONT> OriginateAction();</P>
    <P align=left>originateAction.setChannel(<FONT 
    color=#2a00ff>"SIP/123"</FONT>);</P>
    <P align=left>originateAction.setContext(<FONT 
    color=#2a00ff>"default"</FONT>);</P>
    <P align=left>originateAction.setExten(<FONT 
color=#2a00ff>"123"</FONT>);</P>
    <P align=left>originateAction.setPriority(1);</P>
    <P align=left>originateAction.setTimeout(<B><FONT 
    color=#7f0055>new</B></FONT> Long(60000));</P>
    <P align=left></P>
    <P><FONT 
    color=#0000c0>managerConnection</FONT>.sendAction(originateAction);</P></BLOCKQUOTE></BLOCKQUOTE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// wait 10 seconds for events to come 
in<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Thread.sleep(10000);</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN 
style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// and finally log off and 
disconnect<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
managerConnection.logoff();<BR>&nbsp;&nbsp;&nbsp; }</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp; public void 
onManagerEvent(ManagerEvent event)<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // just print received 
events<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println(event);<BR>&nbsp;&nbsp;&nbsp; }</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp; public 
static void main(String[] args) throws Exception<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelloEvents 
helloEvents;</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><SPAN 
style="FONT-FAMILY: monospace"><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
helloEvents = new HelloEvents();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
helloEvents.run();<BR>&nbsp;&nbsp;&nbsp; }<BR>}</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Essa classe 
faz a mesma coisa que foi feita com o telnet. Realiza uma ligação para o meu 
ramal e transfere o canal para o meu ramal também.&nbsp;Na vida real não tem 
muita utilidade mas para fazer um teste você só vai precisar de um X-Lite 
configurado com o ramal 123.</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Tomara 
que&nbsp;esse tutorial&nbsp;possa ajudar alguém. Ou pelo menos mostrar mais uma 
funcionalidade do Asterisk.</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Abraço a 
todos,</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Silvio 
Netto</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Asterisk 
Counter 241</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN>&nbsp;</DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT 
size=2></FONT></SPAN>&nbsp;</DIV></BODY></HTML>