From 1b38361935d2359f4f81a7f9322b203cf47ce5f1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 10 Oct 2021 12:39:42 +0200 Subject: [PATCH] Delete SocialBotsFunctions.js --- .../Function-Libraries/SocialBotsFunctions.js | 234 ------------------ 1 file changed, 234 deletions(-) delete mode 100644 Projects/Foundations/UI/Function-Libraries/SocialBotsFunctions.js diff --git a/Projects/Foundations/UI/Function-Libraries/SocialBotsFunctions.js b/Projects/Foundations/UI/Function-Libraries/SocialBotsFunctions.js deleted file mode 100644 index 241537375..000000000 --- a/Projects/Foundations/UI/Function-Libraries/SocialBotsFunctions.js +++ /dev/null @@ -1,234 +0,0 @@ -function newFoundationsFunctionLibrarySocialBotsFunctions() { - let thisObject = { - sendTelegramTestMessage: sendTelegramTestMessage, - sendDiscordTestMessage: sendDiscordTestMessage, - sendSlackTestMessage: sendSlackTestMessage, - sendTwitterTestMessage: sendTwitterTestMessage - } - - return thisObject - - function sendTelegramTestMessage(node, callBackFunction) { - - let botToken = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'botToken') - let chatId = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'chatId') - - if (botToken === undefined) { - node.payload.uiObject.setErrorMessage('botToken parameter not defined.') - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - if (chatId === undefined) { - node.payload.uiObject.setErrorMessage('chatId parameter not defined.') - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - let params = { - text: "Test Message from Superalgos", - chat_id: chatId - } - - httpRequestJSON(JSON.stringify(params),"https://api.telegram.org/bot" + botToken + "/sendMessage", onResponse) - - function onResponse(err) { - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setInfoMessage('Telegram message sent.') - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - } else { - node.payload.uiObject.setErrorMessage('Could not send Telegram message. Error Response: ' + err.message) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - - function httpRequestJSON(pContentToSend, pPath, callBackFunction) { - let xmlHttpRequest = new XMLHttpRequest(); - xmlHttpRequest.onreadystatechange = function () { - if (this.readyState === 4 && this.status === 200) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText); - return; - } else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) { - callBackFunction({ - result: "Fail", - message: JSON.parse(xmlHttpRequest.responseText).description, - code: JSON.parse(xmlHttpRequest.responseText).error_code - }); - return; - } - }; - - if (pContentToSend === undefined) { - xmlHttpRequest.open("GET", pPath, true); - xmlHttpRequest.send(); - } else { - try { - let blob = new Blob([pContentToSend], { type: 'application/json' }); - xmlHttpRequest.open("POST", pPath, true); - xmlHttpRequest.send(blob); - } catch (err) { - if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); } - callBackFunction({ result: "Fail", message: err.message }) - } - } - } - } - - function sendDiscordTestMessage(node, callBackFunction) { - - let webhookURL = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'webhookURL') - - if (webhookURL === undefined) { - node.payload.uiObject.setErrorMessage('webhookURL parameter not defined.') - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - let message = "Test message from Superalgos!" - - httpRequestJSON(JSON.stringify({content: message}), webhookURL, onResponse) - - function onResponse(err) { - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setInfoMessage('Discord message sent.') - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - } else { - node.payload.uiObject.setErrorMessage('Could not send Discord message. Error Response: ' + err.message) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - - function httpRequestJSON(pContentToSend, pPath, callBackFunction) { - let xmlHttpRequest = new XMLHttpRequest(); - xmlHttpRequest.onreadystatechange = function () { - if (this.readyState === 4 && this.status === 200) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText); - return; - } else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) { - callBackFunction({ - result: "Fail", - message: JSON.parse(xmlHttpRequest.responseText).description, - code: JSON.parse(xmlHttpRequest.responseText).error_code - }); - return; - } - }; - - if (pContentToSend === undefined) { - xmlHttpRequest.open("GET", pPath, true); - xmlHttpRequest.send(); - } else { - try { - let blob = new Blob([pContentToSend], { type: 'application/json' }); - xmlHttpRequest.open("POST", pPath, true); - xmlHttpRequest.send(blob); - } catch (err) { - if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); } - callBackFunction({ result: "Fail", message: err.message }) - } - } - } - } - - function sendSlackTestMessage(node, callBackFunction) { - - let webhookURL = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'webhookURL') - - if (webhookURL === undefined) { - node.payload.uiObject.setErrorMessage('webhookURL parameter not defined.') - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - let message = "Test message from Superalgos!" - - httpRequestJSON(JSON.stringify({text: message}), webhookURL, onResponse) - - function onResponse(err) { - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setInfoMessage('Slack message sent.') - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - } else { - node.payload.uiObject.setErrorMessage('Could not send Slack message. Error Response: ' + err.message) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - - function httpRequestJSON(pContentToSend, pPath, callBackFunction) { - let xmlHttpRequest = new XMLHttpRequest(); - xmlHttpRequest.onreadystatechange = function () { - if (this.readyState === 4 && this.status === 200) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText); - return; - } else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) { - callBackFunction({ - result: "Fail", - message: xmlHttpRequest.responseText - }); - return; - } - }; - - if (pContentToSend === undefined) { - xmlHttpRequest.open("GET", pPath, true); - xmlHttpRequest.send(); - } else { - try { - let blob = new Blob([pContentToSend]); - xmlHttpRequest.open("POST", pPath, true); - xmlHttpRequest.send(blob); - } catch (err) { - if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); } - callBackFunction({ result: "Fail", message: err.message }) - } - } - } - } - - function sendTwitterTestMessage(node, callBackFunction) { - let message = JSON.stringify({text: "Test message from Superalgos!"}) - let url = "https://api.twitter.com/1.1/statuses/update.json" - - httpRequestJSON(message, url, onResponse) - - function onResponse(err) { - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setInfoMessage('Twitter status update sent.') - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - } else { - node.payload.uiObject.setErrorMessage('Could not send Twitter status update. Error Response: ' + err.message) - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - - function httpRequestJSON(pContentToSend, pPath, callBackFunction) { - let xmlHttpRequest = new XMLHttpRequest(); - xmlHttpRequest.onreadystatechange = function () { - if (this.readyState === 4 && this.status === 200) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText); - return; - } else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) { - callBackFunction({ - result: "Fail", - message: xmlHttpRequest.responseText - }); - return; - } - }; - - if (pContentToSend === undefined) { - xmlHttpRequest.open("GET", pPath, true); - xmlHttpRequest.send(); - } else { - try { - let blob = new Blob([pContentToSend]); - xmlHttpRequest.open("POST", pPath, true); - xmlHttpRequest.send(blob); - } catch (err) { - if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); } - callBackFunction({ result: "Fail", message: err.message }) - } - } - } - } -}