Cliente em Golang para consumo da API da TotalVoice
- Gerenciamento das chamadas
- Consulta e envio de SMS
- Consulta e envio de TTS
- Consulta e envio de Audio
- Consulta e envio de Composto
- Consulta e envio de Conferência
- Gerenciamento da Conta
- Gerenciamento da Central
- Gerenciamento de DID
- Golang 1.6+
Para instalar a biblioteca basta digitar
go get github.com/totalvoice/totalvoice-go
Para utilizar esta biblioteca, primeiramente você deverá realizar um cadastro no site da Total Voice. Após a criação do cadastro será disponibilizado um AccessToken para acesso a API.
Com o AccessToken em mãos será possível realizar as consultas/cadastros conforme documentação da API
Os métodos da API que poderão ser invocados:
- audio
- central
- chamada
- composto
- conferencia
- conta
- perfil
- sms
- tts
- did
A seguir exemplos de como pode ser utilizada esta biblioteca.
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Chamada.Criar("4811111111", "4822222222", nil)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Chamada.Buscar(123) // ID da chamada
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Chamada.Encerrar(123) // ID da chamada
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
di := time.Date(2017, time.December, 06, 00, 20, 0, 0, time.Local)
df := time.Date(2017, time.December, 06, 18, 20, 0, 0, time.Local)
// parametros opcionais - filtros e paginacao
filtros := map[string]interface{}{
"origem": "48999999999",
"destino": "489888888888",
"posicao": 0,
"limite": 100,
}
response, err := client.Chamada.Relatorio.Gerar(di, df, filtros)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.SMS.Enviar("4811111111", "Minha mensagem SMS", false, false, nil)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
di := time.Date(2017, time.December, 06, 00, 20, 0, 0, time.Local)
df := time.Date(2017, time.December, 06, 18, 20, 0, 0, time.Local)
response, err := client.SMS.Relatorio.Gerar(di, df)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.TTS.Enviar("4811111111", "Minha mensagem TTS", nil)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
opcoes := map[string]interface{}{
"velocidade": 1,
"resposta_usuario": true,
"tipo_voz": "br-Vitoria",
"bina": "4811111111",
}
response, err := client.TTS.Enviar("4811111111", "Minha mensagem TTS", opcoes)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
di := time.Date(2017, time.December, 06, 00, 20, 0, 0, time.Local)
df := time.Date(2017, time.December, 06, 18, 20, 0, 0, time.Local)
response, err := client.TTS.Relatorio.Gerar(di, df)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Audio.Enviar("4811111111", "http://foooo.bar/audio.mp3", false, "4811111111", false)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
ramal = new(Ramal)
ramal.Ramal = "4001"
ramal.Login = "meulogin@login.com.br"
ramal.Senha = "12345789"
response, err := client.Ramal.Criar(ramal)
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Conta.Buscar(123) // ID da Conta
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Perfil.MinhaConta()
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Saldo.ConsultaSaldo()
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Perfil.GeraURLRecarga()
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.Perfil.RelatorioRecarga()
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.DID.Estoque()
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewTotalVoiceClient("access-token")
response, err := client.DID.Adquirir(123) // ID do DID
if err != nil {
panic(err)
}
fmt.Println(response)
}
package main
import (
"fmt"
"github.com/totalvoice/totalvoice-go"
)
func main() {
client := totalvoice.NewClient("access-token", "https://seudominio.com.br")
response, err := client.Saldo.ConsultaSaldo()
if err != nil {
panic(err)
}
fmt.Println(response)
}
Mais informações sobre os métodos disponíveis podem ser encontrados na documentação da API
Quer contribuir? clique aqui
Esta biblioteca segue os termos de uso da MIT