Skip to main content

Telegram bot library for Python and humans

Project description

TeBot - Telegram bot library for Python and humans

The goal is to to keep it simple.

How to use

Start bot

If your project uses neotasker

from tebot import TeBot

# interval - polling interval, must be specified
mybot = TeBot(interval=2)
# obtain token from https://telegram.me/BotFather
mybot.set_token('botsecrettoken')
# optionally - load previous state
import json
with open('bot-state.json') as fh:
    mybot.load(json.loads(fh.read()))
mybot.start()

If it doesn't:

from neotasker import task_supervisor

task_supervisor.create_aloop('default', default=True)
task_supervisor.start()
mybot = TeBot(interval=2)
mybot.set_token('botsecrettoken')
mybot.start()

(refer to neotasker documentation for more info)

Stop bot

mybot.stop()
# if your project doesn't use neotasker
task_supervisor.stop()
# optionally - save bot state
with open('bot-state.json', 'w') as fh:
    fh.write(json.dumps(mybot.serialize()))

Send messages

# text
mybot.send(chat_id, msg='hello world')
# files
with open('image.jpg', 'rb') as fh:
    mybot.send(chat_id, media=fh.read())

Handle incoming messages

Override class methods:

  • handle_message(self, chat_id, text) handle regular messages

  • handle_command(self, chat_id, cmd) handle commands (starting with '/')

  • on_message override to implement advanced handling

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

tebot-0.0.1.tar.gz (125.9 kB view hashes)

Uploaded Source

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