# Telegram bot framework
This repository contains a Python framework to build bots against the [Telegram Bot API](https://core.telegram.org/bots).
The framework is event-based where you can configure what actions to perform when certain events occur (eg. someone enters a group, a command is sent to the bot, etc.).
You can find in [bot/manager.py](bot/manager.py) an already-configured bot using this framework.
The framework works only on a Python 3 interpreter.
There are no plans to support Python 2, which will be [retired soon](https://pythonclock.org/).
## Set-up your own bot using this framework
1. Install `telegram-bot-framework` with pip
pip install telegram-bot-framework
or add `telegram-bot-framework` to `install_requires` in your `setup.py`, or to your `requirements.txt` file.
2. Create a `config/` dir in the base directory of your bot and add the configuration options specified in the [configuration section](#configuration) to it.
3. Copy the [main.py](main.py) and [bot/manager.py](bot/manager.py) files to your bot directory. Update `main.py` to use your new `BotManager` class instead of the framework one. Launch `main.py`. You now have a working bot with many features out-of-the-box! Configure them (to remove the ones you do not want, and add yours) in the `manager.py` file.
- You can also copy [run.sh](run.sh) and use it as the launcher script for your bot. It performs some initialization tasks before running the bot, creates a virtual environment to install the dependencies and run the bot on it, re-executes the bot if it crashes, and updates your VCS before running.
4. *OPTIONAL* To enable i18n support, copy the [locales](locales) dir to your bot base directory, and run its `generate_mo.sh` script (the `run.sh` script will do it for you if you are using it). Use the `locales/` dir as the base dir for your translations. You can use and modify the helper script `update_po.sh` to extract `.po` files from your code.
You can use [XtremBot](https://github.com/alvarogzp/xtrem-bot) as an example of a simple bot using this framework.
Take a look at [World Clock](https://github.com/alvarogzp/clock-bot) for a more elaborated bot.
## Configuration
The configuration is read from a `config/` dir in the working directory of the bot.
It consists of key-value entries where the key is the name of the file, and the value is the file content.
The following keys must be present for the bot to work properly (it will refuse to start if they are not set):
- `auth_token`, with the auth token of the bot as provided by [@BotFather](https://t.me/BotFather).
- `admin_user_id`, that must have the `user_id` of the admin of the bot (you can use [@userinfobot](https://t.me/userinfobot) to get yours). The admin can perform some sensitive tasks (like shutting down the bot).
- `admin_chat_id`, with the `chat_id` of the chat you are going to use to manage the bot (you can set it to the same value as `admin_user_id` to use your private chat with the bot). This chat will be used to receive important messages from the bot. It is not recommended to disable notifications on this chat. If it is a group, the bot must be in it.
The following keys are also recognised by the framework, but they are *OPTIONAL*, and if not present, a default value is used:
- `log_chat_id`, can be set to a `chat_id` where you would like the bot to send log messages. If not set, log messages will be discarded. If set to a group, the bot must be in it.
- `traceback_chat_id`, can have the `chat_id` you would like to receive error tracebacks on. If not set, error tracebacks won't be sent anywhere (unless `send_error_tracebacks` is set, in that case they will be sent to `admin_chat_id`). If set to a group, the bot must be in it.
- `debug`, can have a value of `true` if you want requests and exception tracebacks to be printed on the standard output, and `false` if not. By default, they are enabled.
- `send_error_tracebacks` *(deprecated in favor of `traceback_chat_id`)*, can be `true` to send error tracebacks to `admin_chat_id` or `false` to not send them. By default they are not sent.
- `async`, set it to `true` to enable asynchronous support on the bot, and to `false` to disable it. By default, it is enabled.
- `reuse_connections`, can be `true` to enable reusing of network connections to reduce response times by avoiding connection creation overhead, or `false` to disable it. By default it is enabled.
- `scheduler_events_on_log_chat`, with a value of `true` to send scheduler event messages to log chat, and `false` to send them to admin chat. Note that initial scheduler events happening before logger is set-up are sent to admin chat regardless of this setting. By default, it is true.
- `sleep_seconds_on_get_updates_error`, which indicates the number of seconds the bot sleeps when there is an error while getting updates, to avoid hitting the server repeatedly when it has problems. By default, the bot sleeps `60` seconds.
- `max_error_seconds_allowed_in_normal_mode`, with the number of seconds the bot can be in normal mode while getting errors that avoid processing updates correctly. If this value is exceeded, the bot switches to process updates in pending mode, not answering to interactive actions (those under `NoPendingAction` in `BotManager`). The default is one hour.
- `max_network_workers`, with the maximum number of workers (ie. threads) that can be running for network operations at the same time. By default, a maximum of 4 network workers are allowed.
- `instance_name`, can be any string value to identify the bot instance at runtime.
## Some bots using this framework
- [World Clock](https://github.com/alvarogzp/clock-bot)
- [XtremBot](https://github.com/alvarogzp/xtrem-bot)
- Send a pull request adding yours!
# Authors
- Developed by
- Alvaro Gutierrez Perez
- alvarogzp@gmail.com
- https://linkedin.com/in/alvarogzp
- i18n support and visual improvements
- [@KouteiCheke](https://github.com/KouteiCheke)
## Donations
If you find this project useful and want to support its development economically, you can do so at any of the following addresses:
- PayPal: **[paypal.me/AlvaroGP](https://www.paypal.me/AlvaroGP)**
- Bitcoin: **[3CYLixYRc4anUweHy2u4gDa8F76MN5UQnC](bitcoin:3CYLixYRc4anUweHy2u4gDa8F76MN5UQnC)**
Please, contact the authors identifying yourself after donating, so that we can thank you.
没有合适的资源?快使用搜索试试~ 我知道了~
telegram-bot-framework:Python Telegram机器人API框架
共139个文件
py:127个
sh:4个
po:2个
需积分: 33 6 下载量 78 浏览量
2021-02-05
09:14:30
上传
评论
收藏 134KB ZIP 举报
温馨提示
电报bot框架 该存储库包含一个Python框架,用于根据构建机器人。 该框架基于事件,您可以在其中配置某些事件发生时要执行的操作(例如,某人进入组,向机器人发送命令等)。 您可以使用此框架在找到一个已配置的bot。 该框架仅适用于Python 3解释器。 目前尚无计划支持Python 2,它将。 使用此框架设置您自己的机器人 使用pip安装telegram-bot-framework pip install telegram-bot-framework 或将telegram-bot-framework添加到setup.py install_requires或您的requirement
资源详情
资源评论
资源推荐
收起资源包目录
telegram-bot-framework:Python Telegram机器人API框架 (139个子文件)
.gitignore 73B
.gitignore 8B
LICENSE 34KB
README.md 6KB
pole.po 4KB
pole.po 4KB
pole.pot 3KB
pole.py 23KB
analyzer.py 22KB
audios.py 17KB
manager.py 14KB
__init__.py 12KB
hashtags.py 12KB
bot.py 11KB
benchmark.py 9KB
scheduler.py 8KB
textformat.py 8KB
about.py 7KB
format.py 6KB
domain.py 6KB
spawner.py 6KB
user.py 4KB
__init__.py 4KB
action.py 4KB
telegram.py 4KB
throttler.py 4KB
__init__.py 4KB
logger.py 4KB
factory.py 4KB
admin_logger.py 4KB
operations.py 3KB
__init__.py 3KB
chat.py 3KB
action.py 3KB
api.py 3KB
random.py 3KB
state.py 3KB
toggle.py 3KB
config_status.py 3KB
legacypole.py 3KB
__init__.py 3KB
message.py 3KB
reusable.py 2KB
filter.py 2KB
operation.py 2KB
silence.py 2KB
logger.py 2KB
__init__.py 2KB
command_key.py 2KB
userinfo.py 2KB
mapper.py 2KB
main.py 2KB
action.py 2KB
internationalization.py 2KB
stored_message.py 1KB
button.py 1KB
parser.py 1KB
call.py 1KB
setup.py 1KB
params.py 1KB
exception.py 1KB
usagemessage.py 1KB
storage.py 1KB
limited_lifespan.py 1KB
same.py 1KB
enterexit.py 1KB
opt_out.py 1020B
group.py 1011B
synchronized.py 997B
gapdetector.py 915B
attributeobject.py 910B
asynchronous.py 858B
group_admin.py 837B
timed.py 823B
markup.py 813B
fail.py 812B
async.py 806B
abstract.py 790B
queue.py 781B
worker_logger.py 727B
scheduler.py 691B
api.py 670B
factory.py 656B
formatted.py 649B
counter.py 645B
project_info.py 597B
layout.py 587B
__init__.py 555B
no_command.py 547B
length.py 545B
name_generator.py 540B
sqlite.py 515B
number.py 503B
perchat.py 480B
plain.py 478B
asynchronous.py 478B
instance.py 408B
__init__.py 389B
immediate.py 375B
factory.py 361B
共 139 条
- 1
- 2
国服第一奶妈
- 粉丝: 27
- 资源: 4504
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0