zdgram


Namezdgram JSON
Version 0.1.dev7 PyPI version JSON
download
home_page
SummaryPython module based on https://core.telegram.org/bots/api
upload_time2024-01-25 16:35:51
maintainer
docs_urlNone
authorZAID
requires_python~=3.8
license
keywords bots bot-api telegram
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Install :
```commandline
pip install -U zdgram
```

# How to use?
- Config your bot :
---
```python
from zdgram import Bot, types

API_TOKEN = "API_TOKEN_HERE"

bot = Bot(API_TOKEN, allowed_updates=["message"])
```

- Add handlers to recive updates from telegram:
---
- Any update from telegram:
```python
@bot.onUpdate
async def on_updates(bot: Bot, update: types.Update):
    print(update)
```

- message and edited_message:
```python
@bot.onMessage()
async def on_message(bot: Bot, message: types.Message):
    print(message)

@bot.onEditedMessage()
async def on_edited_message(bot: Bot, message: types.Message):
    print(message)

# Custom filter
def filter_admin(message: types.Message):
    admins = [123456789, 987654321]
    return bool(message.from_user.id in admins)

@bot.onMessage(func=filter_admin)
@bot.onEditedMessage(func=filter_admin)
async def on_custom_filter(bot: Bot, message: types.Message):
    print(message)

# Echo Bot
@bot.onMessage(func=lambda m: m.text)
async def echo(bot: Bot, message: types.Message):
    return await bot.sendMessage(
        message.chat.id,
        message.text,
        entities=message.entities
    )
```

- Callback Queries .
```python
@bot.onCallbackQuery()
async def on_callback_query(bot: Bot, callback_query: types.CallbackQuery):
    return await bot.sendMessage(
        callback_query.message.chat.id,
        callback_query.data
    )
```

- Inline Queries .
```python
@bot.onInlineQuery()
async def on_inline_query(bot: Bot, inline_query: types.InlineQuery):
    print(inline_query)
```

- Start the bot:
---
```python
import logging

logging.basicConfig(level=logging.INFO)

bot.run()
```

- Start multiple bots:
---
```python
import logging

from zdgram import run_multiple_bots, Bot, types, enums

logging.basicConfig(level=logging.INFO)

bot_1 = Bot("API_TOKEN_1")
bot_2 = Bot("API_TOKEN_2")

@bot_1.onMessage()
@bot_2.onMessage()
async  def on_message(bot: Bot, message: types.Message):
    return await bot.sendMessage(
        message.chat.id,
        (await bot.getMe()).mention.markdown,
        parse_mode=enums.ParseMode.MARKDOWN
    )

bot_1.run(run_multiple_bots([bot_1, bot_2]))
```

- Create Listener ( Conversation ):
---
```python
from zdgram import types, enums, Bot

bot = Bot(bot_token="")

def filter_text_and_private(m: types.Message):
    return bool(m.text and m.chat.type == enums.ChatType.PRIVATE)

@bot.onMessage(func=filter_text_and_private)
async def on_message(bot: Bot, message: types.Message):
    await bot.sendMessage(
        message.chat.id,
        "Send your name",
        reply_to_message_id=message.id
    )
    msg = await bot.listen(filter_text_and_private)
    return await bot.sendMessage(
        message.chat.id,
        "Your name is : " + msg.text
    )
```

