zalo-py 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
zalo_py-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tbtn123
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
zalo_py-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: zalo-py
3
+ Version: 0.1.0
4
+ Summary: Async Python wrapper for the Zalo Bot API
5
+ Keywords: zalo,zalo-bot,bot-api,asyncio,httpx,chatbot
6
+ Author: tbtn123
7
+ Author-email: tbtn123 <167616182+tbtn123@users.noreply.github.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Framework :: AsyncIO
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Dist: httpx>=0.29.0
19
+ Requires-Dist: starlette>=0.40 ; extra == 'webhook'
20
+ Requires-Dist: uvicorn>=0.30 ; extra == 'webhook'
21
+ Requires-Python: >=3.12
22
+ Project-URL: Homepage, https://github.com/tbtn123/zalo.py
23
+ Project-URL: Repository, https://github.com/tbtn123/zalo.py
24
+ Project-URL: Issues, https://github.com/tbtn123/zalo.py/issues
25
+ Provides-Extra: webhook
26
+ Description-Content-Type: text/markdown
27
+
28
+ # zalo.py
29
+
30
+ Async Python wrapper for the [Zalo Bot API](https://docs.zaloplatforms.com/docs/BOT/apis/).
31
+
32
+ It uses `asyncio` and `httpx`. You write small handlers, then run the bot with long
33
+ polling or a webhook. Python 3.12+.
34
+
35
+ ## Features
36
+
37
+ - Async client with no blocking calls.
38
+ - Handler filters: `text`, `contains`, `regex`, and `step`.
39
+ - One session per user per chat, with a TTL.
40
+ - Long polling and webhooks share the same handlers.
41
+ - Retries on network errors and 429 quota errors.
42
+ - Typed models: `Message`, `Chat`, `User`, `Session`, `BotInfo`, `Update`.
43
+ - One error type, `ZaloAPIError`, with `error_code` and `description`.
44
+
45
+ ## Install
46
+
47
+ The package is not on PyPI yet. Clone it and sync:
48
+
49
+ ```bash
50
+ git clone https://github.com/tbtn123/zalo.py
51
+ cd zalo.py
52
+ uv sync
53
+ ```
54
+
55
+ Add the webhook extra if you want the built-in server:
56
+
57
+ ```bash
58
+ uv sync --extra webhook
59
+ ```
60
+
61
+ The import name is `zalo_py`. The PyPI name will be `zalo-py` when published.
62
+
63
+ ## Quick start
64
+
65
+ ```python
66
+ import asyncio
67
+
68
+ from zalo_py.core import Bot
69
+
70
+ bot = Bot("your-bot-token")
71
+
72
+
73
+ @bot.on_message(contains="hello")
74
+ async def hello(message, session):
75
+ await message.send("hi!")
76
+
77
+
78
+ asyncio.run(bot.start_polling())
79
+ ```
80
+
81
+ ## Handlers
82
+
83
+ Decorators register a function. Filters are ANDed, and the first match wins.
84
+
85
+ ```python
86
+ @bot.on_message(text="ping")
87
+ async def ping(message, session):
88
+ await message.typing()
89
+ await message.send("pong")
90
+
91
+
92
+ @bot.on_message(regex=r"^/start")
93
+ async def start(message, session):
94
+ session.set_step("name", seconds=60)
95
+ await message.send("What is your name?")
96
+
97
+
98
+ @bot.on_message(step="name")
99
+ async def save_name(message, session):
100
+ session.data["name"] = message.text
101
+ await message.send(f"Hello {session.data['name']}!")
102
+ session.clear()
103
+ ```
104
+
105
+ ## Sessions
106
+
107
+ A session is stored under `"<chat_id>:<sender_id>"`. Use it for multi-step
108
+ conversations. Set the step with `session.set_step(...)`, then match it with
109
+ `@bot.on_message(step=...)`. Sessions expire after `session_ttl` seconds.
110
+
111
+ ## Webhook
112
+
113
+ Webhooks use the same handlers. Set the public URL first:
114
+
115
+ ```python
116
+ await bot.set_webhook("https://example.com/webhook", "a-secret-token")
117
+ await bot.run_webhook(host="0.0.0.0", port=8080)
118
+ ```
119
+
120
+ Zalo sends the secret in the `X-Bot-Api-Secret-Token` header. Requests with a wrong
121
+ or missing secret get `403`.
122
+
123
+ ## Examples
124
+
125
+ - [`local_testing/bot.py`](local_testing/bot.py) - polling bot with a few handlers
126
+ - [`local_testing/webhook_bot.py`](local_testing/webhook_bot.py) - same bot behind a webhook
127
+
128
+ ## API
129
+
130
+ The main class is [`Bot`](src/zalo_py/core.py). It has methods for messages,
131
+ stickers, photos, voice, chat actions, updates, and webhook management. Every public
132
+ method has a docstring with arguments and errors.
133
+
134
+ Models live in [`src/zalo_py/models.py`](src/zalo_py/models.py). `Message` and `Chat`
135
+ also have shortcut methods such as `send()`, `send_photo()`, and `typing()`.
136
+
137
+ ## Notes
138
+
139
+ - Text is limited to 2000 characters per message.
140
+ - Media is sent by URL. `send_voice` only accepts `.aac` files.
141
+ - Webhook URLs must use `https://`.
142
+ - `get_update()` returns `None` when a poll times out.
143
+
144
+ ## Project layout
145
+
146
+ ```
147
+ src/zalo_py/core.py Bot class, polling and dispatch
148
+ src/zalo_py/models.py dataclass models
149
+ src/zalo_py/http.py httpx client with retries
150
+ src/zalo_py/webhook.py Starlette webhook server
151
+ src/zalo_py/enum.py ParseMode, ChatAction, MessageType
152
+ src/zalo_py/exceptions.py ZaloAPIError
153
+ ```
154
+
155
+ ## For LLMs and coding agents
156
+
157
+ - [`llms.txt`](llms.txt) - short project context and links
158
+ - [`AGENTS.md`](AGENTS.md) - repo map and development commands
159
+
160
+ ## License
161
+
162
+ MIT
@@ -0,0 +1,135 @@
1
+ # zalo.py
2
+
3
+ Async Python wrapper for the [Zalo Bot API](https://docs.zaloplatforms.com/docs/BOT/apis/).
4
+
5
+ It uses `asyncio` and `httpx`. You write small handlers, then run the bot with long
6
+ polling or a webhook. Python 3.12+.
7
+
8
+ ## Features
9
+
10
+ - Async client with no blocking calls.
11
+ - Handler filters: `text`, `contains`, `regex`, and `step`.
12
+ - One session per user per chat, with a TTL.
13
+ - Long polling and webhooks share the same handlers.
14
+ - Retries on network errors and 429 quota errors.
15
+ - Typed models: `Message`, `Chat`, `User`, `Session`, `BotInfo`, `Update`.
16
+ - One error type, `ZaloAPIError`, with `error_code` and `description`.
17
+
18
+ ## Install
19
+
20
+ The package is not on PyPI yet. Clone it and sync:
21
+
22
+ ```bash
23
+ git clone https://github.com/tbtn123/zalo.py
24
+ cd zalo.py
25
+ uv sync
26
+ ```
27
+
28
+ Add the webhook extra if you want the built-in server:
29
+
30
+ ```bash
31
+ uv sync --extra webhook
32
+ ```
33
+
34
+ The import name is `zalo_py`. The PyPI name will be `zalo-py` when published.
35
+
36
+ ## Quick start
37
+
38
+ ```python
39
+ import asyncio
40
+
41
+ from zalo_py.core import Bot
42
+
43
+ bot = Bot("your-bot-token")
44
+
45
+
46
+ @bot.on_message(contains="hello")
47
+ async def hello(message, session):
48
+ await message.send("hi!")
49
+
50
+
51
+ asyncio.run(bot.start_polling())
52
+ ```
53
+
54
+ ## Handlers
55
+
56
+ Decorators register a function. Filters are ANDed, and the first match wins.
57
+
58
+ ```python
59
+ @bot.on_message(text="ping")
60
+ async def ping(message, session):
61
+ await message.typing()
62
+ await message.send("pong")
63
+
64
+
65
+ @bot.on_message(regex=r"^/start")
66
+ async def start(message, session):
67
+ session.set_step("name", seconds=60)
68
+ await message.send("What is your name?")
69
+
70
+
71
+ @bot.on_message(step="name")
72
+ async def save_name(message, session):
73
+ session.data["name"] = message.text
74
+ await message.send(f"Hello {session.data['name']}!")
75
+ session.clear()
76
+ ```
77
+
78
+ ## Sessions
79
+
80
+ A session is stored under `"<chat_id>:<sender_id>"`. Use it for multi-step
81
+ conversations. Set the step with `session.set_step(...)`, then match it with
82
+ `@bot.on_message(step=...)`. Sessions expire after `session_ttl` seconds.
83
+
84
+ ## Webhook
85
+
86
+ Webhooks use the same handlers. Set the public URL first:
87
+
88
+ ```python
89
+ await bot.set_webhook("https://example.com/webhook", "a-secret-token")
90
+ await bot.run_webhook(host="0.0.0.0", port=8080)
91
+ ```
92
+
93
+ Zalo sends the secret in the `X-Bot-Api-Secret-Token` header. Requests with a wrong
94
+ or missing secret get `403`.
95
+
96
+ ## Examples
97
+
98
+ - [`local_testing/bot.py`](local_testing/bot.py) - polling bot with a few handlers
99
+ - [`local_testing/webhook_bot.py`](local_testing/webhook_bot.py) - same bot behind a webhook
100
+
101
+ ## API
102
+
103
+ The main class is [`Bot`](src/zalo_py/core.py). It has methods for messages,
104
+ stickers, photos, voice, chat actions, updates, and webhook management. Every public
105
+ method has a docstring with arguments and errors.
106
+
107
+ Models live in [`src/zalo_py/models.py`](src/zalo_py/models.py). `Message` and `Chat`
108
+ also have shortcut methods such as `send()`, `send_photo()`, and `typing()`.
109
+
110
+ ## Notes
111
+
112
+ - Text is limited to 2000 characters per message.
113
+ - Media is sent by URL. `send_voice` only accepts `.aac` files.
114
+ - Webhook URLs must use `https://`.
115
+ - `get_update()` returns `None` when a poll times out.
116
+
117
+ ## Project layout
118
+
119
+ ```
120
+ src/zalo_py/core.py Bot class, polling and dispatch
121
+ src/zalo_py/models.py dataclass models
122
+ src/zalo_py/http.py httpx client with retries
123
+ src/zalo_py/webhook.py Starlette webhook server
124
+ src/zalo_py/enum.py ParseMode, ChatAction, MessageType
125
+ src/zalo_py/exceptions.py ZaloAPIError
126
+ ```
127
+
128
+ ## For LLMs and coding agents
129
+
130
+ - [`llms.txt`](llms.txt) - short project context and links
131
+ - [`AGENTS.md`](AGENTS.md) - repo map and development commands
132
+
133
+ ## License
134
+
135
+ MIT
@@ -0,0 +1,53 @@
1
+ [project]
2
+ name = "zalo-py"
3
+ version = "0.1.0"
4
+ description = "Async Python wrapper for the Zalo Bot API"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ keywords = [
8
+ "zalo",
9
+ "zalo-bot",
10
+ "bot-api",
11
+ "asyncio",
12
+ "httpx",
13
+ "chatbot",
14
+ ]
15
+ license = "MIT"
16
+ license-files = ["LICENSE"]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Framework :: AsyncIO",
20
+ "Intended Audience :: Developers",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ ]
27
+ dependencies = ["httpx>=0.29.0"]
28
+
29
+ [[project.authors]]
30
+ name = "tbtn123"
31
+ email = "167616182+tbtn123@users.noreply.github.com"
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/tbtn123/zalo.py"
35
+ Repository = "https://github.com/tbtn123/zalo.py"
36
+ Issues = "https://github.com/tbtn123/zalo.py/issues"
37
+
38
+ [project.optional-dependencies]
39
+ webhook = [
40
+ "starlette>=0.40",
41
+ "uvicorn>=0.30",
42
+ ]
43
+
44
+ [build-system]
45
+ requires = ["uv_build>=0.13.7,<0.14.0"]
46
+ build-backend = "uv_build"
47
+
48
+ [dependency-groups]
49
+ dev = [
50
+ "pytest>=9.2.0",
51
+ "python-dotenv>=1.2.4",
52
+ "ruff>=0.17.6",
53
+ ]
@@ -0,0 +1,48 @@
1
+ [project]
2
+ name = "zalo-py"
3
+ version = "0.1.0"
4
+ description = "Async Python wrapper for the Zalo Bot API"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "tbtn123", email = "167616182+tbtn123@users.noreply.github.com" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ keywords = ["zalo", "zalo-bot", "bot-api", "asyncio", "httpx", "chatbot"]
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Framework :: AsyncIO",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Topic :: Software Development :: Libraries :: Python Modules",
22
+ ]
23
+ dependencies = [
24
+ "httpx>=0.29.0",
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/tbtn123/zalo.py"
29
+ Repository = "https://github.com/tbtn123/zalo.py"
30
+ Issues = "https://github.com/tbtn123/zalo.py/issues"
31
+
32
+
33
+ [build-system]
34
+ requires = ["uv_build>=0.13.7,<0.14.0"]
35
+ build-backend = "uv_build"
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "pytest>=9.2.0",
40
+ "python-dotenv>=1.2.4",
41
+ "ruff>=0.17.6",
42
+ ]
43
+
44
+ [project.optional-dependencies]
45
+ webhook = [
46
+ "starlette>=0.40",
47
+ "uvicorn>=0.30",
48
+ ]
@@ -0,0 +1,2 @@
1
+ def hello() -> str:
2
+ return "Hello from zalo-py!"