TelSDK


NameTelSDK JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/cirebon-dev/TelegramSDK
SummarySimple Telegram bot library
upload_time2024-09-15 12:28:23
maintainerNone
docs_urlNone
authorguangrei
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![status workflow test](https://github.com/cirebon-dev/TelegramSDK/actions/workflows/python-app.yml/badge.svg)](https://github.com/cirebon-dev/TelegramSDK/actions) 
[![status workflow build](https://github.com/cirebon-dev/TelegramSDK/actions/workflows/release_to_pypi.yml/badge.svg)](https://github.com/cirebon-dev/TelegramSDK/actions)
[![Downloads](https://static.pepy.tech/badge/TelSDK)](https://pepy.tech/project/TelSDK)

Simple Telegram BOT library.

## Example Usage

Example with poll method:

```python
# -*-coding:utf8;-*-
from TelegramSDK import telegram as bot


# telegram token is automatic loaded from environment variable TELEGRAM_BOT_TOKEN but you can also set it manually
bot.set_token("your token")

# call this function if you run on old device
# bot.disable_ssl()


def handler(data):
    bot.update(data)
    download_photo = bot.download_file("/tmp", filter=(".jpeg", ".jpg", ".png"))
    if len(download_photo):
        bot.reply_message("Photo downloaded: {}".format(download_photo))
    else:
        try:
            # user not send any file
            bot.reply_message("OK: " + bot.data.message.text)
            """
            or  reply with file bot.reply_file("path/to/file/example.pdf", caption="example file!")
            """
        except BaseException as e:
            # handle user send file but not photo
            bot.reply_message("file not supported!")


bot.poll(handler, worker=5, debug=True)
```

Example with webhook (flask, bottle etc)

```python
@post("/webhook")
def handler():
    bot.update(request.json)
    bot.reply_message("OK: " + bot.data.message.text)
```

TelegramSDK has built-in session function based [zcache](https://pypi.org/project/zcache), for example:

```python
if bot.get_session():
    count = bot.get_session() + 1
    bot.set_session(count, ttl=3600)
    bot.reply_message("count: %d" % count)
else:
    bot.set_session(1, ttl=3600)
    bot.reply_message("count: 1")
```

for more doc please read the source code.

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cirebon-dev/TelegramSDK",
    "name": "TelSDK",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "guangrei",
    "author_email": "myawn@pm.me",
    "download_url": "https://files.pythonhosted.org/packages/58/1d/5685bd659be2ad5441e5473f14a25e59906bd4d90b00cac77ca8c5f3b995/telsdk-0.1.2.tar.gz",
    "platform": "any",
    "description": "[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![status workflow test](https://github.com/cirebon-dev/TelegramSDK/actions/workflows/python-app.yml/badge.svg)](https://github.com/cirebon-dev/TelegramSDK/actions) \n[![status workflow build](https://github.com/cirebon-dev/TelegramSDK/actions/workflows/release_to_pypi.yml/badge.svg)](https://github.com/cirebon-dev/TelegramSDK/actions)\n[![Downloads](https://static.pepy.tech/badge/TelSDK)](https://pepy.tech/project/TelSDK)\n\nSimple Telegram BOT library.\n\n## Example Usage\n\nExample with poll method:\n\n```python\n# -*-coding:utf8;-*-\nfrom TelegramSDK import telegram as bot\n\n\n# telegram token is automatic loaded from environment variable TELEGRAM_BOT_TOKEN but you can also set it manually\nbot.set_token(\"your token\")\n\n# call this function if you run on old device\n# bot.disable_ssl()\n\n\ndef handler(data):\n    bot.update(data)\n    download_photo = bot.download_file(\"/tmp\", filter=(\".jpeg\", \".jpg\", \".png\"))\n    if len(download_photo):\n        bot.reply_message(\"Photo downloaded: {}\".format(download_photo))\n    else:\n        try:\n            # user not send any file\n            bot.reply_message(\"OK: \" + bot.data.message.text)\n            \"\"\"\n            or  reply with file bot.reply_file(\"path/to/file/example.pdf\", caption=\"example file!\")\n            \"\"\"\n        except BaseException as e:\n            # handle user send file but not photo\n            bot.reply_message(\"file not supported!\")\n\n\nbot.poll(handler, worker=5, debug=True)\n```\n\nExample with webhook (flask, bottle etc)\n\n```python\n@post(\"/webhook\")\ndef handler():\n    bot.update(request.json)\n    bot.reply_message(\"OK: \" + bot.data.message.text)\n```\n\nTelegramSDK has built-in session function based [zcache](https://pypi.org/project/zcache), for example:\n\n```python\nif bot.get_session():\n    count = bot.get_session() + 1\n    bot.set_session(count, ttl=3600)\n    bot.reply_message(\"count: %d\" % count)\nelse:\n    bot.set_session(1, ttl=3600)\n    bot.reply_message(\"count: 1\")\n```\n\nfor more doc please read the source code.\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple Telegram bot library",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/cirebon-dev/TelegramSDK"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1b2790f999a6d2a005635bd7fcd3b37a657a1c4703f818195f2eaebcf31ff3d8",
                "md5": "8b5f740b66798ed06bed160e8d7820ba",
                "sha256": "5205e117c7f1e8d0bd0d4a6ae6b519d110a30c2322477a20e974e4450003f05f"
            },
            "downloads": -1,
            "filename": "TelSDK-0.1.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b5f740b66798ed06bed160e8d7820ba",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8426,
            "upload_time": "2024-09-15T12:28:22",
            "upload_time_iso_8601": "2024-09-15T12:28:22.254157Z",
            "url": "https://files.pythonhosted.org/packages/1b/27/90f999a6d2a005635bd7fcd3b37a657a1c4703f818195f2eaebcf31ff3d8/TelSDK-0.1.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "581d5685bd659be2ad5441e5473f14a25e59906bd4d90b00cac77ca8c5f3b995",
                "md5": "e01aba4539c06b3abb2f9ecb7379ebd4",
                "sha256": "e94ea04923fab36025f16ff74bcb7dd04a8ca78ed81056914b3a33b88207b9cc"
            },
            "downloads": -1,
            "filename": "telsdk-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e01aba4539c06b3abb2f9ecb7379ebd4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7363,
            "upload_time": "2024-09-15T12:28:23",
            "upload_time_iso_8601": "2024-09-15T12:28:23.802964Z",
            "url": "https://files.pythonhosted.org/packages/58/1d/5685bd659be2ad5441e5473f14a25e59906bd4d90b00cac77ca8c5f3b995/telsdk-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-15 12:28:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cirebon-dev",
    "github_project": "TelegramSDK",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "telsdk"
}
        
Elapsed time: 1.12756s