fixing telegram issues

This commit is contained in:
orangecoding
2021-05-14 10:36:17 +02:00
parent 38f4a7b149
commit 9f0bcbd85f
2 changed files with 10 additions and 9 deletions

View File

@@ -1,6 +1,5 @@
const TelegramBot = require('tg-yarl');
const { markdown2Html } = require('../../services/markdown'); const { markdown2Html } = require('../../services/markdown');
const opts = { parse_mode: 'Markdown' }; const axios = require('axios');
/** /**
* sends new listings to telegram * sends new listings to telegram
@@ -13,19 +12,22 @@ const opts = { parse_mode: 'Markdown' };
exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => { exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { token, chatId } = notificationConfig.find((adapter) => adapter.id === 'telegram').fields; const { token, chatId } = notificationConfig.find((adapter) => adapter.id === 'telegram').fields;
const bot = new TelegramBot(token); let message = `Job: ${jobKey} | Service <b>${serviceName}</b> found <b>${newListings.length}</b> new listings:\n\n`;
let message = `Job: ${jobKey} | Service _${serviceName}_ found _${newListings.length}_ new listings:\n\n`;
message += newListings.map( message += newListings.map(
(o) => (o) =>
`*${shorten(o.title.replace(/\*/g, ''), 45)}*\n` + `<b>${shorten(o.title.replace(/\*/g, ''), 45)}</b>\n` +
[o.address, o.price, o.size].join(' | ') + [o.address, o.price, o.size].join(' | ') +
'\n' + '\n' +
`[LINK](${o.link})\n\n` `<a href="${o.link}">${o.link}</a>\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) { function shorten(str, len = 30) {

View File

@@ -76,7 +76,6 @@
"semantic-ui-react": "2.0.3", "semantic-ui-react": "2.0.3",
"serve-static": "^1.14.1", "serve-static": "^1.14.1",
"slack": "11.0.2", "slack": "11.0.2",
"tg-yarl": "1.3.0",
"x-ray": "2.3.4" "x-ray": "2.3.4"
}, },
"devDependencies": { "devDependencies": {