davtelepot


Namedavtelepot JSON
Version 2.10.2 PyPI version JSON
download
home_pagehttps://gogs.davte.it/davte/davtelepot
SummaryTelegram bot API mirroring class, featuring dataset-powered SQLite databases.
upload_time2024-04-13 09:16:05
maintainerNone
docs_urlNone
authorDavide Testa
requires_python>=3.5
licenseGNU General Public License v3.0
keywords telegram bot python asyncio async aiohttp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # davtelepot
This project conveniently mirrors the Telegram bot API with the class `Bot`.

Please note that Python3.5+ is needed to run async code.

Check requirements.txt for third party dependencies.

Check out `help(Bot)` for detailed information.

## Project folders

### `davtelepot/data` folder
* `config.py` contains configuration settings (e.g. certificate path, local_host, port etc.)
* `passwords.py` contains secret information to be git-ignored (e.g. bot tokens)
* `*.db` files are SQLite databases used by bots
* `*.log`: log files (store log_file_name and errors_file_name in `data/config.py` module)

### `examples` folder
This folder contains full-commented and ready-to-run examples for simple davtelepot.bot Telegram bots.

## Usage
```
import sys

from davtelepot.bot import Bot

from data.passwords import my_token, my_other_token

long_polling_bot = Bot(token=my_token, database_url='my_db')
webhook_bot = Bot(token=my_other_token, hostname='example.com',
                  certificate='path/to/certificate.pem',
                  database_url='my_other_db')

@long_polling_bot.command('/foo')
async def foo_command(bot, update, user_record):
    return "Bar!"

@webhook_bot.command('/bar')
async def bar_command(bot, update, user_record):
    return "Foo!"

exit_state = Bot.run(
    local_host='127.0.0.5',
    port=8552
)
sys.exit(exit_state)
```
Check out `help(Bot)` for detailed information.

## Webhook additional information
To run a bot in webhook modality, you have to provide a `hostname` and `certificate` at bot instantiation and a `local_host` and `port` when calling `Bot.run` method.
* Telegram will send POST requests at `https://{hostname}/webhook/{tokens}/` using `certificate` for encryption
* `aiohttp.web.Application` server will listen on `http://{local_host}:{port}` for updates

It is therefore required a reverse proxy passing incoming requests to local_host.

**Example of nginx reverse proxy serving this purpose**
```nginx
server {
  listen 8553 ssl;
  listen [::]:8553 ssl;

  server_name example.com www.example.com;

  location /telegram/ {
     proxy_pass http://127.0.0.5:8552/;
  }

  ssl_certificate /path/to/fullchain.pem;
  ssl_certificate_key /path/to/privkey.pem;
}

```

