PABX/APIuTech
De uTech Tecnologia
(Diferença entre revisões)
(→/call/makecall - Gerar chamadas) |
|||
Linha 121: | Linha 121: | ||
|} | |} | ||
<BR><BR> | <BR><BR> | ||
+ | |||
+ | === Exemplo em PHP === | ||
+ | {| class="wikitable" width="65%" | ||
+ | | | ||
+ | <source lang="php"> | ||
+ | <?php | ||
+ | |||
+ | $token = "1234"; | ||
+ | $source = "2001"; | ||
+ | $destination = "4833334840"; | ||
+ | $port = "80"; | ||
+ | $ipaddr = "pabx.dominio.com"; | ||
+ | |||
+ | $url = ""; | ||
+ | $url = "$ipaddr:$port/utech/v1/call/makecall/?token={$token}&source={$source}&destination={$destination}"; | ||
+ | $ch = curl_init($url); | ||
+ | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
+ | curl_setopt($ch, CURLOPT_POST, false); | ||
+ | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); | ||
+ | curl_setopt($ch, CURLOPT_TIMEOUT, 30); | ||
+ | $result = curl_exec($ch); | ||
+ | if(!$result) { | ||
+ | echo "error!\n"; | ||
+ | return 2; | ||
+ | } | ||
+ | |||
+ | print_r(json_decode($result, true)); | ||
+ | |||
+ | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | ||
+ | if($httpcode != 200) { | ||
+ | echo "HTTP return code error [$httpcode]\n"; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | ?> | ||
== /call/get_record - Fazer download de gravações == | == /call/get_record - Fazer download de gravações == |
Edição de 18h23min de 20 de outubro de 2023
Tabela de conteúdo |
Introdução
- A API do PABX uTech está disponível para a versão 1.0.1 - Qui 20 Sep 2023 ou superior.
Configuração do PABX
- Para habilitar ou desabilitar o acesso a API, acesse a interface WEB do PABX, menu GESTÃO ⇒ Configuração. Depois clique na aba Integrações ⇒ Geral. Não opção API uTech'
- Habilite ou desabilite a opção Habilitar API.
- Configure um token de acesso no campo Token. É mandatório a configuração de um token. Se o campo ficar vazio, não será possível a utilização da API.
Nota: utilize um token forte, pois a API deixará seu PABX aberto para tentativas de uso da API! |
Observações
- A API retorna valores no formato JSON.
- Utiliza protocolo HTTP.
Endpoints
/call/makecall - Gerar chamadas
Endpoint utilizado para gerar uma chamada. Ao executar o endpoint, será gerada uma chamada para o numero origem (parâmetro source). Quando a origem atender a chamada, será gerado pelo PABX uma chamada para o numero destino (parâmetro destination). Quando o destino atender a chamada, origem e destino estarão em conversação.
|
GET /utech/v1/call/makecall/?token=1234&source=2000&destination=04833334840
{ "status": "ok", "id": "1695129954.462751335" }
{ "status": "error", "cause": "Authentication error" } |
Exemplo em PHP
<?php $token = "1234"; $source = "2001"; $destination = "4833334840"; $port = "80"; $ipaddr = "pabx.dominio.com"; $url = ""; $url = "$ipaddr:$port/utech/v1/call/makecall/?token={$token}&source={$source}&destination={$destination}"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $result = curl_exec($ch); if(!$result) { echo "error!\n"; return 2; } print_r(json_decode($result, true)); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if($httpcode != 200) { echo "HTTP return code error [$httpcode]\n"; } ?> == /call/get_record - Fazer download de gravações == <BR> Endpoint utilizado para fazer o download de uma gravação. Se o '''ID''' passado corresponder a uma chamada válida e houver gravação dessa chamada, o PABX uTech irá iniciar o download da gravação. Caso contrário, será retornado erro '''404''' e um ''json'' com a causa. {| style="width: 100%;" |- | style="width: 50%"| {| style="width: 50%; background-color: #76b5c5;font-size:16px;padding: 12px;" | '''GET''' /v1/call/'''get_record''' |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Parâmetros:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;vertical-align:top;" align="right"| '''token''' | Token definido na configuração do PABX uTech. | ''string'' | Mandatório |- ! scope="row" style="width: 20%" align="right"| '''id''' | Identificador da chamada que deseja realizar o download da gravação. | ''string'' | Mandatório |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Resposta:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;" align="right"| '''status''' | Estado da geração da chamada. * '''error''': Erro na requisição. | ''string'' |- ! scope="row" style="width: 20%" align="right"| '''cause''' | Em caso de erro na requisição, uma ''string'' de causa do erro será preenchida. | ''string'' |} <!-- Tabela Lateral --> <!-- Tabela Lateral --> <!-- Tabela Lateral --> | style="width: 20%;margin-left: auto; margin-right: 0px;""| <!-- Tabela Lateral --> | style="width: 30%;margin-left: auto; margin-right: 0px;""| {| style="width: 80%; font-size:18px;padding: 12px;" | '''Exemplo:''' |} <pre style="width: 50%;> /utech/v1/call/get_record/?token=1234&id=1694435179.3 </pre> <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''200 OK:''' |} <pre> A gravação! </pre> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Erro 4XX/5XX:''' |} <pre> { "status": "error", "cause": "Invalid callid" } </pre> |} <BR><BR> == /call/get_rec_uri - Buscar link de gravações == <BR> Endpoint utilizado para buscar o link para de download de uma gravação. Se o '''ID''' passado corresponder a uma chamada válida e houver gravação dessa chamada, o PABX uTech retornar um ''json'' com o link da gravação. Caso contrário, será retornado erro '''404''' e um ''json'' com a causa. {| style="width: 100%;" |- | style="width: 50%"| {| style="width: 50%; background-color: #76b5c5;font-size:16px;padding: 12px;" | '''GET''' /v1/call/'''get_record_uri''' |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Parâmetros:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;vertical-align:top;" align="right"| '''token''' | Token definido na configuração do PABX uTech. | ''string'' | Mandatório |- ! scope="row" style="width: 20%" align="right"| '''id''' | Identificador da chamada que deseja realizar o download da gravação. | ''string'' | Mandatório |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Resposta:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;" align="right"| '''status''' | Estado da geração da chamada. * '''ok''': Requisição correta. * '''error''': Erro na requisição. | ''string'' |- ! scope="row" style="width: 20%" align="right"| '''url''' | Link para download da gravação. | ''uri'' |- ! scope="row" style="width: 20%" align="right"| '''cause''' | Em caso de erro na requisição, uma ''string'' de causa do erro será preenchida. | ''string'' |} <!-- Tabela Lateral --> <!-- Tabela Lateral --> <!-- Tabela Lateral --> | style="width: 20%;margin-left: auto; margin-right: 0px;""| <!-- Tabela Lateral --> | style="width: 30%;margin-left: auto; margin-right: 0px;""| {| style="width: 80%; font-size:18px;padding: 12px;" | '''Exemplo:''' |} <pre style="width: 50%;> /utech/v1/call/get_record_uri/?token=1234&id=1694435179.3 </pre> <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''200 OK:''' |} <pre> { "status": "ok", "url": "https://dominio/storage/19092023/4001_6002_eb00000a_18750_003351.wav" }</pre> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Erro 4XX/5XX:''' |} <pre> { "status": "error", "cause": "Invalid callid" } </pre> |} <BR><BR> == /call/summary - Buscar dados/resumo de chamadas == <BR> Endpoint utilizado para buscar informações de uma chamada, como NA, NB, duração entre outros. {| style="width: 100%;" |- | style="width: 50%"| {| style="width: 50%; background-color: #76b5c5;font-size:16px;padding: 12px;" | '''GET''' /v1/call/'''summary''' |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Parâmetros:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;vertical-align:top;" align="right"| '''token''' | Token definido na configuração do PABX uTech. | ''string'' | Mandatório |- ! scope="row" style="width: 20%" align="right"| '''id''' | Identificador da chamada que deseja buscar o sumário. | ''string'' | Mandatório |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Resposta:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;" align="right"| '''status''' | Estado da geração da chamada. * '''ok''': Requisição correta. * '''error''': Erro na requisição. | ''string'' |- ! scope="row" style="width: 20%" align="right"| '''summary''' | Dados da chamada consultada: * '''callid''': Identificação da chamada. * '''url''': Link para download da gravação. * ''''start_date''': Data/Hora de inicio da chamada. * '''end_data''': Data/Hora de finalização da chamada. * '''talk_duration''': Tempo, em segundos,de conversação. * '''total_duration''': Tempo, em segundos,total da chamada. * '''price''': Custo da chamada. * '''caller''': Numero origem. * '''called''': Numero destino. | ''array/json'' |- ! scope="row" style="width: 20%" align="right"| '''cause''' | Em caso de erro na requisição, uma ''string'' de causa do erro será preenchida. | ''string'' |} <!-- Tabela Lateral --> <!-- Tabela Lateral --> <!-- Tabela Lateral --> | style="width: 20%;margin-left: auto; margin-right: 0px;""| <!-- Tabela Lateral --> | style="width: 30%;margin-left: auto; margin-right: 0px;""| {| style="width: 80%; font-size:18px;padding: 12px;" | '''Exemplo:''' |} <pre style="width: 50%;> /utech/v1/call/summary/?token=1234&id=1694435179.3 </pre> <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''200 OK:''' |} <pre> { "status": "ok", "summary": { "callid": "1694435179.3", "url": "https://dominio/storage/19092023/4001_6002_eb00000a_18750_003351.wav", "start_date": "2023-09-19T00:33:51-03:00", "end_data": "2023-09-19T00:33:55-03:00", "talk_duration": "33", "total_duration": 42, "price": "0", "caller": "2000", "called": "4833334840" } } </pre> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Erro 4XX/5XX:''' |} <pre> { "status": "error", "cause": "Invalid callid" } </pre> |} <BR><BR> == /call/call_status - Buscar o status atual de chamadas == <BR> Endpoint utilizado para buscar o estado atual de uma chamada. {| style="width: 100%;" |- | style="width: 50%"| {| style="width: 50%; background-color: #76b5c5;font-size:16px;padding: 12px;" | '''GET''' /v1/call/'''call_status''' |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Parâmetros:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;vertical-align:top;" align="right"| '''token''' | Token definido na configuração do PABX uTech. | ''string'' | Mandatório |- ! scope="row" style="width: 20%" align="right"| '''id''' | Identificador da chamada que deseja realizar o download da gravação. | ''string'' | Mandatório |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Resposta:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;" align="right"| '''status''' | Estado da geração da chamada. * '''ok''': Requisição correta. * '''error''': Erro na requisição. | ''string'' |- ! scope="row" style="width: 20%" align="right"| '''state''' | Estado da chamada: * '''answered''': Chamada atendida. * '''unanswered''': Chamada não atendida. * '''proceeding''': Chamada originada/enviada ao destino. * '''calling''': Chamada iniciada. * '''diverted''': Chamada desviada. * '''transferred''': Chamada transferida. | ''array/json'' |- |- ! scope="row" style="width: 20%" align="right"| '''id''' | Identificador da chamada enviado na requisição. | ''string'' |- ! scope="row" style="width: 20%" align="right"| '''cause''' | Em caso de erro na requisição, uma ''string'' de causa do erro será preenchida. | ''string'' |} <!-- Tabela Lateral --> <!-- Tabela Lateral --> <!-- Tabela Lateral --> | style="width: 20%;margin-left: auto; margin-right: 0px;""| <!-- Tabela Lateral --> | style="width: 30%;margin-left: auto; margin-right: 0px;""| {| style="width: 80%; font-size:18px;padding: 12px;" | '''Exemplo:''' |} <pre style="width: 50%;> /utech/v1/call/call_status/?token=1234&id=1694435179.3 </pre> <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''200 OK:''' |} <pre> { "status": "ok", "id": "1695384025.44", "state": "answered" } </pre> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Erro 4XX/5XX:''' |} <pre> { "status": "error", "cause": "Invalid callid" } </pre> |} <BR><BR> == /call/endcall - Desligar/Derrubar chamadas == <BR> Endpoint utilizado para derrubar/desligar uma chamada ativa.. {| style="width: 100%;" |- | style="width: 50%"| {| style="width: 50%; background-color: #76b5c5;font-size:16px;padding: 12px;" | '''GET''' /v1/call/'''endcall''' |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Parâmetros:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;vertical-align:top;" align="right"| '''token''' | Token definido na configuração do PABX uTech. | ''string'' | Mandatório |- ! scope="row" style="width: 20%" align="right"| '''id''' | Identificador da chamada que deseja realizar desligar. | ''string'' | Mandatório |} <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Resposta:''' |} {| class="wikitable" width="80%" |- ! scope="row" style="width: 20%;" align="right"| '''status''' | Estado da geração da chamada. * '''ok''': Requisição correta. * '''error''': Erro na requisição. | ''string'' |- ! scope="row" style="width: 20%" align="right"| '''callstate''' | Status da chamada: * '''finished''': Chamada finalizada. | ''string'' |- ! scope="row" style="width: 20%" align="right"| '''id''' | Identificador da chamada enviado na requisição. | ''string'' |} <!-- Tabela Lateral --> <!-- Tabela Lateral --> <!-- Tabela Lateral --> | style="width: 20%;margin-left: auto; margin-right: 0px;""| <!-- Tabela Lateral --> | style="width: 30%;margin-left: auto; margin-right: 0px;""| {| style="width: 80%; font-size:18px;padding: 12px;" | '''Exemplo:''' |} <pre style="width: 50%;> /utech/v1/call/endcall/?token=1234&id=1694435179.3 </pre> <BR> {| style="width: 80%; font-size:18px;padding: 12px;" | '''200 OK:''' |} <pre> { "status": "ok", "callstate": "finished", "id": "1695383395.42" } </pre> {| style="width: 80%; font-size:18px;padding: 12px;" | '''Erro 4XX/5XX:''' |} <pre> { "status": "error", "cause": "Invalid callid" } </pre> |} <BR><BR> |