Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ Você terá disponível globalmente o comando `gemidao-do-zap`.

| Parâmetro | Obrigatório | Descrição |
|-----------|--------------------|-----------------------------------------------------------|
| `--token` | :white_check_mark: | Seu token de acesso do TotalVoice |
| `--token` | :white_check_mark: | Seu token de acesso do TotalVoice ou DirectCall |
| `--de` | | Quem está enviando o gemidão? Qualquer número telefônico! |
| `--para` | :white_check_mark: | Quem é a vítima do gemidão do zap? |
| `--sms` | | Se definido, será enviado um SMS ao invés de uma chamada |
| `--api`   | :white_check_mark: | Escolha entre TotalVoice ou DirectCall |

### Exemplo

`gemidao-do-zap --de=47998569631 --para=47996326548 --token=ade6a19ecee14577634f66af105eb68c`
`gemidao-do-zap --de=47998569631 --para=47996326548 --api=TotalVoice --token=ade6a19ecee14577634f66af105eb68c`

Observações:

Expand Down
56 changes: 46 additions & 10 deletions src/gemidao.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import agent from 'superagent';
import promisifyAgent from 'superagent-promise';

const request = promisifyAgent(agent, Bluebird);
const route = path => `https://api.totalvoice.com.br${path}`;
const routeDirectCall = pathDirectCall => `https://api.directcallsoft.com${path}`;
const routeTotalVoice = pathTotalVoice => `https://api.totalvoice.com.br${path}`;

const gemidaoInText = 'OOOWH AHHHWN WOOOO AAAAHN WAAAAA AAAAAAHN ANN WAAA!\n'
+ 'Voce caiu no gemidao do zap';

const sms = (to, token) => request.post(route('/sms'))
// TotalVoice
const smsTotalVoice = (to, token) => request.post(routeTotalVoice('/sms'))
.set('Access-Token', token)
.set('Accept', 'application/json')
.send({ numero_destino: to, mensagem: gemidaoInText });

const call = (from, to, token) => request.post(route('/composto'))
const callTotalVoice = (from, to, token) => request.post(routeTotalVoice('/composto'))
.set('Access-Token', token)
.set('Accept', 'application/json')
.send({
Expand All @@ -29,18 +31,52 @@ const call = (from, to, token) => request.post(route('/composto'))
bina: from
});

export default function gemidao(args) {
if (!/^[a-f0-9]{32}$/.test(args.token)) {
return reject(new Error('Token inválido. Obtenha um em https://totalvoice.com.br'));
}
// DirectCall
const smsDirectCall = (from, to, token) => request.post(routeDirectCall('/sms/send'))
.set('Accept', 'application/json')
.send({
origem: from,
access_token: token,
destino: to,
texto: gemidaoInText
});

const callDirectCall = (from, to, token) => request.post(routeDirectCall('/sms/audio'))
.set('Access-Token', token)
.set('Accept', 'application/json')
.send({
access_token: token,
audio: 'https://github.com/haskellcamargo/gemidao-do-zap/raw/master/resources/gemidao.mp3'
});

// Comum
export default function gemidao(args) {
if (!/^[0-9]{10,11}$/.test(args.para)) {
return reject(new Error('Número de telefone inválido'));
}

const action = args.sms
? sms(args.para, args.token)
: call(args.de, args.para, args.token);
switch(args.api) {
case "TotalVoice":
if (!/^[a-f0-9]{32}$/.test(args.token)) {
return reject(new Error('Token inválido. Obtenha um em https://totalvoice.com.br'));
}

const action = args.sms
? smsTotalVoice(args.para, args.token)
: callTotalVoice(args.de, args.para, args.token);
break;
case "DirectCall":
if (!/^[a-f0-9]{45}$/.test(args.token)) {
return reject(new Error('Token inválido. Obtenha um em https://www.directcallsoft.com'));
}

const action = args.sms
? smsDirectCall(args.de, args.para, args.token)
: callDirectCall(args.de, args.para, args.token);
break;
default:
return reject(new Error('Escolha uma das APIs Suportadas: DirectCall ou TotalVoice.'));
}

return action
.catch(err => {
Expand Down