**Example of python configuration file in this situation**
```python
# File data/config.py, gitignored and imported in main script
hostname = "https://www.example.com:8553/telegram"
certificate = "/path/to/fullchain.pem"
local_host = "127.0.0.5"
port = 8552

# Main script
from data.config import hostname, certificate, local_host, port
from data.passwords import bot_token
from davtelepot.bot import Bot

my_bot = Bot(
  token=bot_token,
  hostname=hostname,
  certificate=certificate
)

# ...

Bot.run(
  local_host=local_host,
  port=port
)
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://gogs.davte.it/davte/davtelepot",
    "name": "davtelepot",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": null,
    "keywords": "telegram bot python asyncio async aiohttp",
    "author": "Davide Testa",
    "author_email": "davide@davte.it",
    "download_url": "https://files.pythonhosted.org/packages/a1/5c/d3121c4d0b08f6c384deb0d35bdafff9fb52dc5193575bfbee6e8d63e838/davtelepot-2.10.2.tar.gz",
    "platform": "any",
    "description": "# davtelepot\nThis project conveniently mirrors the Telegram bot API with the class `Bot`.\n\nPlease note that Python3.5+ is needed to run async code.\n\nCheck requirements.txt for third party dependencies.\n\nCheck out `help(Bot)` for detailed information.\n\n## Project folders\n\n### `davtelepot/data` folder\n* `config.py` contains configuration settings (e.g. certificate path, local_host, port etc.)\n* `passwords.py` contains secret information to be git-ignored (e.g. bot tokens)\n* `*.db` files are SQLite databases used by bots\n* `*.log`: log files (store log_file_name and errors_file_name in `data/config.py` module)\n\n### `examples` folder\nThis folder contains full-commented and ready-to-run examples for simple davtelepot.bot Telegram bots.\n\n## Usage\n```\nimport sys\n\nfrom davtelepot.bot import Bot\n\nfrom data.passwords import my_token, my_other_token\n\nlong_polling_bot = Bot(token=my_token, database_url='my_db')\nwebhook_bot = Bot(token=my_other_token, hostname='example.com',\n                  certificate='path/to/certificate.pem',\n                  database_url='my_other_db')\n\n@long_polling_bot.command('/foo')\nasync def foo_command(bot, update, user_record):\n    return \"Bar!\"\n\n@webhook_bot.command('/bar')\nasync def bar_command(bot, update, user_record):\n    return \"Foo!\"\n\nexit_state = Bot.run(\n    local_host='127.0.0.5',\n    port=8552\n)\nsys.exit(exit_state)\n```\nCheck out `help(Bot)` for detailed information.\n\n## Webhook additional information\nTo run a bot in webhook modality, you have to provide a `hostname` and `certificate` at bot instantiation and a `local_host` and `port` when calling `Bot.run` method.\n* Telegram will send POST requests at `https://{hostname}/webhook/{tokens}/` using `certificate` for encryption\n* `aiohttp.web.Application` server will listen on `http://{local_host}:{port}` for updates\n\nIt is therefore required a reverse proxy passing incoming requests to local_host.\n\n**Example of nginx reverse proxy serving this purpose**\n```nginx\nserver {\n  listen 8553 ssl;\n  listen [::]:8553 ssl;\n\n  server_name example.com www.example.com;\n\n  location /telegram/ {\n     proxy_pass http://127.0.0.5:8552/;\n  }\n\n  ssl_certificate /path/to/fullchain.pem;\n  ssl_certificate_key /path/to/privkey.pem;\n}\n\n```\n\n**Example of python configuration file in this situation**\n```python\n# File data/config.py, gitignored and imported in main script\nhostname = \"https://www.example.com:8553/telegram\"\ncertificate = \"/path/to/fullchain.pem\"\nlocal_host = \"127.0.0.5\"\nport = 8552\n\n# Main script\nfrom data.config import hostname, certificate, local_host, port\nfrom data.passwords import bot_token\nfrom davtelepot.bot import Bot\n\nmy_bot = Bot(\n  token=bot_token,\n  hostname=hostname,\n  certificate=certificate\n)\n\n# ...\n\nBot.run(\n  local_host=local_host,\n  port=port\n)\n```\n\n\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3.0",
    "summary": "Telegram bot API mirroring class, featuring dataset-powered SQLite databases.",
    "version": "2.10.2",
    "project_urls": {
        "Homepage": "https://gogs.davte.it/davte/davtelepot"
    },
    "split_keywords": [
        "telegram",
        "bot",
        "python",
        "asyncio",
        "async",
        "aiohttp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e7200d696b1ff95891b27ee98e768b8b2336e957bb2f4ff59ebb44933943ad7",
                "md5": "7316a2e2e89cdc3a201dd6a2fc1d2cce",
                "sha256": "e1488d23d14e23bd9580b3ca3e6b654c4753e7668fd5341df672e6c7c43ef7e0"
            },
            "downloads": -1,
            "filename": "davtelepot-2.10.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7316a2e2e89cdc3a201dd6a2fc1d2cce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 120428,
            "upload_time": "2024-04-13T09:16:01",
            "upload_time_iso_8601": "2024-04-13T09:16:01.546813Z",
            "url": "https://files.pythonhosted.org/packages/8e/72/00d696b1ff95891b27ee98e768b8b2336e957bb2f4ff59ebb44933943ad7/davtelepot-2.10.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a15cd3121c4d0b08f6c384deb0d35bdafff9fb52dc5193575bfbee6e8d63e838",
                "md5": "7bb73f91ae987f9187bb937632f36c95",
                "sha256": "c014591e9ea013cecd0c38418cbe939bc2b27d9226cc351034f0424bd235d5fe"
            },
            "downloads": -1,
            "filename": "davtelepot-2.10.2.tar.gz",
            "has_sig": false,
            "md5_digest": "7bb73f91ae987f9187bb937632f36c95",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 114634,
            "upload_time": "2024-04-13T09:16:05",
            "upload_time_iso_8601": "2024-04-13T09:16:05.594439Z",
            "url": "https://files.pythonhosted.org/packages/a1/5c/d3121c4d0b08f6c384deb0d35bdafff9fb52dc5193575bfbee6e8d63e838/davtelepot-2.10.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-13 09:16:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "davtelepot"
}
        
Elapsed time: 0.38718s