|
1 | 1 | # telegram-task-bot |
2 | | -Telegrambot to ease the setup of recurring tasks. |
| 2 | +Library to setup telegram bots with recurring tasks. |
3 | 3 |
|
4 | | -## Usage |
| 4 | +# Usage |
5 | 5 | `pip install telegram-task-bot` |
6 | 6 |
|
7 | | -### `.env` Variables |
| 7 | +## `.env` Variables |
8 | 8 | 1) `ALLOWED_USERS` specifies the users which are allowed, if `any`, every one is allowed to use the bot. |
9 | 9 | 1) `BOT_TOKEN` the token of the bot. |
| 10 | +1) `START_MESSAGE` the message to be send as response to the start command. |
10 | 11 |
|
11 | | -## Example |
12 | | -https://github.com/bb4L/digitec_daily_bot |
| 12 | + |
| 13 | +## Classes |
| 14 | +There are several classes included in this Package. |
| 15 | + |
| 16 | +### Task |
| 17 | +Base class for recurring tasks. |
| 18 | + |
| 19 | +#### Configuration |
| 20 | +* `job_name: str` Name of the job defined in this task |
| 21 | +* `disable_notifications: bool` Disable notifications, flag send to the telegram server |
| 22 | +* `generic: bool` Defines if the task looks the same for each user |
| 23 | +* `first_time:time` First time to run the task, 0 is now takes a `datetime.time` |
| 24 | +* `repeat_time: timedelta` Defines the time between two executions of the job, takes `datetime.timedelta` |
| 25 | +* `filename: str` Filename under which data specific to this job should be saved |
| 26 | + |
| 27 | +### GenericTask |
| 28 | +More specific class which adds the possiblity to get the actual value and implements user handling. |
| 29 | +The data is saved to a `JSON` file. |
| 30 | +The callback method ( `callback(self, context: telegram.ext.CallbackContext)`) must be implemented. |
| 31 | + |
| 32 | +### UrlTask |
| 33 | +Extension of the `GenericTask` to simplify the usage for jobs calling a URL and returning the link/ response to the subscribers. |
| 34 | +It tries until it gets a response every 2 seconds. |
| 35 | + |
| 36 | +This class adds a `url` field where the information lies. |
| 37 | + |
| 38 | +The `handle_response(self, response: Response)` must be implemented to extract the data from the request and return the message string. |
| 39 | + |
| 40 | +# Example Project |
| 41 | +https://github.com/bb4L/digitec_daily_bot |
| 42 | + |
| 43 | +# License |
| 44 | +[LGPLv3](LICENSE) |
0 commit comments