mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
fixing telegram issues
This commit is contained in:
@@ -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 <b>${serviceName}</b> found <b>${newListings.length}</b> new listings:\n\n`;
|
||||
|
||||
message += newListings.map(
|
||||
(o) =>
|
||||
`*${shorten(o.title.replace(/\*/g, ''), 45)}*\n` +
|
||||
`<b>${shorten(o.title.replace(/\*/g, ''), 45)}</b>\n` +
|
||||
[o.address, o.price, o.size].join(' | ') +
|
||||
'\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) {
|
||||
|
||||
Reference in New Issue
Block a user