tag:blogger.com,1999:blog-6026656492236135992024-03-13T22:43:35.680-07:00Danilo AlmeidaBlog destinado ao compartilhamento de conhecimento relacionado a linux e asterisk.Anonymoushttp://www.blogger.com/profile/08807748708931455730noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-602665649223613599.post-25780923572998432522016-06-08T06:42:00.001-07:002016-06-08T06:42:43.975-07:000800WEB / click-to-call com asterisk<span style="font-family: "arial" , "helvetica" , sans-serif;">Resumindo... O 0800Web é uma ferramenta que qualquer site pode ter para que os usuários digitem seus números telefônicos e recebam ligação da equipe da empresa ou do site no mesmo momento ou quando desejarem. <br /><br />Aqui utilizaremos uma conexão <a href="http://www.voip-info.org/wiki/view/Asterisk+manager+Example:+PHP">AMI</a> com o servidor responsável por efetur a chamada.<br /><br />Sem delongas, vamos logo ao que interessa:</span><br />
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br />Na área do site, teremos 2 arquivos, o primeiro contém apenas o html do site e irei chamar aqui de ligame.html e o segundo é o que faz a conexão do PHP com o asterisk.</span><br />
<br />
<u><b><span style="font-family: Arial, Helvetica, sans-serif;">ligame.html</span></b></u><br />
<div>
<b><u><br /></u></b>
<br />
<div style="text-align: justify;">
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><html xmlns="http://www.w3.org/1999/xhtml"></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><head></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><title>0800WEB DRAsterisk</title></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span></head></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><body></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><form action="ligar.php" method="post"></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><h3>DRAsterisk Liga-me</h3></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><label>Telefone com DDD:</label></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><input type="number" name="fone" required="required"/></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span><button type="submit">Liga-me</button></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span></form></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span></body></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="background-color: white; font-family: "courier new" , "courier" , monospace;"></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"></html></span></span></div>
<div style="text-align: justify;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /><br />O arquivo ligar.php, é o segundo arquivo da área do site e é reponsável pela conexão com o asterisk e o envio da chamada. Ele também faz uma pequena validação afim de encontrar algum erro no retorno da conexão e envio da ligação.<br /><br /><span style="font-size: xx-small;"><b><u>ligar.php</u></b></span></span><br />
<span style="font-family: "ubuntu" , sans-serif;"><span style="background-color: white; font-family: "arial" , "helvetica" , sans-serif;"><b><u><span style="font-size: x-small;"><br /></span></u></b></span></span>
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><?php</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">//RECEBENDO NUMERO</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">$num = $_POST['fone'];</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> echo "Dialing $num\r\n";</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> $timeout = 10;</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> $asterisk_ip = "192.168.1.201";</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$user_manager = "drasterisk";</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$senha_manager = "teste";</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$channel = "SIP/4000"; //Canal interno que irá receber a chamada</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$context = 'contexto-ligame';</span></span><br />
<span class="Apple-tab-span" style="font-size: 14px; line-height: 20px; white-space: pre;"><span style="font-family: "courier new" , "courier" , monospace;"> </span></span><br />
<span class="Apple-tab-span" style="font-size: 14px; line-height: 20px; white-space: pre;"><span style="font-family: "courier new" , "courier" , monospace;"> //FAZENDO CONEXAO COM ASTERISK</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$socket = fsockopen($asterisk_ip,"5038", $errno, $errstr, 10);</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> <span class="Apple-tab-span" style="white-space: pre;"> </span>if (!$socket){</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>echo "$errstr ($errno)\n";</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "Action: Login\r\n");</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "UserName: ".$user_manager."\r\n");</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "Secret: ".$senha_manager."\r\n\r\n");</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> //ORIGINANDO A CHAMADA</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> fputs($socket, "Action: Originate\r\n" );</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "Channel: ".$channel."\r\n" );</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "Exten: ".$num."\r\n" );</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "Context: ".$context."\r\n" );</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "Priority: 1\r\n" );</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> fputs($socket, "Async: yes\r\n\r\n" );</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> fputs($socket, "Action: Logoff\r\n\r\n");</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> /****************DEBUGAR*****************/</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> //while (!feof($socket)){</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> // $retorno[] = fgets($socket);</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> //}</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> fclose($socket);</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> }</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"> //VERIFICANDO SE TEM ALGUM ERRO</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$result = '';</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for ($i=0; $i < count($retorno) ; $i++) {<span class="Apple-tab-span" style="white-space: pre;"> </span></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$result = (preg_match("/Response: Error/",$retorno[$i]))?'erro':$result;</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>echo $retorno[$i]."<br/>"; //para debugar</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if($result == "erro"){</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>echo "Não foi possíve efetuar a ligação";</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>echo "Aguarde o retorno da chamada";</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></span><br />
<span class="Apple-tab-span" style="font-size: 14px; line-height: 20px; white-space: pre;"><span style="font-family: "courier new" , "courier" , monospace;"> </span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sleep(5);</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>header("Location: ligame.html");</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="background-color: white; font-family: "courier new" , "courier" , monospace;"></span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">?></span></span><br />
<span style="font-family: "ubuntu" , sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 20px;"><br /></span></span><span style="font-family: "arial" , "helvetica" , sans-serif;"><br />Do lado do asterisk, iremos alterar dois arquivo também (manager.conf e extensions.conf).<br /><br />O manager.conf é responsável por liberar a conexão realizada pelo PHP através de um usuário e senha de autenticação, procuro também limitar somente aos IPs permitos.</span></div>
<div style="text-align: justify;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b><u><span style="font-family: Arial, Helvetica, sans-serif;">/etc/asterisk/manager.conf</span></u></b></div>
</div>
<div>
<b><u><br /></u></b>
<br />
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">[general]</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">enabled = yes</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">;webenabled = yes</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">deny = 0.0.0.0/0.0.0.0</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">permit = 127.0.0.1/255.255.255.255</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">permit = 192.168.1.0/255.255.255.0</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">port = 5038</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">[drasterisk]</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">secret = teste</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">read = system,call,log,verbose,command,agent,user</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="background-color: white; font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;"></span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: "courier new" , "courier" , monospace; font-size: 14px; line-height: 20px;">write = system,call,log,verbose,command,agent,user</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-size: 14px; line-height: 20px;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-size: 14px; line-height: 20px;">No extensions.conf, criaremos um contexto para tratar as chamadas realizadas pela interface. Aqui criei apenas um básico, mais pode-se adequar para a sua necessidade.</span></span><br />
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-size: 14px; line-height: 20px;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;"><b><u>/etc/asterisk/extensions.conf</u></b></span></span><br />
<span style="font-family: "ubuntu" , sans-serif;"><span style="font-size: 14px; line-height: 20px;"><b><u><br /></u></b></span></span></div>
<div style="text-align: justify;">
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">[contexto-ligame]</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">exten => _ZZ[2-9].,1,NoOp(---> NOVA LIGACAO 0800WEB <--)</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">same => n,Set(CDR(accountcode)=0800WEB)</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">same => n,Dial(SIP/operadora/0${EXTEN},60,Tg) ;SAINDO PELO VOIP</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">;same => n,Dial(Khomp/b0l0/021${EXTEN},60,Tg) ; SAINDO PELO HARDWARE KHOMP</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">;same => n,Dial(Dahdi/g0/021${EXTEN},60,Tg) ; SAINDO PELO HARDWARE DIGIUM</span></span><br />
<span style="font-size: 14px; line-height: 20px;"><span style="font-family: "courier new" , "courier" , monospace;">same => n,Hangup</span></span><br />
<br /><br /><span style="font-family: Arial, Helvetica, sans-serif;">É isso ai, agora basta fazer algumas modificações para adaptar da forma que precisa.<br /><br />Para quem usa Elastix, ao invés de alterar o arquivo extensions.conf, altere o arquivo extensions_custom.conf (se não me falha a memória).<br /><br />Para consultoria em asterisk: daniloricalmeida@gmail.com e skype danilo.almeida33<br /><br />Abraços!</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: "ubuntu" , sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 20px;"><br /></span></span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/08807748708931455730noreply@blogger.com11tag:blogger.com,1999:blog-602665649223613599.post-48342405148094863202014-05-13T06:41:00.002-07:002014-05-13T06:41:59.346-07:00Convertendo texto em voz com API do googleOlá Galera!<br />
<br />
Depois de um tempo grande sem postagem, venho novamente aqui para mais uma.<br />
Hoje esta sendo muito utilizada uma API do google chamada<span style="font-family: Helvetica, Arial, FreeSans, san-serif;"><b> GOOGLETTS (text to speech). </b>Essa API converte o texto passado em voz, logicamente não é aquela voz esperada por todos, porém, quebra o galho em alguns casos.</span><br />
<span style="font-family: Helvetica, Arial, FreeSans, san-serif;">Utilizaremos um script em AGI para enviar o texto para conversão através do asterisk, o script e mais exemplos podem ser encontrados neste site: </span><a href="http://zaf.github.io/asterisk-googletts/">http://zaf.github.io/asterisk-googletts/</a>. Vamos la:<br />
<br />
Precisaremos das seguinte dependências:<br />
<br />
- Perl<br />
- perl-libwww<br />
- sox<br />
- mpg123<br />
<br />
para quem usa Debian, basta dar um apt-get install nome-dependencia<br />
<br />
Além das dependências acima, precisaremos de acesso a internet para a conversão que será feita pelo google.<br />
<br />
Instalação:<br />
<br />
Baixe o arquivo <a href="https://github.com/downloads/zaf/asterisk-googletts/asterisk-googletts-0.6.tar.gz" url="https://github.com/downloads/zaf/asterisk-googletts/asterisk-googletts-0.6.tar.gz">googletts.agi</a>, descompacte e salve no diretório /var/lib/asterisk/agi-bin e de permissão de execução para o mesmo --> chmod a+x googletss.agi.<br />
Existe algumas configurações que podemos fazer neste arquivo, como por exemplo, mudar o diretório padrão (/tmp) que ele salva as gravações, assim, toda vez que um texto idêntico for passado, ele não precisa fazer a aquisição ao google, tendo em vista que o áudio já esta salvo no diretório. Além disso, podemos mudar a linguagem padrão para pt_BR... porém, por hora não precisamos fazer isto e não entrarei nestes detalhes.<br />
<br />
Criando contexto no asterisk:<br />
<br />
Vamos criar um contexto no asterisk chamado "google-speech" e fazer nossa lógica nele.<br />
<br />
[google-speech]<br />
<i><span style="font-family: Courier New, Courier, monospace;">;convertendo texto em voz</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => 1234,1,Answer() ;;Atendendo canal</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => 1234,n,agi(googletts.agi,"Testando conversor de texto em voz.",pt_BR) ;; passando texto e a linguagem que queremos o retorno.</span></i><br />
<span style="color: white;"><br /></span>
no exemplo acima, apenas atendemos a ligação e enviamos a aquisição ao AGI passando de parâmetros o texto que será convertido e a linguagem que será retornado a "voz".<br />
<br />
Agora vamos ver um exemplo simples IVR Dinâmico:<br />
<br />
[ivr]<br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => s,1,Answer()</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => s,n,Set(TIMEOUT(digit)=5)</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => s,n,agi(googletts.agi,"Bem vindo ao Meu menu de voz interativa.",pt_BR)</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;"> ;;Aguardando Dígito:</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => s,n(start),agi(googletts.agi,"Por favor, digite um número.",pt_BR,any) </span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => s,n,WaitExten()</span></i><br />
<br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => _X,1,agi(googletts.agi,"Você digitou o número ${EXTEN}. Tente outra vez.",pt_BR,any)</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => _X,n,WaitExten()</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;"><br /></span></i>
<i><span style="font-family: Courier New, Courier, monospace;">exten => i,1,agi(googletts.agi,"Dígito Inválido.",pt_BR)</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => i,n,goto(s,start)</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;"><br /></span></i>
<i><span style="font-family: Courier New, Courier, monospace;">exten => t,1,agi(googletts.agi,"Você não digitou nenhum número.",pt_BR)</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;">exten => t,n,goto(s,start)</span></i><br />
<i><span style="font-family: Courier New, Courier, monospace;"><br /></span></i>
<i><span style="font-family: Courier New, Courier, monospace;">exten => h,1,Hangup()</span></i><br />
<br />
É isso ai pessoal, esse exemplo é bem simples e não precisa de muita explicação, o que ele faz:<br />
<br />
- Atende o canal<br />
- Mensagem de boas vindas<br />
- Mensagem para digitar um número<br />
- aguardar dígito<br />
- Dizer qual o número discado.<br />
<br />
Exemplo simples e direto tirado direto do site oficial mencionado acima.<br />
<br />
Espero que ajude<br />
<br />
Até a próxima, valeu!!<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/08807748708931455730noreply@blogger.com0tag:blogger.com,1999:blog-602665649223613599.post-50888134575305202322013-03-08T04:24:00.001-08:002013-03-08T04:24:12.430-08:00O que é o Asterisk?<br />
Bom Galera!!!<br />
Decidi fazer um post aqui, para pessoas que não conhece esse sistema fantástico que é o ASTERISK. Vou fazer uma breve explicação para que fiquem mais informadas do assunto. Tive conversando com alguns amigos que trabalham na área de informática, e poucos conhece sobre o sistema e por isso estou escrevendo este POST.<br />
<br />
Bom, tudo que quero explicar já tem em vários sites pela rede, então encolhi um e disponibilizei para vocês.<br />
<br />
Asterisk é um poderoso software livre que permite transformar um ordinário PC numa poderosa central telefónica multi protocolo. É licenciado através de uma licença do tipo GPL - Gnu Public License. A Digium, empresa que promove o Asterisk, investe em ambos, o desenvolvimento do código fonte e em hardware de telefonia de baixo custo que funciona com o Asterisk. O Asterisk funciona sobre uma plataforma Linux ou outras plataformas Unix com ou sem hardware conectando à rede pública de telefonia.<br />
<br />
<br />
<br />
<a href="http://1.bp.blogspot.com/-A_MWLj7zd88/UTnVq9bnM6I/AAAAAAAAADE/EBvBchWWTtE/s1600/rj_phone.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-A_MWLj7zd88/UTnVq9bnM6I/AAAAAAAAADE/EBvBchWWTtE/s1600/rj_phone.gif" /></a>O Asterisk permite conectividade em tempo real entre a rede pública de telefonia e redes VoIP. A rede pública de telefonia é frequentemente referida pela sua sigla em inglês PSTN (Public Switched Telephony Network).<br />
O Asterisk integra telefones, computadores, Rede LAN e a Internet numa única plataforma. Baseado em tecnologias abertas e protocolos padrões de mercado, este sistema tem as funcionalidades de correio de voz, correio electrónico, atendimento automático, unidade de resposta audível (URA), distribuição automática de chamadas (DAC) e integração entre telefonia e computadores, além da conectividade com o PBX da empresa e com a rede pública de telefonia comutada (STFC) e móvel.<br />
<br />
<h3>
<b>Características do sistema:</b></h3>
• Sistema de telefonia IP-PBX;<br />
• Distribuidor Automático de Chamadas (DAC);<br />
• Unidade de Resposta Audível (URA);<br />
• Correio de Voz com integração com o correio electrónico;<br />
• Relatório e estatísticas das chamadas;<br />
• Facilidade de administração e gestão através da Web;<br />
• Compatível com os PBX’s analógicos;<br />
• Compatível com os telefones digitais IP;<br />
• Conectividade com troncos analógicos e digitais;<br />
• Sistema voltado para pequenas e médias empresas.<br />
<br />
<h3>
Funcionamento do Asterisk:</h3>
<br />
O Asterisk interliga-se com a rede de dados através de uma porta Ethernet de 100Mbps, com a possibilidade de activar um firewall e fazer o controle de banda para os telefones IPs, caso seja necessário.<br />
<br />
<a href="http://2.bp.blogspot.com/-1X6xz7ZuFbc/UTnWMGOdzsI/AAAAAAAAADM/qwFGSJyhtfA/s1600/sobre_asterisk3.gif" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="206" src="http://2.bp.blogspot.com/-1X6xz7ZuFbc/UTnWMGOdzsI/AAAAAAAAADM/qwFGSJyhtfA/s320/sobre_asterisk3.gif" width="320" /></a>Para interligar-se com o PBX Analógico ou STFC, o Asterisk possui vários tipos de modelos de placas, com interfaces FXS, FXO, E1, T1 e PRI. É possível também utilizar qualquer produto VoIP padrão de mercado, como por exemplo do fabricante Sipura, Linksys, Grandstream, Mediatrix, Micronet ou outro qualquer, tanto para portas FXS como para portas FXO.<br />
A figura mostra um exemplo de uma empresa utilizando o sistema Asterisk, onde todos os telefones IPs locais e de sites remotos conectam-se ao servidor VoIP localizado na matriz através da Internet. Como exemplo de mobilidade, o IPFone utilizado na Residência tem acesso a todos os ramais da empresa, incluindo os ramais analógicos da central PBX, sendo possível também capturar uma linha telefónica de qualquer PBX, tanto na matriz com nos sites remotos.<br />
<br />
<h3>
Benefícios do Asterisk, além dos serviços tradicionais de telefonia:</h3>
• Plano unificado de numeração entre vários escritórios distribuídos em várias localidades;<br />
• Interligação de centrais PBX, permitindo que os ramos de 2 ou mais PBX falem entre si com custo zero;<br />
• Possibilidade de capturar uma linha remota de um outro PBX, fazendo com que a ligação internacional e nacional sejam tarifadas como ligação local;<br />
• Possibilidade de conexão simultânea com diversas redes VoIP;<br />
• Arquitectura distribuída e com gestão centralizado;<br />
• Facilidade de administração via Web;<br />
• Mensagem unificada;<br />
• Média de economia de 50% para ligações internacionais e nacionais;<br />
• Provê funcionalidades de PBX de grande porte com custo acessível também para as pequenas e médias empresas;<br />
• Permite a criação de ramais para clientes, fornecedores e parceiros, facilitando a comunicação sem que haja custo na ligação;<br />
• Integração da empresa, aumentando a produtividade dos funcionários em deslocamento: vendedores, executivos em viagem, “presença virtual”.<br />
<br />
<b>Comentário</b><br />
<br />
A telefonia convencional está a mudar e PBXs baseados em comutação de circuitos estão a tornar-se produtos obsoletos. A tecnologia VoIP expandiu muito nos últimos anos e está a começar a tornar-se o padrão de comunicação das empresas corporativas e até das pequenas/médias empresas e residências.<br />
<br />
Os novos equipamentos IP-PBXs permitem uma verdadeira convergência na área de telecomunicações, integrando voz e dados na mesma rede, proporcionando a unificação de mensagens, o aumento de produtividade e fornecendo todos esses elementos e muito mais num único produto, fácil de gerir.<br />
<br />
Baseada em uma solução software, esta arquitectura assegura uma grande escalabilidade, redução de custos (sem a necessidade de trocar o equipamento em caso de expansão), flexibilidade, confiabilidade, facilidade de administrar e gerir, suporte para equipamentos legados, tudo isso num sistema que opera no mesmo ambiente heterogêneo da Rede de dados. Sem dúvida, uma grande evolução nas telecomunicações.<br />
<br />
fonte: http://www.asterisk.pt/o-que-e-o-asterisk.html<br />
Anonymoushttp://www.blogger.com/profile/08807748708931455730noreply@blogger.com0tag:blogger.com,1999:blog-602665649223613599.post-11478345245417671032013-03-07T06:03:00.002-08:002017-04-04T12:19:32.993-07:00Script php+agi Portabilidade celular<br />
<div class="MsoNormal">
Bom
galera, algum tempo atrás postei um script de portabilidade de operadoras de celular na lista asteriskBrasil usando a classe agiphp, esse script é bem simples, porém, com um pouco de imaginação da pra ir além.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Utilizo
como servidor de consulta a DRA Telecom, basta contratar um dos planos para ter acesso a URL de consulta, o usuário neste exemplo é demo e permite somente 20 consultas diária.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Utilizei
algumas informações de alguns posts encontrados na lista.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: "arial" , "helvetica" , sans-serif;">Extensions
.conf</span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">exten
=> _0XX[6-9]XXXXXXX,1,NoOp(---> DE ${CALLERID(num)} PARA ${EXTEN} <--)</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">exten
=> _0XX[6-9]XXXXXXX,n,AGI(portabilidade.php,${EXTEN:1})</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">exten
=> _0XX[6-9]XXXXXXX,n,NoOp(---> A OPERADORA DISCADA E: ${OPERADORA}
<---)</span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">exten =>
_0XX[6-9]XXXXXXX,n,Hangup()</span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><b>portabilidade.php</b></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">#!/usr/bin/php -q</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;"><?php</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">include("phpagi.php");</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">//version:
Danilo Almeida</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">//package:
AGI Portabilidade PHP</span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">//copyright: Copyright (C) Open
Source.</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">//license: GNU/GPL, see LICENSE.php</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">//Agi
para consulta de operadora para celulares portados</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">//Acesso
ao banco de dados fornecido por <a href="http://dratelecom.com.br/">http://dratelecom.com.br</a></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">//Contato: daniloricalmeida@gmail.com</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">$agi
= new AGI(); //instanciando objeto</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">$numero
= $argv[1]; //pegando numero discado no extensions.conf</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">$numero
= $numero; //DDD+NUMERO</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">$url="<span style="color: #cc6600;"><span style="font-size: 15.4px;"><u>http://portabilidade.dratelecom.com.br/consulta.php?number=$numero&user=demo&pass=demo</u></span></span>";</span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">$chave = file_get_contents($url);</span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">switch($chave){</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;"> case 5312 :</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'CTBC CELULAR S.A' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55314 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'BRASIL TELECOM CELULAR' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
<span lang="EN-US">break;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
case 55320 :</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'VIVO' ;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
break;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
case 55321 :</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;"><span lang="EN-US">
</span>$operadora = 'AMERICEL' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55323 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'TELEMIG CELULAR' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55324 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = </span><span style="font-family: "courier new" , "courier" , monospace;">'AMERICEL'</span><span style="font-family: "courier new" , "courier" , monospace;"> ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;"> <span lang="EN-US">break;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
case 55331 :</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'TNL PCS' ;</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;"><span lang="EN-US">
</span>break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55337 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'UNICEL DO BRASIL' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
<span lang="EN-US">break;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
case 55341 :</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'TIM CELULAR' ;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
break;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
case 55343 :</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;"><span lang="EN-US">
</span>$operadora = 'SERCOMTEL CELULAR' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55349 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'OPTIONS COMP' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
<span lang="EN-US">break;</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
case 55377 :</span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'MCS (Nextel)' ;</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;"><span lang="EN-US">
</span>break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55390 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'TELCOM TELECOMUNICACOES DO BRASIL' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
<span lang="EN-US">break;</span></span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55391 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'FALKLAND TECNOLOGIA' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55392 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'IRIDIUM' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
case 55393 :</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
$operadora = 'GLOBALSTAR DO BRASIL' ;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">
break;</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">$agi->set_variable("OPERADORA",
$operadora);</span></div>
<div class="MsoNormal">
<span style="font-family: "courier new" , "courier" , monospace;">exit();</span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: "courier new" , "courier" , monospace;">?></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><b>Retorno CLI</b></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">-- Executing
[91538563@contexto-ramais-voip:1] NoOp("SIP/5001-0000011d",
"---> DE 5001 PARA 91538563 <--") in new stack</span></div>
<div class="MsoNormal">
<span lang="EN-US"> -- Executing [91538563@contexto-ramais-voip:2]
AGI("SIP/5001-0000011d", "portabilidade.php,<a href="tel:4391538563" target="_blank">4391538563</a>") in new stack</span></div>
<div class="MsoNormal">
<span lang="EN-US"> -- Launched AGI
Script /var/lib/asterisk/agi-bin/portabilidade.php</span></div>
<div class="MsoNormal">
<span lang="EN-US"> --
<SIP/5001-0000011d>AGI Script portabilidade.php completed, returning 0</span></div>
<div class="MsoNormal">
<span lang="EN-US"> -- Executing
[91538563@contexto-ramais-voip:3] NoOp("SIP/5001-0000011d",
"---> A OPERADORA DISCADA E: VIVO <---") in new stack</span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
Lembrando que estou utilizando a classe agiphp, a mesma deve estar no diretório /var/lib/asterisk/agi-bin/ juntamente com o arquivo portabilidade.php.</div>
<div class="MsoNormal">
Deve-se também dar permissão de execução nos arquivos para que o asterisk possa executar o mesmo.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
qualquer dúvida estou a disposição, devida a correria acabo fazendo os tutoriais correndo e pode ser que fique alguma coisa para trás..rsrs</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
abraço galera e até a próxima.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Danilo Almeida</div>
Anonymoushttp://www.blogger.com/profile/08807748708931455730noreply@blogger.com5tag:blogger.com,1999:blog-602665649223613599.post-91437791970574721412013-03-07T04:46:00.001-08:002013-03-07T05:11:58.046-08:00Tutorial - CAllBACK asterisk<br />
<div class="MsoNormal">
Hoje precisei criar um callback na empresa que trabalho,
esse callback funciona da seguinte maneira:<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Ligo na empresa do meu celular(ou de qualquer número que
bine) de qualquer região, o servidor pega o meu número, desliga a chamada e me
retorna, após isso, digito o numero que desejo fazer a ligação e ele disca e
completa para mim.<u5:p></u5:p></div>
<div class="MsoNormal">
Isso foi necessário, pois nossos celulares só fazem ligação
para região 43...<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Então criei uma tutorial Básico para quem necessitar.<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Callback para ligações externas<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
primeiro, criaremos a regra de entrada, nesse caso estou
simulando uma ligação entrando por um <u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<u5:p></u5:p>determinado DDR de um link E1, mais pode ser
ligações de entrada de qualquer tipo (FXO, SIP, <u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<u5:p></u5:p>Analógico, etc) bastando apenas ser alterado
para cada situação.<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>[entrada]<u5:p></u5:p><o:p></o:p></b></span></div>
<div class="MsoNormal">
<span style="color: #f3f3f3;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => _3200,1,NoOp(Realizando CallBack )<u5:p></u5:p></b></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten =>
_3200,2,Wait(1)<u5:p></u5:p></b></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten =>
_3200,3,Macro(callback,)<u5:p></u5:p></b></span></span></div>
<div class="MsoNormal">
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => _3200,4,Hangup()</b></span><u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
linha 1 - mostra na tela a descrição dentro dos parenteses
"()"<u5:p></u5:p></div>
<div class="MsoNormal">
linha 2 - espera um segundo antes de continuar<u5:p></u5:p></div>
<div class="MsoNormal">
linha 3 - vai para macro callback que veremos a seguir.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 4 - derruba a ligação após colher as primeiras
informações.<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
agora, criaremos uma macro callback onde criaremos o arquivo
.call que fará o retorno da ligação para o número que ligou.<br />
<br />
<br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>[macro-callback]</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,1,set(CALLBACK-FILE=/var/spool/asterisk/outgoing/${MACRO_EXTEN}-${CALLERID(num)}.call)</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,system(echo Channel: SIP/0${CALLERID(num)}@g1entrada > ${CALLBACK-FILE})</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,system(echo Context: saida-callback >> ${CALLBACK-FILE})</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,system(echo Extension: 1000 >> ${CALLBACK-FILE})</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,system(echo Callerid: ${CALLERID(num)} >> ${CALLBACK-FILE})</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,system(echo MaxRetries: 2 >> ${CALLBACK-FILE})</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,system(echo RetryTime: 30 >> ${CALLBACK-FILE})</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,system(echo WaitTime: 30 >> ${CALLBACK-FILE})</b></span><br />
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => s,n,MacroExit</b></span><br />
<br />
<br /></div>
<div class="MsoNormal">
linha 1 - seto uma variável com o diretório
/var/spool/asterisk/outgoing/ + o nome do arquivo que será criado
automaticamente. <u5:p></u5:p></div>
<div class="MsoNormal">
linhas n - no restante das linhas, escrevo dentro do arquivo
as opções necessárias para rodar um arquivo .call (vejam mais informações de
arquivos .call para entenderem melhor caso tenham dúvidas).<u5:p></u5:p></div>
<div class="MsoNormal">
linha 2 - canal que sairá a ligação, no meu caso estou
enviando pela operadora da empresa em que trabalho.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 3 - contexto que será direcionado para que a pessoa
possa digitar o numero desejado.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 4 - extensão que será entregue esta ligação dentro do
contexto anterior.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 5 - callerid da chamada<u5:p></u5:p></div>
<div class="MsoNormal">
linha 6 - Numero maximo de vezes que o asterisk irá
tentar chamar o originador antes de considerar que a chamada falhou.<u5:p></u5:p></div>
<div class="MsoNormal">
Este parâmetro não considera a primeira tentativa, portanto
se definido como 0, o asterisk tentará chamar apenas uma vez.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 7 - Seguntos entre as tentativas de chamar o
originador. O padrão é 300 segundos.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 8 - Numero de segundos que o asterisk irá chamar o
originador a cada tentativa. O padrão é 45.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 9 - sai da Macro.<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
após sair da macro, o asterisk dará o hangup conforme linha
4 do contexto entrada, após isso, o arquivo .call criado já será executado
chamando o número que havia ligado anteriormente, quando houver o atendimento
dessa chamada, jogará para o contexto descrito no arquivo .call que criamos
(saida-callback).<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
o contexto saida-callback dará um bip e aguardará um numero
ser digitado. Nesse caso dará um Bip, mais pode-se personalizar com uma
gravação da maneira que desejar.<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b><span lang="EN-US">[saida-callback]<u5:p></u5:p></span><o:p></o:p></b></span></div>
<div class="MsoNormal">
<span style="color: #f3f3f3;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten =>
1000,1,Answer()<u5:p></u5:p></b></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten =>
1000,2,PlayBack(beep)<u5:p></u5:p></b></span></span></div>
<div class="MsoNormal">
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => 1000,n,Read(NUMERO)<u5:p></u5:p></b></span></div>
<div class="MsoNormal">
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => 1000,n,Dial(SIP/${NUMERO}@g1telecom,40,tg)<u5:p></u5:p></b></span></div>
<div class="MsoNormal">
<span style="color: #f3f3f3; font-family: Courier New, Courier, monospace;"><b>exten => 1000,n,Macro(hangupcall,)</b></span><u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
linha 1 - atende a chamada<u5:p></u5:p></div>
<div class="MsoNormal">
linha 2 - dá um bip após o atendimento da chamada, aqui
pode-se colocar uma mensagem para o usuário ouvir tipo: digite o numero que
deseja, ou coisa do tipo.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 3 - lê os digitos e salva na variável NUMERO<u5:p></u5:p></div>
<div class="MsoNormal">
linha 4 - dá um dial para o numero capturado.<u5:p></u5:p></div>
<div class="MsoNormal">
linha 5 - dá um hangup ao término da ligação.<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
acho que é isso pessoal, desculpem qualquer coisa, mais esse
é um dos meus primeiros tutoriais e fiz correndo, qualquer erro me
perdoem..rsrs.<u5:p></u5:p><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
abraços.<u5:p></u5:p><o:p></o:p></div>
<u5:p></u5:p>Anonymoushttp://www.blogger.com/profile/08807748708931455730noreply@blogger.com14