davtelepot


Namedavtelepot JSON
Version 2.10.7 PyPI version JSON
download
home_pagehttps://gogs.davte.it/davte/davtelepot
SummaryTelegram bot API mirroring class, featuring dataset-powered SQLite databases.
upload_time2024-09-01 16:27:50
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/d7/b7/6dd8776fbe57196e6e6f88cf78a0ce20be64176fa86d8cf7a0800cf49440/davtelepot-2.10.7.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.7",
    "project_urls": {
        "Homepage": "https://gogs.davte.it/davte/davtelepot"
    },
    "split_keywords": [
        "telegram",
        "bot",
        "python",
        "asyncio",
        "async",
        "aiohttp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82098baab32e9bedf4c7c53a069a8a065302645a5b6479144a9b77244cb12891",
                "md5": "08771abf54c2eff09cba7aab85b64a57",
                "sha256": "16043537e4df3c849289ef02222bc2bd16cc2e088748bab346ae6d1956b47197"
            },
            "downloads": -1,
            "filename": "davtelepot-2.10.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "08771abf54c2eff09cba7aab85b64a57",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 122159,
            "upload_time": "2024-09-01T16:27:47",
            "upload_time_iso_8601": "2024-09-01T16:27:47.070806Z",
            "url": "https://files.pythonhosted.org/packages/82/09/8baab32e9bedf4c7c53a069a8a065302645a5b6479144a9b77244cb12891/davtelepot-2.10.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d7b76dd8776fbe57196e6e6f88cf78a0ce20be64176fa86d8cf7a0800cf49440",
                "md5": "975c8f5c229f8d4ab16b889978170357",
                "sha256": "037f622fce5d97dc572ac14ba022142c5b6e191896b702e55a05ccb37303b735"
            },
            "downloads": -1,
            "filename": "davtelepot-2.10.7.tar.gz",
            "has_sig": false,
            "md5_digest": "975c8f5c229f8d4ab16b889978170357",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 116344,
            "upload_time": "2024-09-01T16:27:50",
            "upload_time_iso_8601": "2024-09-01T16:27:50.180320Z",
            "url": "https://files.pythonhosted.org/packages/d7/b7/6dd8776fbe57196e6e6f88cf78a0ce20be64176fa86d8cf7a0800cf49440/davtelepot-2.10.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-01 16:27:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "davtelepot"
}
        
Elapsed time: 0.31083s