@WebpageBot can update link previews in Telegram, but doesn't have a web API. This project creates a userbot that sends links to @WebpageBot to refresh the cache.
- Send single or multiple URLs to update Telegram link previews
- Auto-mark messages as read with random delay (500-2000ms)
- RESTful HTTP API
- Environment-based configuration
npm installCreate a .env file with your Telegram API credentials:
cp .env.example .envEdit .env and add your credentials (get them from my.telegram.org):
TG_API_ID=your_api_id
TG_API_HASH=your_api_hashFirst time only, you need to login:
npm run loginFollow the prompts to enter your phone number and verification code.
npm startServer will start on http://127.0.0.1:2344
Send a single URL:
curl http://127.0.0.1:2344/ -X POST --data 'url=https://www.google.com'Send multiple URLs:
curl http://127.0.0.1:2344/ -X POST \
-H "Content-Type: application/json" \
-d '{
"url": [
"https://www.google.com",
"https://github.com",
"https://twitter.com"
]
}'Response:
{
"ok": true,
"status": "sent"
}// Using fetch
async function updateLinkPreview(urls) {
const response = await fetch('http://127.0.0.1:2344/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: Array.isArray(urls) ? urls : [urls]
})
})
return await response.json()
}
// Single URL
await updateLinkPreview('https://example.com')
// Multiple URLs
await updateLinkPreview([
'https://example.com',
'https://github.com',
'https://twitter.com'
])// Using axios
const axios = require('axios')
async function updateLinkPreview(urls) {
const response = await axios.post('http://127.0.0.1:2344/', {
url: Array.isArray(urls) ? urls : [urls]
})
return response.data
}
// Usage
updateLinkPreview('https://example.com')
.then(result => console.log(result))
.catch(error => console.error(error))import requests
def update_link_preview(urls):
"""
Update Telegram link preview cache
Args:
urls: Single URL string or list of URLs
Returns:
dict: Response from API
"""
if isinstance(urls, str):
urls = [urls]
response = requests.post(
'http://127.0.0.1:2344/',
json={'url': urls}
)
return response.json()
# Single URL
result = update_link_preview('https://example.com')
print(result)
# Multiple URLs
result = update_link_preview([
'https://example.com',
'https://github.com',
'https://twitter.com'
])
print(result)# Using httpx (async)
import httpx
import asyncio
async def update_link_preview(urls):
if isinstance(urls, str):
urls = [urls]
async with httpx.AsyncClient() as client:
response = await client.post(
'http://127.0.0.1:2344/',
json={'url': urls}
)
return response.json()
# Usage
async def main():
result = await update_link_preview('https://example.com')
print(result)
asyncio.run(main())- Built with Koa web framework
- Uses tdl for Telegram client
- Messages are automatically marked as read after a random delay (500-2000ms)
- Supports ES6 modules
MIT
Based on tdl by eilvelia