Skip to main content

A simple telegram bot api

Project description

Simple Telegram Bot

A simple and easy-to-use Python library for Telegram bots. This library allows you to send messages, edit messages, fetch updates, and handle messages easily.

Installation

Installation using pip (a Python package manager):

pip install simple-telegram-api

Usage/Examples

A simple echo bot:

from simple_telegram_api import TelegramBot

BOT_TOKEN = "BOT_TOKEN"

bot = TelegramBot(BOT_TOKEN)

# Skip old messages before bot is running.
bot.reset_updates()

print("Bot is running.")
while True:
    updates = bot.get_updates()

    # Check if it's empty.
    if updates:
        print(updates)
        bot.reset_updates(updates=updates)

        # For multiple coming up messages.
        for update in updates["result"]:
            chat_id = update["message"]["chat"]["id"]
            user_message = update["message"]["text"]
            
            bot_update = bot.send_message(user_message, chat_id=chat_id)
            print(bot_update)

Using the TelegramBot Class

from simple_telegram_api import TelegramBot

bot = TelegramBot('BOT_TOKEN')

Get Updates

This function gets new messages from Telegram.

updates = bot.get_updates()

Reset Updates

This method gets updates from Telegram and skips old messages.

bot.reset_updates()

Send Message

To send a message:

bot.send_message(text=text, chat_id=chat_id)

To reply to a message:

bot.send_message(text=text, chat_id=chat_id, reply_to_message=True, message_id=message_id)

Edit Message

bot.edit_message(text=text, chat_id=chat_id, message_id=message_id)

Recommendations

If updates is not provided in reset_updates(), new updates will be fetched automatically. Use the result from get_updates() as updates, as shown in the example.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_telegram_api-0.2.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

simple_telegram_api-0.2.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file simple_telegram_api-0.2.0.tar.gz.

File metadata

  • Download URL: simple_telegram_api-0.2.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for simple_telegram_api-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4a153bb4af8259dd60c16c49589b04224ed709f469a7810cc14997d87aa58fa5
MD5 cd206468703fae0eb7ff66ba481252b7
BLAKE2b-256 ef5f9f5635efd1bf49de0b6a26ec50a0c79d467aad0d7de77f27b7b035f3431b

See more details on using hashes here.

File details

Details for the file simple_telegram_api-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_telegram_api-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc9746b3d7a9b4dcc6fc4a84432bd3dc5a6c37573c51c3db2e9b6b9f003e0f69
MD5 3e2ac924c64a39147df44529be489de1
BLAKE2b-256 68204f087a4803308d3c7c600ee011dc15ade068e63fd97b586927edfc94996f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page