autogram


Nameautogram JSON
Version 3.6.1 PyPI version JSON
download
home_pageNone
SummaryAn easily extensible telegram API wrapper
upload_time2024-07-08 07:04:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseMIT License Copyright (c) 2022-2024 drui9 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords autogram telegram api wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p style="text-align: center;">
    <img src="https://raw.githubusercontent.com/drui9/autogram/main/autogram.png" align="middle" alt="Autogram">
<p>

Autogram is a telegram bot-API wrapper written in python3, with a keen focus on remaining stupidly simple.

## QuickStart
`pip install autogram`
- Copy either the Functional or OOP example below.
- Run the bot the first time to generate `project-name.json` config template
- Add your telegram bot token in the config, (from telegram:BotFather chat)
- Ready to run.
- Add your own logic and handler methods. `core.telegram.org` manual is your friend.

## `Why AutoGram?`
The name implies automated-telegram. I needed a framework that is easy and intuitive to work with.

## Usage1: Functional
```python
from autogram import Autogram
from autogram.config import Start

#-- handle private dm
@Autogram.add('message')
def message(bot, update):
    print('message:', update)

#-- handle callback queries
@Autogram.add('callback_query')
def callback_query(bot, update):
    print('callback_query:', update)

#***************************** <start>
@Start(config_file='web-auto.json')
def main(config):
    bot = Autogram(config)
    bot.run() # every call fetches updates, and updates internal offset
#-- </start>
```
## Usage2: OOP
```python
import time
from loguru import logger
from autogram import Autogram, Start

# --
class ExampleBot(Autogram):
    def __init__(self, config):
        super().__init__(config)

    def run(self):
        """Custom implementation of bot.poll()"""
        super().run() # initializes bot info, abstractmethod
        for _ in range(10): # should be endless loop
            offset = self.data('offset')
            for rep in self.poll(offset=offset).json()['result']:
              self.data('offset', rep.pop('update_id') + 1)
              with self.register['lock']:
                if handler := self.register['handlers'].get(list(rep.keys())[-1]):
                  handler(self, self, rep)
            time.sleep(5)

    @Autogram.add('message')
    def message(self, bot: Autogram, update):
        logger.debug(update['message']['text'])
        chat_id = update['message']['chat']['id']
        keyb = [[{'text': 'The armpit', 'callback_data': 'tickled'}]]
        data = {
            'reply_markup': bot.getInlineKeyboardMarkup(keyb)
        }
        bot.sendMessage(chat_id, 'Tickle me!', **data)

    # --
    @Autogram.add('callback_query')
    def callback_query(self, bot: Autogram, update):
        callback_id = update['callback_query']['id']
        bot.answerCallbackQuery(callback_id, 'Ha-ha-ha')

#***************************** <start>
@Start()
def main(config):
    bot = ExampleBot(config)
    bot.run()
# ************ </start>
```
If you have a url-endpoint, call bot.setWebhook(url), then run some sort of webserver in bot.run.

## `Project TODOs`
- Add webhook example.
- Extend coverage of the API.

