Ditching Pocket Premium: Streamline link saving with Telegram
For the past two years, I’ve been using Pocket to save links that I want to revisit later. However, as my yearly subscription is about to expire, I’ve started thinking about finding a free alternative that offers the features I actually use, without paying for unnecessary extras.
Although Pocket Premium has a wide range of features, I primarily use it as a place to dump links and synchronize them between my PC and phone. For these purposes, I don’t really need the full functionality provided by Pocket Premium.
After considering my needs, I came up with a simpler solution. I can use Telegram to save links by sharing them to a private Telegram channel. On my phone using the Telegram app and on my desktop browser using a userscript.
Here’s how you can set it up:
- Create a Telegram bot using the BotFather. The BotFather will provide you with an API token for the bot.
- Create a private channel on Telegram and invite the bot you just created to the channel with permission to send messages.
- Obtain the chat ID of the channel. You can do this by sending a message to the channel, then copying the share link for the message. The share link has the structure of
https://t.me/c/<CHANNEL_ID>/<MESSAGE_ID>
. Please note that the Telegram Bot API requires the-100
prefix for private channels. Without it, you’ll encounter an error stating that the chat was not found. For public channels, you can simply use@channelname
instead.
For the userscript, you can use a userscript manager like Violentmonkey. This userscript will allow you to send the current page link and title to your private Telegram channel directly from your browser. Follow these steps:
- Install the Violentmonkey extension for your browser.
- Click on the Violentmonkey icon in your browser toolbar and select “Create a new script”.
- Replace the existing code in the script editor with the JavaScript code provided below.
- Modify the
botApiToken
andchatId
variables with your Telegram bot API token and channel ID. - Save the script.
Here’s the JavaScript code you need to enter into the Violentmonkey script editor:
// ==UserScript==
// @name Telegram Pocket
// @namespace https://jlelse.blog/dev/telegram-link-saving
// @version 0.1
// @description Send current page link and title with a Telegram bot to a channel
// @author Jan-Lukas Else
// @match *://*/*
// @grant GM_registerMenuCommand
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
function sendTelegramMessage() {
// Replace these values
const botApiToken = 'YOUR_BOT_TOKEN';
const chatId = -100YOUR_CHAT_ID;
// Get the current page's URL and title
const pageUrl = window.location.href;
const pageTitle = document.title;
// Telegram API endpoint for sending messages
const telegramApiUrl = `https://api.telegram.org/bot${botApiToken}/sendMessage`;
// Construct the message
const message = `${pageTitle}\n\n${pageUrl}`;
// Send the message to the Telegram Bot
GM_xmlhttpRequest({
method: 'POST',
url: telegramApiUrl,
data: JSON.stringify({
chat_id: chatId, // Replace with your Telegram chat ID
text: message
}),
headers: {
'Content-Type': 'application/json'
},
onload: function(response) {
console.log('Message sent to Telegram Bot:', response.responseText);
},
onerror: function(error) {
console.error('Error sending message:', error);
}
});
}
// Register the manual activation menu command
GM_registerMenuCommand('Save to Telegram Links', sendTelegramMessage);
})();
Remember to replace the YOUR_BOT_TOKEN
and YOUR_CHAT_ID
placeholders with the appropriate values for your setup.
Update: Originally, I tried to use a bookmarklet and shared the code here on this blog post. However a userscript is the better method as a lot of sites use CSP restrictions (for good reasons) and a userscript manager like Violentmonkey allows sending HTTP requests even from those sites.