Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bidirectional call/sms send #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const emitError = message => console.log(red(` ✗ Erro: ${message}`));

function cli(args) {
gemidao(args)
.then(() => {
emitSuccess(args.sms ? 'sms enviado!' : 'chamada efetuada!');
})
.catch(pipe(prop('message'), emitError));
.then(() => {
emitSuccess(args.sms ? 'sms enviado!' : 'chamada efetuada!');
})
.catch(pipe(prop('message'), emitError));
}

cli(yargs
Expand All @@ -34,6 +34,10 @@ cli(yargs
describe: 'Se definido, será enviado um SMS ao invés de uma chamada',
type: 'boolean'
})
.option('bidirecional', {
describe: 'Se definido, realiza uma nova ligação, desta vez com o de/para invertidos',
type: 'boolean'
})
.demandOption(['para', 'token'])
.locale('pt_BR')
.strict()
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