### `footnotes`
- Invalid `TELEGRAM_TOKEN` return 404 through `bot.getMe()`
- Thread safety is not guaranteed for calls from multiple threads to: `bot.data, bot.settings`. Prefferably, handle the bot in a single thread, as handlers use these methods to persist data.
- Don't run multiple bots with the same `TOKEN` as this will cause update problems
- Sending unescaped special characters when using MarkdownV2 will return HTTP400
- Have `fun` with whatever you're building `;)`


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "autogram",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "autogram, telegram, API, wrapper",
    "author": null,
    "author_email": "drui9 <drui9@duck.com>",
    "download_url": "https://files.pythonhosted.org/packages/69/f4/aab562c35d7d3c7d028746ee4c852cf5bed691bf9d1adfa1f8a96bd2e792/autogram-3.6.1.tar.gz",
    "platform": null,
    "description": "<p style=\"text-align: center;\">\n    <img src=\"https://raw.githubusercontent.com/drui9/autogram/main/autogram.png\" align=\"middle\" alt=\"Autogram\">\n<p>\n\nAutogram is a telegram bot-API wrapper written in python3, with a keen focus on remaining stupidly simple.\n\n## QuickStart\n`pip install autogram`\n- Copy either the Functional or OOP example below.\n- Run the bot the first time to generate `project-name.json` config template\n- Add your telegram bot token in the config, (from telegram:BotFather chat)\n- Ready to run.\n- Add your own logic and handler methods. `core.telegram.org` manual is your friend.\n\n## `Why AutoGram?`\nThe name implies automated-telegram. I needed a framework that is easy and intuitive to work with.\n\n## Usage1: Functional\n```python\nfrom autogram import Autogram\nfrom autogram.config import Start\n\n#-- handle private dm\n@Autogram.add('message')\ndef message(bot, update):\n    print('message:', update)\n\n#-- handle callback queries\n@Autogram.add('callback_query')\ndef callback_query(bot, update):\n    print('callback_query:', update)\n\n#***************************** <start>\n@Start(config_file='web-auto.json')\ndef main(config):\n    bot = Autogram(config)\n    bot.run() # every call fetches updates, and updates internal offset\n#-- </start>\n```\n## Usage2: OOP\n```python\nimport time\nfrom loguru import logger\nfrom autogram import Autogram, Start\n\n# --\nclass ExampleBot(Autogram):\n    def __init__(self, config):\n        super().__init__(config)\n\n    def run(self):\n        \"\"\"Custom implementation of bot.poll()\"\"\"\n        super().run() # initializes bot info, abstractmethod\n        for _ in range(10): # should be endless loop\n            offset = self.data('offset')\n            for rep in self.poll(offset=offset).json()['result']:\n              self.data('offset', rep.pop('update_id') + 1)\n              with self.register['lock']:\n                if handler := self.register['handlers'].get(list(rep.keys())[-1]):\n                  handler(self, self, rep)\n            time.sleep(5)\n\n    @Autogram.add('message')\n    def message(self, bot: Autogram, update):\n        logger.debug(update['message']['text'])\n        chat_id = update['message']['chat']['id']\n        keyb = [[{'text': 'The armpit', 'callback_data': 'tickled'}]]\n        data = {\n            'reply_markup': bot.getInlineKeyboardMarkup(keyb)\n        }\n        bot.sendMessage(chat_id, 'Tickle me!', **data)\n\n    # --\n    @Autogram.add('callback_query')\n    def callback_query(self, bot: Autogram, update):\n        callback_id = update['callback_query']['id']\n        bot.answerCallbackQuery(callback_id, 'Ha-ha-ha')\n\n#***************************** <start>\n@Start()\ndef main(config):\n    bot = ExampleBot(config)\n    bot.run()\n# ************ </start>\n```\nIf you have a url-endpoint, call bot.setWebhook(url), then run some sort of webserver in bot.run.\n\n## `Project TODOs`\n- Add webhook example.\n- Extend coverage of the API.\n\n### `footnotes`\n- Invalid `TELEGRAM_TOKEN` return 404 through `bot.getMe()`\n- Thread safety is not guaranteed for calls from multiple threads to: `bot.data, bot.settings`. Prefferably, handle the bot in a single thread, as handlers use these methods to persist data.\n- Don't run multiple bots with the same `TOKEN` as this will cause update problems\n- Sending unescaped special characters when using MarkdownV2 will return HTTP400\n- Have `fun` with whatever you're building `;)`\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022-2024 drui9  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "An easily extensible telegram API wrapper",
    "version": "3.6.1",
    "project_urls": {
        "Homepage": "https://github.com/drui9/autogram"
    },
    "split_keywords": [
        "autogram",
        " telegram",
        " api",
        " wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6ad62f5258d1e5f4d88fd0f544e1f1e3de22a83a786a0494f877b4e5b0aef0a",
                "md5": "573ebabf07c90f52438080761c08a8d0",
                "sha256": "a3c8a6a18af25e5c47570af1b9f6e67e29e968b72e6895a086f3eb5ecd661c23"
            },
            "downloads": -1,
            "filename": "autogram-3.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "573ebabf07c90f52438080761c08a8d0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8066,
            "upload_time": "2024-07-08T07:04:40",
            "upload_time_iso_8601": "2024-07-08T07:04:40.242405Z",
            "url": "https://files.pythonhosted.org/packages/a6/ad/62f5258d1e5f4d88fd0f544e1f1e3de22a83a786a0494f877b4e5b0aef0a/autogram-3.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "69f4aab562c35d7d3c7d028746ee4c852cf5bed691bf9d1adfa1f8a96bd2e792",
                "md5": "80a8bb77a0555fe87d8b21304522487f",
                "sha256": "414eb3298d0379979bc7920b5fddb49761591babb51bf88465cba015557ab7ff"
            },
            "downloads": -1,
            "filename": "autogram-3.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "80a8bb77a0555fe87d8b21304522487f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7636,
            "upload_time": "2024-07-08T07:04:41",
            "upload_time_iso_8601": "2024-07-08T07:04:41.868656Z",
            "url": "https://files.pythonhosted.org/packages/69/f4/aab562c35d7d3c7d028746ee4c852cf5bed691bf9d1adfa1f8a96bd2e792/autogram-3.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-08 07:04:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "drui9",
    "github_project": "autogram",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "autogram"
}
        
Elapsed time: 0.29278s