diff --git a/api/controllers/CeloController.js b/api/controllers/CeloController.js index 709d6d6e48ec71afe2f189f30358c9d9d2afe661..f6fc6da86b5649f1c2e431c62e9dfd17f60953e1 100755 --- a/api/controllers/CeloController.js +++ b/api/controllers/CeloController.js @@ -61,6 +61,19 @@ module.exports = { // 19. Print new balance console.log(`Your new account balance: ${balance.toString()}`) + + + if(req.body.phone){ + var notificacion = `Your transaction was successfully sent ! The hash is ${receipt.transactionHash}. Greetings team Celo`; + + // Notifico por whatsapp + await sails.helpers.enviarWhatsapp.with({ + texto: notificacion + numero: req.body.phone, + }); + + } + return res.json({ status: 'ok', tx: receipt diff --git a/api/helpers/enviar-whatsapp.js b/api/helpers/enviar-whatsapp.js new file mode 100755 index 0000000000000000000000000000000000000000..40bbe34089eb63d97ddf634e10714a96b8044c15 --- /dev/null +++ b/api/helpers/enviar-whatsapp.js @@ -0,0 +1,76 @@ +const axios = require('axios'); +const querystring = require('querystring'); // Luego modificar envÃos por POST + +module.exports = { + + + friendlyName: 'Enviar whatsapp', + + + description: '', + + + inputs: { + texto: { + type: 'string', + require : true + }, + + numero: { + type: 'string', + require: true + } + }, + + + exits: { + + success: { + description: 'All done.', + }, + + }, + + + fn: async function (inputs) { + var data = querystring.stringify({ + texto : inputs.texto, + telefono : inputs.telefono + }); + + const response = await axios.get('http://190.105.227.247/~umbot/api-whatsapp/?'+data) + .then((response) => { + return response; + }) + .catch((err) => { + return { + status : 201, + statusText : String(err.message), + } + }); + + + // Respuesta + if(response.status == 200 && response.statusText == 'OK'){ + + sails.log.info( + 'Send whatsapp complete: \n'+ + util.inspect(inputs,{depth:null}) + ); + return { + status : 'ok', + }; + } else { + sails.log.info( + 'Send whatsapp incomplete: \n'+ + util.inspect(inputs,{depth:null}) + ); + return { + status : 'fail' + }; + } + } + + +}; +