{ "info": { "author": "Anton Bulakh", "author_email": "necauqua@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Topic :: Communications :: Chat", "Topic :: Utilities" ], "description": "# tinybot\nThis is a small and simple library for quickly building Telegram Bots with Python.\n\nIt is made to be dynamic and independent of the Telegram Bot API.\nIt means that whenever a new Telegram API method or callback is added,\nthere is no need to update this library, all calls are dynamic and you can send whatever you like to Telegram.\n\n## Installation\nIt is published on PyPI so to use it simply install it with pip.\n```\n$ pip install tinybot\n```\n\n## Example\nActually working little bot (from which this library was originated) can be found [here](https://github.com/necauqua/county-bot).\n\nHere is a simple example:\n```python\n\nimport tinybot\n\n\nclass Assistant(tinybot.Bot):\n version = '0.0.1-SNAPSHOT'\n token = '123456789:token-for-debugging' # token is not required when using tinybot.run\n\n def handle_message(self, data, api):\n if '@all' in data.text:\n api.sendMessage(chat_id=data.chat.id, text='@necauqua @other_people..')\n api.sendMessage(chat_id=data.chat.id, text='[debug] update id ' + str(self.update_id))\n\n\nif __name__ == '__main__':\n # just start longpoll loop for debugging\n Assistant.launch_longpoll(30)\n\n # tinybot.run is a ready-to-use CLI for launching longpoll or webhook and providing the token\n # tinybot.run(Assistant, 'necauqua assistant bot')\n\n```\n\n## Usage\nYour bot is a class which derives from `tinybot.Bot` class.\nYou can start it with a ready-to-use CLI using this standard construct\n```python\nif __name__ == '__main__':\n tinybot.run(bot_cls, bot_description)\n```\nAll of the bot's logic is defined inside the class deriven from `tinybot.Bot`.\n\nIt have static fields `name`, `version`,`full_name` and `token`.\n* `name` defaults to the class name and is the name of your bot. Used in `full_name`\n* `version` is a version of your bot, it defaults to `0.1.0`. Used in `full_name`.\n* `full_name` defaults to `name/version`.\nIt is used as a `User-Session` header when making requests, and as `Server` header when\nresponding to Telegram from a webhook server.\n* `token` is an optional field, because usually it is set from command line when running `tinybot.run`.\nHowever, it might be useful for debugging.\nIt is obviously the token which is used for all requests.\n\nYour class should define methods with signarure `handle_xxx(self, data, api)` where `xxx` is one of the update types found [here](https://core.telegram.org/bots/api#getting-updates).\n\nFor example:\n```python\ndef handle_message(self, message, api): pass\n# or\ndef handle_channel_post(self, post, api): pass\n```\n* `self` parameter can contain some additional data, for now it only contains the `update_id` field.\n* `data` parameter is a dict/list-like recursive structure made with `__getattr__`'s\nand `__getitems__`'s in which the received Update JSON object is given.\nWhen you try to get a nonexistent field, `NoSuchElementException` is raised and\nthen handled properly by the `launch_xxx` methods caller.\n* `api` parameter worls similarly, any method call which looks like\n`api.anyMethodCall(**kwargs)` would send appropriate request to the Telegram Bot API.
\nWhen you do such a request, Telegram returns JSON in format
\n`{\"ok\": true, \"update\": ..data..}`
or
\n`{\"ok\": false, \"description\": \"..error message..\"}`.
\nThis JSON is unwrapped and if ok is false or non-existent, `RequestException` is raised\nwith the description and similarly handled by the `launch_xxx` methods caller.\nElse, the `\"update\"` object is wrapped in the same structure as the `data` parameter and\nis returned from the `api` method call.\n\nAll of the above means that if you want your bot to do multiple get-and-then-send requests,\nyou'll want to arrange your code to first get all the data and only after that send your requests.\nThat way, if any of the data weren't available, any of your mutating requests would not be sent.\n\n## License\nIt is licensed under permissive MIT license which means you can use this code in\nwhatever way possible, as long as you include the LICENSE file (by which you mention my authorship).\nIt is included in the package so you have to do nothing yourself when simply using this library.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/necauqua/tinybot/archive/v1.0.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/necauqua/tinybot", "keywords": "telegram,bot,api", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "tinybot", "package_url": "https://pypi.org/project/tinybot/", "platform": "", "project_url": "https://pypi.org/project/tinybot/", "project_urls": { "Download": "https://github.com/necauqua/tinybot/archive/v1.0.0.tar.gz", "Homepage": "http://github.com/necauqua/tinybot" }, "release_url": "https://pypi.org/project/tinybot/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Very simple yet flexible Telegram Bot API", "version": "1.0.0" }, "last_serial": 3947883, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "4d5f6c0fd88e7c7207b8a221b43f9638", "sha256": "2226e6be78845ee5ee4c58a8b8c08eefbff6636eee5d1e07d97b2db760df82b7" }, "downloads": -1, "filename": "tinybot-0.1.5.tar.gz", "has_sig": true, "md5_digest": "4d5f6c0fd88e7c7207b8a221b43f9638", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7659, "upload_time": "2018-06-10T18:06:18", "url": "https://files.pythonhosted.org/packages/5e/cf/9e8c5bfeb76a22cb9e23f087faa4b0cd47535010436ecde4d9a7b8cd13cd/tinybot-0.1.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4d5f6c0fd88e7c7207b8a221b43f9638", "sha256": "2226e6be78845ee5ee4c58a8b8c08eefbff6636eee5d1e07d97b2db760df82b7" }, "downloads": -1, "filename": "tinybot-0.1.5.tar.gz", "has_sig": true, "md5_digest": "4d5f6c0fd88e7c7207b8a221b43f9638", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7659, "upload_time": "2018-06-10T18:06:18", "url": "https://files.pythonhosted.org/packages/5e/cf/9e8c5bfeb76a22cb9e23f087faa4b0cd47535010436ecde4d9a7b8cd13cd/tinybot-0.1.5.tar.gz" } ] }