add more discord bot config and docs

This commit is contained in:
Brett Taylor committed 2021-04-27 14:41:06 -04:00
1 parent f59dbeec3b
commit 3831809f6c
8 files changed
+138 -7

No files matched your search

+8 -1
View File
@@ -675,6 +675,13 @@
"fileName": "TelegramBot.js",
"folderName": "Trading-Bot/Announcements"
},
{
"name": "Discord Bot",
"propertyName": "discordBot",
"functionName": "newSuperalgosBotModulesDiscordBot",
"fileName": "DiscordBot.js",
"folderName": "Trading-Bot/Announcements"
},
{
"name": "Trading Process",
"propertyName": "tradingProcess",
@@ -943,4 +950,4 @@
]
}
}
]
]
@@ -0,0 +1,41 @@
{
"type": "Discord Bot",
"editors": {
"config": true
},
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Send Discord Test Message",
"label": "Send Discord Test Message",
"iconPathOn": "test-entity",
"iconPathOff": "test-entity",
"actionFunction": "payload.executeAction"
},
{
"action": "Delete UI Object",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"initialValues": {
"config": "{\n\"webhookURL\": \"Paste the webhook url obtained from Discord > Channel Settings > Integrations > Webhooks > New Webhook\"\n}"
},
"addLeftIcons": true,
"level": 4,
"attachingRules": {
"compatibleTypes": "->Social Bots->"
},
"childrenNodesProperties": [],
"propertyNameAtParent": "bots"
}
@@ -7,6 +7,12 @@
"relatedUiObject": "Telegram Bot",
"actionFunction": "payload.executeAction"
},
{
"action": "Add Discord Bot",
"label": "Add Discord Bot",
"relatedUiObject": "Discord Bot",
"actionFunction": "payload.executeAction"
},
{
"action": "Delete UI Object",
"askConfirmation": true,
@@ -26,9 +32,9 @@
{
"name": "bots",
"type": "array",
"childType": "Telegram Bot",
"childType": "Telegram Bot, Discord Bot",
"autoAdd": true
}
],
"propertyNameAtParent": "socialBots"
}
}
@@ -0,0 +1,14 @@
{
"type": "Discord Bot",
"definition": {
"text": "The Discord Bot node is used for defining the configuration for a Discord Bot. This bot allows Superalgos to send announcements to a Discord Channel.",
"updated": 1619546769461
},
"paragraphs": [
{
"style": "Link",
"text": "In order to use the Discord Bot, you will need to create a new Webhook Integration in Discord. The only configuration that is required within Superalgos is the webhookURL.",
"updated": 1619546875758
}
]
}
@@ -8,8 +8,8 @@
},
{
"style": "Note",
"text": "At present Superalgos only supports the Telegram messaging application.",
"updated": 1618221056200
"text": "At present Superalgos only supports Telegram and Discord messaging applications.",
"updated": 1619547181067
}
],
"definition": {
@@ -3,7 +3,6 @@ exports.newSuperalgosBotModulesDiscordBot = function (processIndex) {
const MODULE_NAME = 'Discord Bot'
let thisObject = {
DiscordBot: undefined,
webhookURL: undefined,
sendMessage: sendMessage,
initialize: initialize,
@@ -717,6 +717,11 @@ function newSuperalgosActionSwitch() {
UI.projects.superalgos.functionLibraries.socialBotsFunctions.sendTelegramTestMessage(action.node, action.callBackFunction)
}
break
case 'Send Discord Test Message':
{
UI.projects.superalgos.functionLibraries.socialBotsFunctions.sendDiscordTestMessage(action.node, action.callBackFunction)
}
break
}
}
}
@@ -1,6 +1,7 @@
function newSuperalgosFunctionLibrarySocialBotsFunctions() {
thisObject = {
sendTelegramTestMessage: sendTelegramTestMessage
sendTelegramTestMessage: sendTelegramTestMessage,
sendDiscordTestMessage: sendDiscordTestMessage
}
return thisObject
@@ -70,4 +71,62 @@ function newSuperalgosFunctionLibrarySocialBotsFunctions() {
}
}
}
function sendDiscordTestMessage(node, callBackFunction) {
let webhookURL = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'webhookURL')
if (webhookURL === undefined) {
node.payload.uiObject.setErrorMessage('webhookURL parameter not defined.')
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
let params = {
text: "Test message from Superalgos!"
}
httpRequestJSON(JSON.stringify(params), 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 })
}
}
}
}
}