How to Get Facebook Page updates through a Telegram Channel

This is my first post here since the pandemic began or since WHO officially announced it. I hope this post finds you well and safe.

Facebook is ubiquitous here in the Philippines. It would seem that the many security and privacy issues being raised about it abroad hardly affect Filipinos. Only the more tech-savvy folks apparently care enough about its adverse effects. Every business and organization has flocked to it to set up pages and groups for communities. To keep abreast of any new updates, followers would “Like” pages and monitor their feeds daily. But there’s really no need to be sucked in to the blackhole of distractions that is the Facebook news feed. You don’t even need to have a Facebook account to see the posts of public pages!

Granted this solution might be too much for the average Facebook user, I’m still sharing it here for reference. Also, this solution only uses free and open-source software. (Well, maybe with the exception of Telegram but it’s free.)

In the past, Facebook offered RSS feeds for their pages. For the same reason Google killed Google Reader, Facebook has removed RSS altogether from the site. But RSS is what we need. Luckily, we have solutions like RSS-Bridge which allows us to create an RSS feed out of most popular websites. You can actually adapt this tutorial to get Telegram notifications for virtually any website where you can procure an RSS feed even with the help of RSS-Bridge. The possibilities are endless!

Install RSS-Bridge ideally on a server. The steps to do that are outside the scope of this article. If RSS-Bridge doesn’t make any sense to you, unfortunately the rest of this guide won’t be of any help. Facebook does its best to force people to use their app and website. Any business hoping to provide a service like the one described here will be shutdown. That’s why this solution is selfhosted and thus would have to be done privately as an individual. Some kind people do share their RSS-Bridge instances for others to use though…

With the help of the Telegram Bot and this RSS Feeder Bot script, the ingredients are complete.

The workflow looks like this:
Facebook page –> RSS-Bridge –> RSS_Feederbot –> Telegram

RSS-Bridge

https://github.com/RSS-Bridge/rss-bridge
Use RSS-Bridge to generate feeds for the Facebook pages you’d like to monitor. The resulting feed URL format goes like this:

1
https://YOUR_RSSBRIDGE_DOMAIN/?action=display&bridge=Facebook&context=User&u=FACEBOOKPAGE_URLNAME&media_type=all&limit=-1&format=Atom

The Facebook username is the string after facebook.com as in the example:
https://www.facebook.com/youtube
“youtube” is the username

OPTIONAL:
I did some small changes on the Facebook Bridge’s code to allow me to get certain updates only (e.g. videos) from the Facebook page. For some reason, the built-in media type filters didn’t work so I tweaked them myself. (I should probably make a GitHub issue on that.)

/var/www/rss-bridge/bridges/FacebookBridge.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
// Check media type
switch($this->getInput('media_type')) {
case 'all': break;
case 'video':
// if(empty($post->find('[aria-label=Video]'))) continue 2;
break;
case 'novideo':
// if(!empty($post->find('[aria-label=Video]'))) continue 2;
break;
default: break;
}
$media_type = $this->getInput('media_type');

...

if (($media_type == 'video' && strpos($item['uri'], '/videos/') !== false) || $media_type != 'video') {
$this->items[] = $item;
}

Telegram

Next is Telegram. I will outline the Telegram steps quickly below for reference.

  1. Create a new Telegram bot by messaging @BotFather. Note the token.
  2. Create Telegram channel. Set it to Private if you prefer.
  3. Add the Telegram bot to the channel as an Admin.
  4. Get the chat ID of the channel by posting something on the channel and sharing it to @get_id_bot

RSS_Feederbot [Telegram]

https://github.com/dbrennand/RSS_Feederbot
I changed the RSS Feeder Bot to receive updates on separate Telegram channels. So I’d have a dedicated channel in Telegram for each Facebook page I am monitoring. You’d only need one Telegram bot but you can get multiple chat IDs. Repeat the Telegram steps for as many channels as you need.

Now for the customized RSS Feeder Bot code.

feeds.json - add the chat IDs and leave date_title blank

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"somefacebookpage":
{
"url": "https://YOUR_RSSBRIDGE_DOMAIN/whateverfollows",
"date_title": "",
"chatid": "-999999999999"
},
"anotherfacebookpage":
{
"url": "https://YOUR_RSSBRIDGE_DOMAIN/anotherrss
"date_title": "",
"chatid": "-000000000000"
}
}

bot.py - a small change to use specified chat IDs in the JSON file

1
2
3
context.bot.send_message(chat_id=feed_data["chat_id"], text=rss_msg, parse_mode="Markdown")
...
updater = Updater(token="YOUR_TELEGRAMBOT_TOKEN", use_context=True)

Create a systemd service to easily start and stop the bot.

sudo nano /etc/systemd/system/telegramrssbot.service

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Telegram RSS Bot
After=syslog.target network.target

[Service]
Type=simple
User=YOUR_NONROOT_USER
ExecStart=/usr/bin/python3 /PATH_TO/RSS_Feederbot/bot.py
WorkingDirectory=/PATH_TO/RSS_Feederbot

[Install]
WantedBy=multi-user.target

And that’s it! You will now get Telegram notifications of new posts from the Facebook pages you’ve chosen. I find this useful right now for monitoring the Facebook pages of the churches I follow. It’s some work to setup but I save lots of time because of this. Not having to open Facebook and get trapped doomscrolling just to see what’s new is liberating.

This isn’t the only way to programmatically automate Telegram notifications from any source but until I check out other solutions, this works well enough for me now.

Tools used:

RSS-Bridge
Python Telegram Bot
RSS Feeder Bot