From 4dd6db9c24333afe5ef2fe3d159060297bbb10a8 Mon Sep 17 00:00:00 2001
From: Renzo <rontivero@ultimamillasa.com.ar>
Date: Mon, 18 May 2020 17:08:37 -0300
Subject: [PATCH] =?UTF-8?q?A=C3=B1adiendo=20envio=20de=20whatsapp=20Celo?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 api/controllers/CeloController.js | 13 ++++++
 api/helpers/enviar-whatsapp.js    | 76 +++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100755 api/helpers/enviar-whatsapp.js

diff --git a/api/controllers/CeloController.js b/api/controllers/CeloController.js
index 709d6d6..f6fc6da 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 0000000..40bbe34
--- /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'
+      };
+    }
+  }
+
+
+};
+
-- 
GitLab