Skip to main content

Library for writing task based telegram bots

Project description

telegram-task-bot

Library to setup telegram bots with recurring tasks.

Usage

pip install telegram-task-bot

.env Variables

  1. ALLOWED_USERS specifies the users which are allowed, if any, every one is allowed to use the bot.
  2. BOT_TOKEN the token of the bot.
  3. START_MESSAGE the message to be send as response to the start command.

Classes

There are several classes included in this Package.

Task

Base class for recurring tasks.

Configuration

  • job_name: str Name of the job defined in this task
  • disable_notifications: bool Disable notifications, flag send to the telegram server
  • generic: bool Defines if the task looks the same for each user
  • first_time:time First time to run the task, 0 is now takes a datetime.time
  • repeat_time: timedelta Defines the time between two executions of the job, takes datetime.timedelta
  • filename: str Filename under which data specific to this job should be saved

GenericTask

More specific class which adds the possiblity to get the actual value and implements user handling. The data is saved to a JSON file. The callback method ( callback(self, context: telegram.ext.CallbackContext)) must be implemented.

UrlTask

Extension of the GenericTask to simplify the usage for jobs calling a URL and returning the link/ response to the subscribers. It tries until it gets a response every 2 seconds.

This class adds a url field where the information lies.

The handle_response(self, response: Response) must be implemented to extract the data from the request and return the message string.

Example Project

https://github.com/bb4L/digitec_daily_bot

License

LGPLv3

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

telegram-task-bot-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file telegram-task-bot-0.1.1.tar.gz.

File metadata

  • Download URL: telegram-task-bot-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

File hashes

Hashes for telegram-task-bot-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0f44a729b14a178d4991fe6e4e01c63834a34a291a2f1b9c9359363102f2920c
MD5 e263df8d684cd850ec0514e98ae7ad04
BLAKE2b-256 c27e3ce4e55c7bbf88836dd243d3ce32d2b974a172abd8301b77e55e18605d45

See more details on using hashes here.

Supported by

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