Skip to content

my-telegram-bots/WebpageBot-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebpageBot API

@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.

Features

  • 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

Setup

1. Install Dependencies

npm install

2. Configure Environment

Create a .env file with your Telegram API credentials:

cp .env.example .env

Edit .env and add your credentials (get them from my.telegram.org):

TG_API_ID=your_api_id
TG_API_HASH=your_api_hash

3. Login to Telegram

First time only, you need to login:

npm run login

Follow the prompts to enter your phone number and verification code.

4. Start the Server

npm start

Server will start on http://127.0.0.1:2344

API Usage

cURL Examples

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"
}

JavaScript SDK Example

// 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))

Python SDK Example

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())

Technical Details

  • 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

License

MIT

Credits

Based on tdl by eilvelia

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published