Skip to content

Add bidirectional call/sms send #18

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
26 changes: 21 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ const emitSuccess = message => console.log(green(` ✔ Sucesso: ${message}`));
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));
if (args.bidirecional) {
send(args);
const temp = args.de;
args.de = args.para;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Não querendo ser muito chato, mas já sendo, esse pedacinho que vc faz o swap, da pra dar uma melhoradinha, não? rsrs

Copy link
Collaborator

@cuchi cuchi Aug 9, 2017

Choose a reason for hiding this comment

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

Eu usaria o ramda:

const swapValues = (key1, key2, obj) => pipe(
  assoc(key1, obj[key2]),
  assoc(key2, obj[key1]))
    (obj);

// ...
if (args.bidirecional) {
  send(args);
  send(swapValues('de', 'para', args))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Achei elegante

Copy link
Author

@walteraa walteraa Aug 9, 2017

Choose a reason for hiding this comment

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

Resolvi desacoplando os dados da msg, isso possibilita modificar o padrão from/to e fazer outra chamada send após gerar a call invertendo os valores, o que vocês acham @williamokano @cuchi?

args.para = temp;
send(args);
} else {
send(args);
}
}

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

cli(yargs
Expand All @@ -34,6 +46,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