diff --git a/lib/notification/adapter/telegram.js b/lib/notification/adapter/telegram.js index 17fad01..6cfc7bc 100644 --- a/lib/notification/adapter/telegram.js +++ b/lib/notification/adapter/telegram.js @@ -1,6 +1,5 @@ -const TelegramBot = require('tg-yarl'); const { markdown2Html } = require('../../services/markdown'); -const opts = { parse_mode: 'Markdown' }; +const axios = require('axios'); /** * sends new listings to telegram @@ -13,19 +12,22 @@ const opts = { parse_mode: 'Markdown' }; exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => { const { token, chatId } = notificationConfig.find((adapter) => adapter.id === 'telegram').fields; - const bot = new TelegramBot(token); - - let message = `Job: ${jobKey} | Service _${serviceName}_ found _${newListings.length}_ new listings:\n\n`; + let message = `Job: ${jobKey} | Service ${serviceName} found ${newListings.length} new listings:\n\n`; message += newListings.map( (o) => - `*${shorten(o.title.replace(/\*/g, ''), 45)}*\n` + + `${shorten(o.title.replace(/\*/g, ''), 45)}\n` + [o.address, o.price, o.size].join(' | ') + '\n' + - `[LINK](${o.link})\n\n` + `${o.link}\n\n` ); - return bot.sendMessage(chatId, message, opts); + return axios.post(`https://api.telegram.org/bot${token}/sendMessage`, { + chat_id: chatId, + text: message, + parse_mode: 'HTML', + disable_web_page_preview: true, + }); }; function shorten(str, len = 30) { diff --git a/package.json b/package.json index 09c4579..93380e2 100755 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "semantic-ui-react": "2.0.3", "serve-static": "^1.14.1", "slack": "11.0.2", - "tg-yarl": "1.3.0", "x-ray": "2.3.4" }, "devDependencies": {