Update index.js
This commit is contained in:
parent
aaa7106c9e
commit
6a00759424
44
index.js
44
index.js
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
const Request = require('request-promise');
|
||||||
const dotenv = require('dotenv');
|
const dotenv = require('dotenv');
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -43,11 +44,11 @@ try {
|
|||||||
|
|
||||||
}, 60000).then(ws => {
|
}, 60000).then(ws => {
|
||||||
console.log(`${event} - Monitoring Spot User Order Data for binance.com`);
|
console.log(`${event} - Monitoring Spot User Order Data for binance.com`);
|
||||||
toTelegram(`<b>Binance Spot Order Monitor Started</b>\nthis message shows that you or heroku(if your are using) restart the bot.`)
|
sendMessage(`<b>Binance Spot Order Monitor Started</b>\nthis message shows that you or heroku(if your are using) restart the bot.`)
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`${event} - ${err}`)
|
console.error(`${event} - ${err}`)
|
||||||
toTelegram(err.toString())
|
sendMessage(err.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
function fixFloat(floatNum, Precision = 8) {
|
function fixFloat(floatNum, Precision = 8) {
|
||||||
@ -82,22 +83,39 @@ function process_data(data) {
|
|||||||
} else {
|
} else {
|
||||||
txt = `⚠️ ⚠️ ⚠️\n<b>Undefined</b>\nExecution Type: ${data.executionType}\nOrder Status ${data.orderStatus}\nFull Details:\n${msg}`
|
txt = `⚠️ ⚠️ ⚠️\n<b>Undefined</b>\nExecution Type: ${data.executionType}\nOrder Status ${data.orderStatus}\nFull Details:\n${msg}`
|
||||||
}
|
}
|
||||||
toTelegram(txt)
|
sendMessage(txt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toTelegram(text) {
|
function sendMessage(text) {
|
||||||
let parse_mode = {
|
let params = {
|
||||||
|
chat_id: chat_id,
|
||||||
|
text: text,
|
||||||
parse_mode: 'html'
|
parse_mode: 'html'
|
||||||
};
|
};
|
||||||
bot.sendMessage(chat_id, text, parse_mode)
|
let options = {
|
||||||
.then(message => {
|
uri: 'https://api.telegram.org/bot' + token + '/' + 'sendMessage',
|
||||||
//console.log(message);
|
qs: params,
|
||||||
if (message['ok'] === true) {
|
simple: false,
|
||||||
console.log(`${event} - Message send to ${message['result']['chat']['first_name']} via Telegram`)
|
resolveWithFullResponse: true,
|
||||||
} else if (message['ok'] === false) {
|
forever: true
|
||||||
console.log(`${event} - something went wrong while sending message to telegram see detailed error below.`)
|
};
|
||||||
console.error(message)
|
return Request(options)
|
||||||
|
.then(resp => {
|
||||||
|
if (resp.statusCode !== 200) {
|
||||||
|
throw new Error(resp.statusCode + ':\n' + resp.body);
|
||||||
}
|
}
|
||||||
|
let updates = JSON.parse(resp.body);
|
||||||
|
if (updates.ok) {
|
||||||
|
console.log("Message send via Telegram")
|
||||||
|
return updates;
|
||||||
|
} else {
|
||||||
|
console.log(`something went wrong while sending message to telegram see detailed error below.`)
|
||||||
|
console.error(updates)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user