T2972
This Telegram msg preprocessing function belongs in utils. Move it there.
Differential D13713
[herald] Move telegram function to telegram.js bytesofman on Apr 14 2023, 03:21. Authored by
Details
T2972 This Telegram msg preprocessing function belongs in utils. Move it there. npm test
Diff Detail
Event TimelineComment Actions I agree this function doesn't belong to parse.js, but it is a telegram specific function so it belongs to telegram.js. Also I don't think calling it from parse.js is a good api: it's much cleaner to have a method for sending the message that takes care of that. This means that you could have several messaging bots and don't have to reformat in the parse.js function for each of them. Comment Actions k will move it
It would be cleaner to have a method for sending the message that simply takes the whole msg and prepares it for whatever bot is about to send it. However such a function needs to be much more sophisticated -- it needs to know which "<" characters are part of URLs and should not be escaped vs which "<" characters are supposed to be rendered as "<" Would need to have an entire HTML parsing routine to figure this out. Even then, getBlockTgMessage has several hardcoded sections that depend on telegram's specific HTML parser. These would need to be replaced with some kind of parameter. I don't think it's technical debt to have a collection of parser specific functions like getBlockTweet, getBlockSlackMsg, etc, that all take the same data inputs but work with the different rulesets of each bot. There are too many differences between each given parser to make a clean master function. Each parser will have different character limits, API restrictions, parsing language, escape characters...parseBlock needs to be "the" parsing function, but having distinct msg building functions will be necessary. Comment Actions Moving the function to telegram.js -- need to refactor telegram.js to stop actually initializing the bot. This needs to be done in index.js and passed as a param for unit tests to work. Comment Actions This can be solved by passing the content unformatted, or with some kind of template. Let's keep that for a future diff, for now it's tg only. |