# LICENSE :
- [MIT](https://github.com/x72x/zdgram/blob/master/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "zdgram",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "~=3.8",
    "maintainer_email": "",
    "keywords": "bots,bot-api,telegram",
    "author": "ZAID",
    "author_email": "y8838@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/89/84/2e2bd66827fe736dffdd1b1d1d2c986763f6fe036c316f89f40f9bc50eb6/zdgram-0.1.dev7.tar.gz",
    "platform": null,
    "description": "\r\n# Install :\r\n```commandline\r\npip install -U zdgram\r\n```\r\n\r\n# How to use?\r\n- Config your bot :\r\n---\r\n```python\r\nfrom zdgram import Bot, types\r\n\r\nAPI_TOKEN = \"API_TOKEN_HERE\"\r\n\r\nbot = Bot(API_TOKEN, allowed_updates=[\"message\"])\r\n```\r\n\r\n- Add handlers to recive updates from telegram:\r\n---\r\n- Any update from telegram:\r\n```python\r\n@bot.onUpdate\r\nasync def on_updates(bot: Bot, update: types.Update):\r\n    print(update)\r\n```\r\n\r\n- message and edited_message:\r\n```python\r\n@bot.onMessage()\r\nasync def on_message(bot: Bot, message: types.Message):\r\n    print(message)\r\n\r\n@bot.onEditedMessage()\r\nasync def on_edited_message(bot: Bot, message: types.Message):\r\n    print(message)\r\n\r\n# Custom filter\r\ndef filter_admin(message: types.Message):\r\n    admins = [123456789, 987654321]\r\n    return bool(message.from_user.id in admins)\r\n\r\n@bot.onMessage(func=filter_admin)\r\n@bot.onEditedMessage(func=filter_admin)\r\nasync def on_custom_filter(bot: Bot, message: types.Message):\r\n    print(message)\r\n\r\n# Echo Bot\r\n@bot.onMessage(func=lambda m: m.text)\r\nasync def echo(bot: Bot, message: types.Message):\r\n    return await bot.sendMessage(\r\n        message.chat.id,\r\n        message.text,\r\n        entities=message.entities\r\n    )\r\n```\r\n\r\n- Callback Queries .\r\n```python\r\n@bot.onCallbackQuery()\r\nasync def on_callback_query(bot: Bot, callback_query: types.CallbackQuery):\r\n    return await bot.sendMessage(\r\n        callback_query.message.chat.id,\r\n        callback_query.data\r\n    )\r\n```\r\n\r\n- Inline Queries .\r\n```python\r\n@bot.onInlineQuery()\r\nasync def on_inline_query(bot: Bot, inline_query: types.InlineQuery):\r\n    print(inline_query)\r\n```\r\n\r\n- Start the bot:\r\n---\r\n```python\r\nimport logging\r\n\r\nlogging.basicConfig(level=logging.INFO)\r\n\r\nbot.run()\r\n```\r\n\r\n- Start multiple bots:\r\n---\r\n```python\r\nimport logging\r\n\r\nfrom zdgram import run_multiple_bots, Bot, types, enums\r\n\r\nlogging.basicConfig(level=logging.INFO)\r\n\r\nbot_1 = Bot(\"API_TOKEN_1\")\r\nbot_2 = Bot(\"API_TOKEN_2\")\r\n\r\n@bot_1.onMessage()\r\n@bot_2.onMessage()\r\nasync  def on_message(bot: Bot, message: types.Message):\r\n    return await bot.sendMessage(\r\n        message.chat.id,\r\n        (await bot.getMe()).mention.markdown,\r\n        parse_mode=enums.ParseMode.MARKDOWN\r\n    )\r\n\r\nbot_1.run(run_multiple_bots([bot_1, bot_2]))\r\n```\r\n\r\n- Create Listener ( Conversation ):\r\n---\r\n```python\r\nfrom zdgram import types, enums, Bot\r\n\r\nbot = Bot(bot_token=\"\")\r\n\r\ndef filter_text_and_private(m: types.Message):\r\n    return bool(m.text and m.chat.type == enums.ChatType.PRIVATE)\r\n\r\n@bot.onMessage(func=filter_text_and_private)\r\nasync def on_message(bot: Bot, message: types.Message):\r\n    await bot.sendMessage(\r\n        message.chat.id,\r\n        \"Send your name\",\r\n        reply_to_message_id=message.id\r\n    )\r\n    msg = await bot.listen(filter_text_and_private)\r\n    return await bot.sendMessage(\r\n        message.chat.id,\r\n        \"Your name is : \" + msg.text\r\n    )\r\n```\r\n\r\n# LICENSE :\r\n- [MIT](https://github.com/x72x/zdgram/blob/master/LICENSE)\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python module based on https://core.telegram.org/bots/api",
    "version": "0.1.dev7",
    "project_urls": null,
    "split_keywords": [
        "bots",
        "bot-api",
        "telegram"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14d3b6feee0ab690fe7e9d4b4c255930c1981de9f79c687e35508dab15d1dded",
                "md5": "7469528104f5aa3203e6366722d4819b",
                "sha256": "c0d0e5da988feb93bb49c2e2cddb1f54c42f109678fa89b2c273a4def599bd1d"
            },
            "downloads": -1,
            "filename": "zdgram-0.1.dev7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7469528104f5aa3203e6366722d4819b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "~=3.8",
            "size": 73878,
            "upload_time": "2024-01-25T16:35:49",
            "upload_time_iso_8601": "2024-01-25T16:35:49.158767Z",
            "url": "https://files.pythonhosted.org/packages/14/d3/b6feee0ab690fe7e9d4b4c255930c1981de9f79c687e35508dab15d1dded/zdgram-0.1.dev7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "89842e2bd66827fe736dffdd1b1d1d2c986763f6fe036c316f89f40f9bc50eb6",
                "md5": "9af427e1c336b18145f8ef7fe2fdb938",
                "sha256": "c3daecb90023db119ac25e4bf0e6fd833ec9642a1c91b6ccd66a915f7b29bc9a"
            },
            "downloads": -1,
            "filename": "zdgram-0.1.dev7.tar.gz",
            "has_sig": false,
            "md5_digest": "9af427e1c336b18145f8ef7fe2fdb938",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.8",
            "size": 35346,
            "upload_time": "2024-01-25T16:35:51",
            "upload_time_iso_8601": "2024-01-25T16:35:51.042812Z",
            "url": "https://files.pythonhosted.org/packages/89/84/2e2bd66827fe736dffdd1b1d1d2c986763f6fe036c316f89f40f9bc50eb6/zdgram-0.1.dev7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-25 16:35:51",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "zdgram"
}
        
Elapsed time: 0.35653s