aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiyush Dixit <79581397+PiyushDixit96@users.noreply.github.com>2021-05-12 20:39:31 +0530
committerGitHub <noreply@github.com>2021-05-12 20:39:31 +0530
commit6a00759424b16222ee312f4769581b5a4bddfcf9 (patch)
tree30b0ee7b6dfebae3c3ed402fa27a0b51c2eef0bb
parentaaa7106c9e2460cf07658907cc0a5fb0a7b728ee (diff)
Update index.js
-rw-r--r--index.js44
1 files changed, 31 insertions, 13 deletions
diff --git a/index.js b/index.js
index b085ef2..54bc2f2 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,5 @@
#!/usr/bin/env node
+const Request = require('request-promise');
const dotenv = require('dotenv');
dotenv.config();
@@ -43,11 +44,11 @@ try {
}, 60000).then(ws => {
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) {
console.error(`${event} - ${err}`)
- toTelegram(err.toString())
+ sendMessage(err.toString())
}
function fixFloat(floatNum, Precision = 8) {
@@ -82,22 +83,39 @@ function process_data(data) {
} else {
txt = `⚠️ ⚠️ ⚠️\n<b>Undefined</b>\nExecution Type: ${data.executionType}\nOrder Status ${data.orderStatus}\nFull Details:\n${msg}`
}
- toTelegram(txt)
+ sendMessage(txt)
}
}
-function toTelegram(text) {
- let parse_mode = {
+function sendMessage(text) {
+ let params = {
+ chat_id: chat_id,
+ text: text,
parse_mode: 'html'
};
- bot.sendMessage(chat_id, text, parse_mode)
- .then(message => {
- //console.log(message);
- if (message['ok'] === true) {
- console.log(`${event} - Message send to ${message['result']['chat']['first_name']} via Telegram`)
- } else if (message['ok'] === false) {
- console.log(`${event} - something went wrong while sending message to telegram see detailed error below.`)
- console.error(message)
+ let options = {
+ uri: 'https://api.telegram.org/bot' + token + '/' + 'sendMessage',
+ qs: params,
+ simple: false,
+ resolveWithFullResponse: true,
+ forever: true
+ };
+ 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;
});
}