Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/botPage/bot/Interface/MiscInterface.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import { notify } from '../broadcast';
import { translate } from '../../../common/i18n';
import { observer as globalObserver } from '../../../common/utils/observer';

export default Interface =>
class extends Interface {
// eslint-disable-next-line class-methods-use-this
notifyTelegram(accessToken, chatId, text) {
const url = `https://api.telegram.org/bot${accessToken}/sendMessage`;
const onError = () => notify('warn', translate('The Telegram notification could not be sent'));

fetch(url, {
method : 'POST',
mode : 'cors',
headers: { 'Content-Type': 'application/json' },
body : JSON.stringify({ chat_id: chatId, text }),
})
.then(response => {
if (!response.ok) {
onError();
}
})
.catch(onError);
}

getMiscInterface() {
return {
notify : args => globalObserver.emit('Notify', args),
notifyTelegram: this.notifyTelegram,
getTotalRuns : () => this.tradeEngine.getTotalRuns(),
getBalance : type => this.tradeEngine.getBalance(type),
getTotalProfit: () => this.tradeEngine.getTotalProfit(),
Expand Down
1 change: 1 addition & 0 deletions src/botPage/view/blockly/blocks/tools/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './balance';
import './notify';
import './notify_telegram';
import './total_profit';
import './total_runs';
import './block_holder';
Expand Down
45 changes: 45 additions & 0 deletions src/botPage/view/blockly/blocks/tools/notify_telegram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { translate } from '../../../../../common/i18n';

Blockly.Blocks.notify_telegram = {
init() {
this.jsonInit({
message0: translate('Notify Telegram %1 Access Token: %2 Chat ID: %3 Message: %4'),
args0 : [
{
type: 'input_dummy',
},
{
type: 'input_value',
name: 'TELEGRAM_ACCESS_TOKEN',
},
{
type: 'input_value',
name: 'TELEGRAM_CHAT_ID',
},
{
type: 'input_value',
name: 'TELEGRAM_MESSAGE',
},
],
colour : '#dedede',
inputsInline : true,
previousStatement: null,
nextStatement : null,
tooltip : translate('Sends a message to Telegram'),
});
},
};

Blockly.JavaScript.notify_telegram = block => {
const accessToken =
Blockly.JavaScript.valueToCode(block, 'TELEGRAM_ACCESS_TOKEN', Blockly.JavaScript.ORDER_ATOMIC) || '';
const chatId = Blockly.JavaScript.valueToCode(block, 'TELEGRAM_CHAT_ID', Blockly.JavaScript.ORDER_ATOMIC) || '';
const message = Blockly.JavaScript.valueToCode(block, 'TELEGRAM_MESSAGE', Blockly.JavaScript.ORDER_ATOMIC) || '';

if (!accessToken || !chatId || !message) {
return '';
}

const code = `Bot.notifyTelegram(${accessToken}, ${chatId}, ${message});\n`;
return code;
};
2 changes: 1 addition & 1 deletion src/common/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const addUiLang = () => {
el.text(translate($(this).attr('data-i18n-text'))).append(contents);
});

document.querySelectorAll('[data-i18n-title').forEach(titleNode => {
document.querySelectorAll('[data-i18n-title]').forEach(titleNode => {
titleNode.setAttribute('title', translate(titleNode.getAttribute('data-i18n-title')));
});
};
Expand Down
Loading