Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eb60c2
commit cb7a9f0
Showing
7 changed files
with
128 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,4 @@ typings/ | |
# dotenv environment variables file | ||
.env | ||
|
||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Bluebird, { reject } from 'bluebird'; | ||
import agent from 'superagent'; | ||
import promisifyAgent from 'superagent-promise'; | ||
|
||
const request = promisifyAgent(agent, Bluebird); | ||
const route = path => `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')) | ||
.set('Access-Token', token) | ||
.set('Accept', 'application/json') | ||
.send({ numero_destino: to, mensagem: gemidaoInText }) | ||
.catch(err => { | ||
if (err.status === 405) { | ||
return reject(new Error(err.body.mensagem)); | ||
} | ||
|
||
return reject(err); | ||
}); | ||
|
||
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')); | ||
} | ||
|
||
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) | ||
: x => reject(new Error('...')); | ||
|
||
return action | ||
.catch(err => { | ||
if (err.status === 405) { | ||
return reject(new Error(err.body.mensagem)); | ||
} | ||
|
||
return reject(err); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters