python-vk-bot 0.1.0__tar.gz → 0.2.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.
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/CHANGELOG.md +25 -0
- python_vk_bot-0.1.0/README.md → python_vk_bot-0.2.0/PKG-INFO +101 -4
- python_vk_bot-0.1.0/PKG-INFO → python_vk_bot-0.2.0/README.md +75 -25
- python_vk_bot-0.2.0/examples/README.md +93 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/pyproject.toml +8 -1
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/__init__.py +17 -1
- python_vk_bot-0.2.0/python_vk_bot/bot.py +350 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/errors.py +4 -0
- python_vk_bot-0.2.0/python_vk_bot/models/__init__.py +24 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/models/api.py +26 -0
- python_vk_bot-0.2.0/python_vk_bot/models/attachments.py +138 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/models/messages.py +6 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/transport.py +85 -1
- python_vk_bot-0.1.0/python_vk_bot/bot.py +0 -184
- python_vk_bot-0.1.0/python_vk_bot/models/__init__.py +0 -4
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/.gitignore +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/LICENSE +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/docs/decisions/README.md +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/.agents/skills/telegram-to-vk/SKILL.md +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/.agents/skills/telegram-to-vk/references/migration-mapping.md +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/_config.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/application.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/callback.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/context.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/filters.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/handlers.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/long_poll.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/models/base.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/models/events.py +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/py.typed +0 -0
- {python_vk_bot-0.1.0 → python_vk_bot-0.2.0}/python_vk_bot/settings.py +0 -0
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes will be documented here, following Keep a Changelog.
|
|
4
4
|
|
|
5
|
+
## 0.2.0 - 2026-11-01
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- An ordinary and inline keyboard example, with setup and usage instructions for all
|
|
10
|
+
examples in the [examples guide](examples/README.md).
|
|
11
|
+
- Photo and document uploads from bytes, paths and binary files, with typed saved
|
|
12
|
+
attachments and document/voice upload selection.
|
|
13
|
+
- Typed incoming photo, document, video and voice views through
|
|
14
|
+
`Message.typed_attachments`, preserving raw attachments and unknown fields.
|
|
15
|
+
- Attachment support in message editing, a photo replacement convenience method and
|
|
16
|
+
explicit message deletion. See [media contracts and limits](docs/development/media-api.md).
|
|
17
|
+
- An interactive PNG map example with serialized navigation updates. Live VK photo
|
|
18
|
+
replacement remains unverified; an opt-in integration test is available.
|
|
19
|
+
- Installation and compatibility guidance for the separate `main` (Python >=3.14)
|
|
20
|
+
and `compat/py39` (tested on Python 3.9–3.14) branches. See the
|
|
21
|
+
[branch comparison](docs/development/python-compatibility.md).
|
|
22
|
+
- Repository, documentation, issue tracker and changelog links in package metadata.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Isolate nested attachment metadata from raw message data when creating typed views.
|
|
27
|
+
- Reject conflicting injected-client defaults before multipart uploads instead of
|
|
28
|
+
sending malformed requests. See [client restrictions](docs/development/media-api.md#resources-and-limitations).
|
|
29
|
+
|
|
5
30
|
## 0.1.0 - 2026-10-31
|
|
6
31
|
|
|
7
32
|
### Added
|
|
@@ -1,12 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: python-vk-bot
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: An asynchronous framework for VK community bots.
|
|
5
|
+
Project-URL: Homepage, https://github.com/fomenko-ai/python-vk-bot
|
|
6
|
+
Project-URL: Repository, https://github.com/fomenko-ai/python-vk-bot
|
|
7
|
+
Project-URL: Documentation, https://github.com/fomenko-ai/python-vk-bot/blob/main/README.md
|
|
8
|
+
Project-URL: Issues, https://github.com/fomenko-ai/python-vk-bot/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/fomenko-ai/python-vk-bot/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Aleksei Fomenko <fomenko_ai@proton.me>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: asyncio,bot,vk
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.14
|
|
19
|
+
Requires-Dist: httpx<1,>=0.28
|
|
20
|
+
Requires-Dist: pydantic-settings<3,>=2.12
|
|
21
|
+
Requires-Dist: pydantic<3,>=2.12
|
|
22
|
+
Provides-Extra: callback
|
|
23
|
+
Requires-Dist: starlette<1,>=0.49; extra == 'callback'
|
|
24
|
+
Requires-Dist: uvicorn<1,>=0.38; extra == 'callback'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
1
27
|
<p align="center">
|
|
2
28
|
<img src="logo.png" alt="python-vk-bot logo" width="720">
|
|
3
29
|
</p>
|
|
4
30
|
|
|
31
|
+
[](https://github.com/fomenko-ai/python-vk-bot/tree/main)
|
|
32
|
+
[](https://github.com/fomenko-ai/python-vk-bot/tree/compat/py39)
|
|
33
|
+
[](LICENSE)
|
|
34
|
+
|
|
5
35
|
# python-vk-bot
|
|
6
36
|
|
|
7
37
|
An asynchronous framework for VK community bots, inspired by python-telegram-bot.
|
|
8
|
-
|
|
9
|
-
network access; see [verification results](docs/development/verification.md).
|
|
38
|
+
Supports VK API **5.199**.
|
|
10
39
|
|
|
11
40
|
## Installation
|
|
12
41
|
|
|
@@ -14,6 +43,15 @@ network access; see [verification results](docs/development/verification.md).
|
|
|
14
43
|
uv add python-vk-bot
|
|
15
44
|
```
|
|
16
45
|
|
|
46
|
+
For Python 3.9–3.13, use the `compat/py39` branch:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv add git+https://github.com/fomenko-ai/python-vk-bot.git --branch compat/py39
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
See [Python compatibility](docs/development/python-compatibility.md) for branch
|
|
53
|
+
differences, optional dependencies and installation with pip.
|
|
54
|
+
|
|
17
55
|
### Install from this checkout
|
|
18
56
|
|
|
19
57
|
```bash
|
|
@@ -26,6 +64,17 @@ For the optional Callback HTTP receiver:
|
|
|
26
64
|
uv sync --locked --extra callback
|
|
27
65
|
```
|
|
28
66
|
|
|
67
|
+
## Examples
|
|
68
|
+
|
|
69
|
+
See the [examples guide](examples/README.md) for setup, required events and run commands.
|
|
70
|
+
|
|
71
|
+
| Example | Description |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| [Echo bot](examples/echo.py) | Reply to text messages using Bots Long Poll |
|
|
74
|
+
| [Keyboards](examples/keyboards.py) | Ordinary text buttons and inline callback buttons with message editing |
|
|
75
|
+
| [Interactive map](examples/interactive_map.py) | Generate, upload and replace a PNG using navigation buttons |
|
|
76
|
+
| [Callback receiver](examples/callback.py) | Receive events through an ASGI application |
|
|
77
|
+
|
|
29
78
|
## Long Poll bot
|
|
30
79
|
|
|
31
80
|
Enable Bots Long Poll and the `message_new` event in the community settings. Configure
|
|
@@ -137,8 +186,8 @@ async with Bot(token) as bot:
|
|
|
137
186
|
user = await bot.get_user_info(user_id)
|
|
138
187
|
```
|
|
139
188
|
|
|
140
|
-
An injected `httpx.AsyncClient` remains caller-owned. Methods cover
|
|
141
|
-
forwarding, fetching a message/user, answering message events, and obtaining Long Poll
|
|
189
|
+
An injected `httpx.AsyncClient` remains caller-owned. Methods cover uploading, sending,
|
|
190
|
+
editing, deleting, forwarding, fetching a message/user, answering message events, and obtaining Long Poll
|
|
142
191
|
connection data. `Bot.request(method, parameters)` exposes raw JSON results for additional
|
|
143
192
|
VK methods; nested request parameters must be JSON encoded explicitly.
|
|
144
193
|
|
|
@@ -191,6 +240,53 @@ Partial handler failures, restarts and multiple workers can repeat side effects;
|
|
|
191
240
|
is not a durable queue or an exactly-once processing guarantee. See the architecture
|
|
192
241
|
for delivery limitations and resource limits.
|
|
193
242
|
|
|
243
|
+
## Media and location
|
|
244
|
+
|
|
245
|
+
With an initialized bot:
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from pathlib import Path
|
|
249
|
+
|
|
250
|
+
photo = await bot.upload_photo(peer_id, Path("map.png"))
|
|
251
|
+
message_id = await bot.send_message(peer_id, "Map", attachment=photo, keyboard=keyboard)
|
|
252
|
+
|
|
253
|
+
document = await bot.upload_document(peer_id, Path("report.pdf"))
|
|
254
|
+
await bot.send_message(peer_id, "Report", attachment=document)
|
|
255
|
+
|
|
256
|
+
await bot.edit_message_media(
|
|
257
|
+
peer_id,
|
|
258
|
+
new_png_bytes,
|
|
259
|
+
message_id=message_id,
|
|
260
|
+
caption="Updated map",
|
|
261
|
+
keyboard=keyboard,
|
|
262
|
+
filename="map.png",
|
|
263
|
+
)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Uploads accept bytes, `Path` and binary file objects. Files are read off the event loop
|
|
267
|
+
and buffered in memory; use inputs that fit comfortably in memory. Existing attachment
|
|
268
|
+
identifiers can be passed directly to send/edit methods, and a saved photo passed to
|
|
269
|
+
`edit_message_media` skips uploading. Supply the desired caption and keyboard explicitly;
|
|
270
|
+
there is no automatic fallback send when editing fails.
|
|
271
|
+
|
|
272
|
+
Incoming `message.attachments` remain raw dictionaries. Use `message.typed_attachments`
|
|
273
|
+
for `PhotoAttachment`, `DocumentAttachment`, `VideoAttachment`, `AudioMessageAttachment`
|
|
274
|
+
or a generic `Attachment` preserving unknown fields. With `message.geo is not None`,
|
|
275
|
+
read `message.geo.coordinates.latitude` and `.longitude`; `filters.LOCATION` selects
|
|
276
|
+
these messages. Incomplete coordinate objects fail validation.
|
|
277
|
+
|
|
278
|
+
See the [media API guide](docs/development/media-api.md) for incoming attachment examples,
|
|
279
|
+
deletion, errors and VK restrictions, and [interactive_map.py](examples/interactive_map.py)
|
|
280
|
+
for a PNG grid with navigation buttons. Enable `message_new` and `message_event`, then run:
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
uv run python examples/interactive_map.py
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
The media API has network-free regression tests. Actual replacement of a photo in an
|
|
287
|
+
existing VK message has not yet been verified with a live token; an explicitly enabled
|
|
288
|
+
[integration test](docs/development/media-api.md#live-integration-test) is provided.
|
|
289
|
+
|
|
194
290
|
## Agent Skills
|
|
195
291
|
|
|
196
292
|
The bundled **telegram-to-vk** Agent Skill helps AI coding agents migrate
|
|
@@ -213,4 +309,5 @@ checkout, and usage examples.
|
|
|
213
309
|
- [python-telegram-bot design mapping](docs/architecture/python-telegram-bot-compatibility.md)
|
|
214
310
|
- [VK API support](docs/development/api-compatibility.md)
|
|
215
311
|
- [Contributing and verification](CONTRIBUTING.md)
|
|
312
|
+
- [Python compatibility branches](docs/development/python-compatibility.md)
|
|
216
313
|
- [Changelog](CHANGELOG.md)
|
|
@@ -1,33 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: python-vk-bot
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: An asynchronous framework for VK community bots.
|
|
5
|
-
Author-email: Aleksei Fomenko <fomenko_ai@proton.me>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Keywords: asyncio,bot,vk
|
|
9
|
-
Classifier: Development Status :: 3 - Alpha
|
|
10
|
-
Classifier: Intended Audience :: Developers
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
-
Classifier: Typing :: Typed
|
|
13
|
-
Requires-Python: >=3.14
|
|
14
|
-
Requires-Dist: httpx<1,>=0.28
|
|
15
|
-
Requires-Dist: pydantic-settings<3,>=2.12
|
|
16
|
-
Requires-Dist: pydantic<3,>=2.12
|
|
17
|
-
Provides-Extra: callback
|
|
18
|
-
Requires-Dist: starlette<1,>=0.49; extra == 'callback'
|
|
19
|
-
Requires-Dist: uvicorn<1,>=0.38; extra == 'callback'
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
|
|
22
1
|
<p align="center">
|
|
23
2
|
<img src="logo.png" alt="python-vk-bot logo" width="720">
|
|
24
3
|
</p>
|
|
25
4
|
|
|
5
|
+
[](https://github.com/fomenko-ai/python-vk-bot/tree/main)
|
|
6
|
+
[](https://github.com/fomenko-ai/python-vk-bot/tree/compat/py39)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
26
9
|
# python-vk-bot
|
|
27
10
|
|
|
28
11
|
An asynchronous framework for VK community bots, inspired by python-telegram-bot.
|
|
29
|
-
|
|
30
|
-
network access; see [verification results](docs/development/verification.md).
|
|
12
|
+
Supports VK API **5.199**.
|
|
31
13
|
|
|
32
14
|
## Installation
|
|
33
15
|
|
|
@@ -35,6 +17,15 @@ network access; see [verification results](docs/development/verification.md).
|
|
|
35
17
|
uv add python-vk-bot
|
|
36
18
|
```
|
|
37
19
|
|
|
20
|
+
For Python 3.9–3.13, use the `compat/py39` branch:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
uv add git+https://github.com/fomenko-ai/python-vk-bot.git --branch compat/py39
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
See [Python compatibility](docs/development/python-compatibility.md) for branch
|
|
27
|
+
differences, optional dependencies and installation with pip.
|
|
28
|
+
|
|
38
29
|
### Install from this checkout
|
|
39
30
|
|
|
40
31
|
```bash
|
|
@@ -47,6 +38,17 @@ For the optional Callback HTTP receiver:
|
|
|
47
38
|
uv sync --locked --extra callback
|
|
48
39
|
```
|
|
49
40
|
|
|
41
|
+
## Examples
|
|
42
|
+
|
|
43
|
+
See the [examples guide](examples/README.md) for setup, required events and run commands.
|
|
44
|
+
|
|
45
|
+
| Example | Description |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| [Echo bot](examples/echo.py) | Reply to text messages using Bots Long Poll |
|
|
48
|
+
| [Keyboards](examples/keyboards.py) | Ordinary text buttons and inline callback buttons with message editing |
|
|
49
|
+
| [Interactive map](examples/interactive_map.py) | Generate, upload and replace a PNG using navigation buttons |
|
|
50
|
+
| [Callback receiver](examples/callback.py) | Receive events through an ASGI application |
|
|
51
|
+
|
|
50
52
|
## Long Poll bot
|
|
51
53
|
|
|
52
54
|
Enable Bots Long Poll and the `message_new` event in the community settings. Configure
|
|
@@ -158,8 +160,8 @@ async with Bot(token) as bot:
|
|
|
158
160
|
user = await bot.get_user_info(user_id)
|
|
159
161
|
```
|
|
160
162
|
|
|
161
|
-
An injected `httpx.AsyncClient` remains caller-owned. Methods cover
|
|
162
|
-
forwarding, fetching a message/user, answering message events, and obtaining Long Poll
|
|
163
|
+
An injected `httpx.AsyncClient` remains caller-owned. Methods cover uploading, sending,
|
|
164
|
+
editing, deleting, forwarding, fetching a message/user, answering message events, and obtaining Long Poll
|
|
163
165
|
connection data. `Bot.request(method, parameters)` exposes raw JSON results for additional
|
|
164
166
|
VK methods; nested request parameters must be JSON encoded explicitly.
|
|
165
167
|
|
|
@@ -212,6 +214,53 @@ Partial handler failures, restarts and multiple workers can repeat side effects;
|
|
|
212
214
|
is not a durable queue or an exactly-once processing guarantee. See the architecture
|
|
213
215
|
for delivery limitations and resource limits.
|
|
214
216
|
|
|
217
|
+
## Media and location
|
|
218
|
+
|
|
219
|
+
With an initialized bot:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from pathlib import Path
|
|
223
|
+
|
|
224
|
+
photo = await bot.upload_photo(peer_id, Path("map.png"))
|
|
225
|
+
message_id = await bot.send_message(peer_id, "Map", attachment=photo, keyboard=keyboard)
|
|
226
|
+
|
|
227
|
+
document = await bot.upload_document(peer_id, Path("report.pdf"))
|
|
228
|
+
await bot.send_message(peer_id, "Report", attachment=document)
|
|
229
|
+
|
|
230
|
+
await bot.edit_message_media(
|
|
231
|
+
peer_id,
|
|
232
|
+
new_png_bytes,
|
|
233
|
+
message_id=message_id,
|
|
234
|
+
caption="Updated map",
|
|
235
|
+
keyboard=keyboard,
|
|
236
|
+
filename="map.png",
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Uploads accept bytes, `Path` and binary file objects. Files are read off the event loop
|
|
241
|
+
and buffered in memory; use inputs that fit comfortably in memory. Existing attachment
|
|
242
|
+
identifiers can be passed directly to send/edit methods, and a saved photo passed to
|
|
243
|
+
`edit_message_media` skips uploading. Supply the desired caption and keyboard explicitly;
|
|
244
|
+
there is no automatic fallback send when editing fails.
|
|
245
|
+
|
|
246
|
+
Incoming `message.attachments` remain raw dictionaries. Use `message.typed_attachments`
|
|
247
|
+
for `PhotoAttachment`, `DocumentAttachment`, `VideoAttachment`, `AudioMessageAttachment`
|
|
248
|
+
or a generic `Attachment` preserving unknown fields. With `message.geo is not None`,
|
|
249
|
+
read `message.geo.coordinates.latitude` and `.longitude`; `filters.LOCATION` selects
|
|
250
|
+
these messages. Incomplete coordinate objects fail validation.
|
|
251
|
+
|
|
252
|
+
See the [media API guide](docs/development/media-api.md) for incoming attachment examples,
|
|
253
|
+
deletion, errors and VK restrictions, and [interactive_map.py](examples/interactive_map.py)
|
|
254
|
+
for a PNG grid with navigation buttons. Enable `message_new` and `message_event`, then run:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
uv run python examples/interactive_map.py
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
The media API has network-free regression tests. Actual replacement of a photo in an
|
|
261
|
+
existing VK message has not yet been verified with a live token; an explicitly enabled
|
|
262
|
+
[integration test](docs/development/media-api.md#live-integration-test) is provided.
|
|
263
|
+
|
|
215
264
|
## Agent Skills
|
|
216
265
|
|
|
217
266
|
The bundled **telegram-to-vk** Agent Skill helps AI coding agents migrate
|
|
@@ -234,4 +283,5 @@ checkout, and usage examples.
|
|
|
234
283
|
- [python-telegram-bot design mapping](docs/architecture/python-telegram-bot-compatibility.md)
|
|
235
284
|
- [VK API support](docs/development/api-compatibility.md)
|
|
236
285
|
- [Contributing and verification](CONTRIBUTING.md)
|
|
286
|
+
- [Python compatibility branches](docs/development/python-compatibility.md)
|
|
237
287
|
- [Changelog](CHANGELOG.md)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Run these examples from the repository root on Python 3.14. Each script is a separate
|
|
4
|
+
application; start one at a time for the same community.
|
|
5
|
+
|
|
6
|
+
## Setup
|
|
7
|
+
|
|
8
|
+
Install the checkout and configure `VK_TOKEN` (a community token) and `VK_GROUP_ID`
|
|
9
|
+
(a positive community ID) in the environment:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uv sync --locked
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`BotSettings` reads the environment at startup; it does not load `.env` automatically.
|
|
16
|
+
See [settings](../README.md#settings) for optional configuration and explicit dotenv use.
|
|
17
|
+
|
|
18
|
+
For the Long Poll examples, enable Bots Long Poll in the community settings and select
|
|
19
|
+
the events listed below. Use API version 5.199, matching the library's default.
|
|
20
|
+
The Callback example uses its own HTTP delivery setup instead.
|
|
21
|
+
|
|
22
|
+
| Example | Demonstrates | Events |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| [echo.py](echo.py) | Text messages, filters and Long Poll lifecycle | `message_new` |
|
|
25
|
+
| [keyboards.py](keyboards.py) | Ordinary and inline keyboards, payloads and message editing | `message_new`, `message_event` |
|
|
26
|
+
| [interactive_map.py](interactive_map.py) | Photo upload and replacement with inline navigation | `message_new`, `message_event` |
|
|
27
|
+
| [callback.py](callback.py) | A Callback API receiver using an ASGI factory | `message_new` |
|
|
28
|
+
|
|
29
|
+
## Echo bot
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uv run python examples/echo.py
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Send a text message to the community. The bot replies with the same text. This is the
|
|
36
|
+
smallest example of `Application`, `BotSettings`, `MessageHandler` and `filters.TEXT`.
|
|
37
|
+
|
|
38
|
+
## Ordinary and inline keyboards
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv run python examples/keyboards.py
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- `/keyboard` opens a persistent ordinary keyboard with **Помощь**, **О боте** and
|
|
45
|
+
**Скрыть клавиатуру**. Text buttons are handled through `MessageHandler`; actions are
|
|
46
|
+
selected by their JSON `payload`, independently of the displayed label. Hiding sends
|
|
47
|
+
an empty ordinary keyboard. Send `/keyboard` to show it again.
|
|
48
|
+
- `/inline` sends a message with **Подтвердить** and **Отмена** callback buttons.
|
|
49
|
+
`MessageEventHandler` acknowledges the click with a snackbar, then edits that message
|
|
50
|
+
using `conversation_message_id`. Both buttons remain available for repeated use.
|
|
51
|
+
|
|
52
|
+
The example validates the payload namespace, structure and supported actions. Ordinary
|
|
53
|
+
message payloads are JSON strings; event payloads can also be objects. In a conversation,
|
|
54
|
+
any participant can change the inline selection: this demonstrates UI interaction,
|
|
55
|
+
without performing a privileged action or storing a confirmation workflow.
|
|
56
|
+
|
|
57
|
+
VK edit errors propagate through the application's error handling; there is no fallback
|
|
58
|
+
send. Running the example against a community is a live operation, not a unit test.
|
|
59
|
+
|
|
60
|
+
## Interactive map
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
uv run python examples/interactive_map.py
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Send `/map`. The bot renders a synthetic PNG grid using the standard library, uploads
|
|
67
|
+
it and adds navigation and zoom buttons. Each click renders and uploads a replacement
|
|
68
|
+
photo, then edits the same message with an explicit caption and keyboard.
|
|
69
|
+
|
|
70
|
+
One active map per peer is stored in memory. Only its creator can navigate it, and a
|
|
71
|
+
lock serializes render/upload/edit operations. Restarting the process loses the state;
|
|
72
|
+
send `/map` again. The grid is a demonstration image, not geographical map data.
|
|
73
|
+
|
|
74
|
+
Actual photo replacement has not yet been verified against live VK. See the
|
|
75
|
+
[media guide](../docs/development/media-api.md) for limitations and the opt-in integration
|
|
76
|
+
test. Upload and edit are separate operations; a failed edit can leave an unused photo.
|
|
77
|
+
|
|
78
|
+
## Callback API receiver
|
|
79
|
+
|
|
80
|
+
Set `VK_CALLBACK_SECRET` and `VK_CALLBACK_CONFIRMATION` in addition to `VK_TOKEN` and
|
|
81
|
+
`VK_GROUP_ID`, then run:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
uv run --extra callback uvicorn examples.callback:create_app --factory
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Expose the application's `/callback` endpoint through your HTTPS deployment. Configure
|
|
88
|
+
that address, the same secret and the `message_new` event in the community's Callback
|
|
89
|
+
API settings. The confirmation value must match the code provided by VK.
|
|
90
|
+
|
|
91
|
+
The receiver echoes text messages. `CallbackSettings` extends `BotSettings` with the
|
|
92
|
+
required secret and confirmation fields, and the ASGI lifespan manages the application's
|
|
93
|
+
resources. See [Callback API](../README.md#callback-api) for delivery semantics.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-vk-bot"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "An asynchronous framework for VK community bots."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.14"
|
|
@@ -20,6 +20,13 @@ classifiers = [
|
|
|
20
20
|
"Typing :: Typed",
|
|
21
21
|
]
|
|
22
22
|
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/fomenko-ai/python-vk-bot"
|
|
25
|
+
Repository = "https://github.com/fomenko-ai/python-vk-bot"
|
|
26
|
+
Documentation = "https://github.com/fomenko-ai/python-vk-bot/blob/main/README.md"
|
|
27
|
+
Issues = "https://github.com/fomenko-ai/python-vk-bot/issues"
|
|
28
|
+
Changelog = "https://github.com/fomenko-ai/python-vk-bot/blob/main/CHANGELOG.md"
|
|
29
|
+
|
|
23
30
|
[project.optional-dependencies]
|
|
24
31
|
callback = ["starlette>=0.49,<1", "uvicorn>=0.38,<1"]
|
|
25
32
|
|
|
@@ -7,16 +7,30 @@ from .callback import Callback
|
|
|
7
7
|
from .context import Context
|
|
8
8
|
from .handlers import CommandHandler, Handler, MessageEventHandler, MessageHandler
|
|
9
9
|
from .long_poll import LongPoll
|
|
10
|
-
from .models import
|
|
10
|
+
from .models import (
|
|
11
|
+
Attachment,
|
|
12
|
+
AudioMessageAttachment,
|
|
13
|
+
DocumentAttachment,
|
|
14
|
+
Keyboard,
|
|
15
|
+
Message,
|
|
16
|
+
MessageEvent,
|
|
17
|
+
PhotoAttachment,
|
|
18
|
+
Update,
|
|
19
|
+
User,
|
|
20
|
+
VideoAttachment,
|
|
21
|
+
)
|
|
11
22
|
from .settings import BotSettings
|
|
12
23
|
|
|
13
24
|
__all__ = [
|
|
14
25
|
"Application",
|
|
26
|
+
"Attachment",
|
|
27
|
+
"AudioMessageAttachment",
|
|
15
28
|
"Bot",
|
|
16
29
|
"BotSettings",
|
|
17
30
|
"Callback",
|
|
18
31
|
"CommandHandler",
|
|
19
32
|
"Context",
|
|
33
|
+
"DocumentAttachment",
|
|
20
34
|
"Handler",
|
|
21
35
|
"Keyboard",
|
|
22
36
|
"LongPoll",
|
|
@@ -24,7 +38,9 @@ __all__ = [
|
|
|
24
38
|
"MessageEvent",
|
|
25
39
|
"MessageEventHandler",
|
|
26
40
|
"MessageHandler",
|
|
41
|
+
"PhotoAttachment",
|
|
27
42
|
"Update",
|
|
28
43
|
"User",
|
|
44
|
+
"VideoAttachment",
|
|
29
45
|
"filters",
|
|
30
46
|
]
|