<!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> </DIV>
<DIV><FONT face=Arial size=2>Estive tentando acessar um servidor Asterisk a
partir de uma máquina Windows realizar uma ligação e transferir 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 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> </DIV>
<DIV><STRONG><SPAN style="FONT-FAMILY: monospace">; </SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> ; Asterisk Call Management support
</SPAN><BR><SPAN style="FONT-FAMILY: monospace"> ; </SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> [general] </SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> enabled = yes </SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> port = 5038
</SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> bindaddr = 0.0.0.0
</SPAN><BR><BR><SPAN style="FONT-FAMILY: monospace"> [mark]
</SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> secret = mysecret
</SPAN><BR><SPAN style="FONT-FAMILY: monospace"> deny=0.0.0.0/0.0.0.0
</SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> permit=209.16.236.73/255.255.255.0
</SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> permit=127.0.0.1/255.255.255.0
</SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> read = system,call,log,verbose,command,agent,user
</SPAN><BR><SPAN
style="FONT-FAMILY: monospace"> write = system,call,log,verbose,command,agent,user</SPAN></STRONG></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN> </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> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>telnet 192.168.0.1
5038</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN> </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> </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> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT
size=2></FONT></SPAN> </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> </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> </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> </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> </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> </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> </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> </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> </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> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>action:
logoff</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN> </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> </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> </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> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>import
java.io.IOException;</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </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> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG>public class HelloEvents
implements ManagerEventListener<BR>{<BR> private
ManagerConnection managerConnection;</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG> public
HelloEvents() throws IOException<BR>
{<BR> ManagerConnectionFactory factory
= new
ManagerConnectionFactory(<BR>
"192.168.0.1", "mark", "mysecret");</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV><SPAN
style="FONT-FAMILY: monospace"><STRONG>
this.managerConnection =
factory.createManagerConnection();<BR> }</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG> public void
run() throws IOException,
AuthenticationFailedException,<BR>
TimeoutException, InterruptedException<BR>
{<BR> // register for
events<BR>
managerConnection.addEventListener(this);<BR>
<BR> // connect to Asterisk and log
in<BR>
managerConnection.login();</STRONG></SPAN></DIV>
<DIV><SPAN
style="FONT-FAMILY: monospace"><STRONG>
<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> <BR>
// wait 10 seconds for events to come
in<BR>
Thread.sleep(10000);</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV><SPAN
style="FONT-FAMILY: monospace"><STRONG>
// and finally log off and
disconnect<BR>
managerConnection.logoff();<BR> }</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG> public void
onManagerEvent(ManagerEvent event)<BR>
{<BR> // just print received
events<BR>
System.out.println(event);<BR> }</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><STRONG> public
static void main(String[] args) throws Exception<BR>
{<BR> HelloEvents
helloEvents;</STRONG></SPAN></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV><SPAN
style="FONT-FAMILY: monospace"><STRONG>
helloEvents = new HelloEvents();<BR>
helloEvents.run();<BR> }<BR>}</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial
size=2></FONT></SPAN> </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. 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> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial size=2>Tomara
que esse tutorial 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> </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> </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> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: monospace"><FONT
size=2></FONT></SPAN> </DIV></BODY></HTML>