(Unofficial) BBC News bot for Telegram
After browsing a wide range of Telegram bot lists and directories, I managed to find several BBC News bots. From the few that still worked, the remaining lacked in quality. So, I decided to make my own.
With this being my first bot for Telegram, I conducted research into libraries that support the Telegram API.
NodeJS programming language was chosen for its server-side capabilities, allowing me to setup the bot on a server to manage user commands given in the app.
Finally, as BBC News actively uses RSS feeds, using this XML data would be a no brainer as each news category has its own feed. Although it is simple to parse XML data, I chose to use a third-party library to speed this process up.
The following node packages were used:
# NPM packages npm i node-telegram-bot-api npm i rss-parser
Looking through BBC News I managed to find
88 feeds available, so I decided to support them all.
Based on the type of news requested by the user, for example
/science, the bot will simply identify which URL is needed to parse the XML data and return articles to the user based on a limit they have set.
Bot was setup on a Heroku dyno making deployment quick and painless.
As network outages and other exceptions are inevitable, I developed the bot to manage most scenarios.
For example, if a feed does not return XML data or a 2XX status code, the bot will notify the developer to an error, its reasons why, and will attempt alternative methods to get the news for the user. Should that also fail, it will notify the user.
After running successfully for a number of weeks, all of BBC News feeds (except for 1 which has a different setup and structure to all other feeds) went offline without reason (all returned error 404).
When researching the problem online, many users complained as apps and services that aggregated news did not display any BBC articles.
Reasons to why this happened were never disclosed, however, it became apparent that even the BBC does not have 100% uptime and required an alternative method to guarantee delivery of news content for the bot.
In this eventuality, the bot will crawl a given category for example
/scotland and gather URLs from the page.
Perhaps offering the user of the bot the ability to subscribe to given command(s). For example, when using the
/notifycommand, they pass in a number which acts as frequency (min/hour) and the category they wish.
Example as follows:
# Retrieve politics news every 6 hours. /notify -6 politics
The second improvement will be used to gauge the bots’ interest. There are currently no methods implemented to measure its usage, and by employing this feature would help measure its popularity.
Currently, user’s of the bot are not aware of latest changes. The final improvement would allow users to opt-in for bot updates.
With at least 88 commands available, I am pleased with how well (and quickly) it works. Others have also expressed interest in the bot, so as it is now publicly available, click here to start using the bot.