diff --git a/lib/notification/adapter/telegram.js b/lib/notification/adapter/telegram.js index 745a71e..30ef672 100644 --- a/lib/notification/adapter/telegram.js +++ b/lib/notification/adapter/telegram.js @@ -1,4 +1,5 @@ const { markdown2Html } = require('../../services/markdown'); +const { getJob } = require('../../services/storage/jobStorage'); const axios = require('axios'); /** @@ -19,23 +20,24 @@ const arrayChunks = (inputArray, perChunk) => * @param serviceName e.g immowelt * @param newListings an array with newly found listings * @param notificationConfig config of this notification adapter - * * @param jobKey name of the current job that is being executed + * @param jobKey name of the current job that is being executed * @returns {Promise | void} */ exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => { const { token, chatId } = notificationConfig.find((adapter) => adapter.id === 'telegram').fields; + const job = getJob(jobKey); + const jobName = job == null ? jobKey : job.name; //we have to split messages into chunk, because otherwise messages are going to become too big and will fail const chunks = arrayChunks(newListings, 3); const promises = chunks.map((chunk) => { - let message = `Job: ${jobKey} | Service ${serviceName} found ${newListings.length} new listings:\n\n`; + let message = `${jobName} (${serviceName}) found ${newListings.length} new listings:\n\n`; message += chunk.map( (o) => - `${shorten(o.title.replace(/\*/g, ''), 45)}\n` + + `${shorten(o.title.replace(/\*/g, ''), 45).trim()}\n` + [o.address, o.price, o.size].join(' | ') + - '\n' + - `${o.link}\n\n` + '\n\n' ); return axios.post(`https://api.telegram.org/bot${token}/sendMessage`, {