Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 2 additions & 14 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,9 @@ const emitSuccess = message => console.log(green(` ✔ Sucesso: ${message}`));
const emitError = message => console.log(red(` ✗ Erro: ${message}`));

function cli(args) {
if (args.bidirecional) {
send(args);
const temp = args.de;
args.de = args.para;
args.para = temp;
send(args);
} else {
send(args);
}
}

function send(arg) {
gemidao(arg)
gemidao(args)
.then(() => {
emitSuccess(arg.sms ? 'sms enviado!' : 'chamada efetuada!');
emitSuccess(args.sms ? 'sms enviado!' : 'chamada efetuada!');
})
.catch(pipe(prop('message'), emitError));
}
Expand Down
12 changes: 9 additions & 3 deletions src/gemidao.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const sms = (to, token) => request.post(route('/sms'))
const call = (from, to, token) => request.post(route('/composto'))
.set('Access-Token', token)
.set('Accept', 'application/json')
.send({
.send(msg_data(from, to));

function msg_data(from, to) {
return {
numero_destino: to,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deixa as variáveis em inglês. E bina é o sistema de identificação, não sei se seria o melhor nome para deixar o from, prefiro os nomes originais from e to

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@williamokano eu mantive o que vinha sendo feito porque isso é a estrutura de dados que o endpoint recebe, os nomes dos parâmetros foram mantidos também, só fiz desacoplar.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walteraa numero_destino e bina já existiam?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, viajei aqui, talvez sejam requisitos para enviar a totalvoice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sim, são os dados recebidos pelo totalvoice, segundo a doc deles(https://api2.totalvoice.com.br/doc/#!/Composto/post_composto)

dados: [
{
Expand All @@ -27,7 +30,8 @@ const call = (from, to, token) => request.post(route('/composto'))
}
],
bina: from
});
};
}

export default function gemidao(args) {
if (!/^[a-f0-9]{32}$/.test(args.token)) {
Expand All @@ -40,7 +44,9 @@ export default function gemidao(args) {

const action = args.sms
? sms(args.para, args.token)
: call(args.de, args.para, args.token);
: (args.bidirecional
? call(args.de, args.para, args.token)
: call(args.de, args.para, args.token).send(msg_data(args.para, args.de)));

return action
.catch(err => {
Expand Down