python-vk-bot 0.5.0__tar.gz → 0.6.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.5.0 → python_vk_bot-0.6.0}/CHANGELOG.md +12 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/PKG-INFO +2 -2
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/README.md +1 -1
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/examples/README.md +6 -3
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/pyproject.toml +1 -1
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/__init__.py +6 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/bot.py +7 -2
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/errors.py +4 -1
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/__init__.py +12 -1
- python_vk_bot-0.6.0/python_vk_bot/models/event_answers.py +14 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/keyboards.py +25 -4
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/transport.py +54 -1
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/.gitignore +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/LICENSE +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/docs/decisions/README.md +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/.agents/skills/telegram-to-vk/SKILL.md +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/.agents/skills/telegram-to-vk/references/migration-mapping.md +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/_config.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/application.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/callback.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/context.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/filters.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/handlers.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/long_poll.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/api.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/attachments.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/base.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/donut.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/events.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/models/messages.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/py.typed +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/queues.py +0 -0
- {python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/settings.py +0 -0
|
@@ -6,6 +6,18 @@ All notable changes will be documented here, following Keep a Changelog.
|
|
|
6
6
|
|
|
7
7
|
-
|
|
8
8
|
|
|
9
|
+
## 0.6.0 - 2026-11-06
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `OpenLinkButton` and `LocationButton` with automatic payload serialization, mixed
|
|
14
|
+
typed/raw keyboards, and `ButtonType.OPEN_LINK` / `ButtonType.LOCATION` values.
|
|
15
|
+
- `ShowSnackbar` for typed callback answers through `Bot.send_message_event_answer`,
|
|
16
|
+
validating VK's 90-character text limit while retaining raw mapping support.
|
|
17
|
+
- Optional `HTTPError.retry_after` in seconds, read from HTTP `Retry-After` integer
|
|
18
|
+
seconds or HTTP-date. No automatic retries or waits are added; VK API error 6
|
|
19
|
+
retains its separate `RateLimitError` behavior.
|
|
20
|
+
|
|
9
21
|
## 0.5.0 - 2026-11-05
|
|
10
22
|
|
|
11
23
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-vk-bot
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: An asynchronous framework for VK community bots.
|
|
5
5
|
Project-URL: Homepage, https://github.com/fomenko-ai/python-vk-bot
|
|
6
6
|
Project-URL: Repository, https://github.com/fomenko-ai/python-vk-bot
|
|
@@ -71,7 +71,7 @@ See the [examples guide](examples/README.md) for setup, required events and run
|
|
|
71
71
|
| Example | Description |
|
|
72
72
|
| --- | --- |
|
|
73
73
|
| [Echo bot](examples/echo.py) | Reply to text messages using Bots Long Poll |
|
|
74
|
-
| [Keyboards](examples/keyboards.py) |
|
|
74
|
+
| [Keyboards](examples/keyboards.py) | Text, callback, link and location buttons; typed snackbar answers and message editing |
|
|
75
75
|
| [Interactive map](examples/interactive_map.py) | Generate, upload and replace a PNG using navigation buttons |
|
|
76
76
|
| [Callback receiver](examples/callback.py) | Receive events through an ASGI application |
|
|
77
77
|
| [Background result](examples/background_result.py) | Return a local calculation through the unified event queue |
|
|
@@ -45,7 +45,7 @@ See the [examples guide](examples/README.md) for setup, required events and run
|
|
|
45
45
|
| Example | Description |
|
|
46
46
|
| --- | --- |
|
|
47
47
|
| [Echo bot](examples/echo.py) | Reply to text messages using Bots Long Poll |
|
|
48
|
-
| [Keyboards](examples/keyboards.py) |
|
|
48
|
+
| [Keyboards](examples/keyboards.py) | Text, callback, link and location buttons; typed snackbar answers and message editing |
|
|
49
49
|
| [Interactive map](examples/interactive_map.py) | Generate, upload and replace a PNG using navigation buttons |
|
|
50
50
|
| [Callback receiver](examples/callback.py) | Receive events through an ASGI application |
|
|
51
51
|
| [Background result](examples/background_result.py) | Return a local calculation through the unified event queue |
|
|
@@ -39,8 +39,9 @@ smallest example of `Application`, `BotSettings`, `MessageHandler` and `filters.
|
|
|
39
39
|
|
|
40
40
|
## Ordinary and inline keyboards
|
|
41
41
|
|
|
42
|
-
The example constructs Pydantic `TextButton
|
|
43
|
-
`
|
|
42
|
+
The example constructs Pydantic `TextButton`, `CallbackButton`, `OpenLinkButton` and
|
|
43
|
+
`LocationButton` objects and uses `ButtonColor` enum members for text/callback colors.
|
|
44
|
+
Dictionary payloads are JSON encoded by the library; callback answers use `ShowSnackbar`.
|
|
44
45
|
See the [keyboard API](../docs/development/keyboards.md) for model payloads and serialization.
|
|
45
46
|
|
|
46
47
|
```bash
|
|
@@ -50,10 +51,12 @@ uv run python examples/keyboards.py
|
|
|
50
51
|
- `/keyboard` opens a persistent ordinary keyboard with **Помощь**, **О боте** and
|
|
51
52
|
**Скрыть клавиатуру**. Text buttons are handled through `MessageHandler`; actions are
|
|
52
53
|
selected by their JSON `payload`, independently of the displayed label. Hiding sends
|
|
53
|
-
an empty ordinary keyboard. Send `/keyboard` to show it again.
|
|
54
|
+
an empty ordinary keyboard. Send `/keyboard` to show it again. A separate location
|
|
55
|
+
button opens VK's location chooser; the selected location is sent to the chat.
|
|
54
56
|
- `/inline` sends a message with **Подтвердить** and **Отмена** callback buttons.
|
|
55
57
|
`MessageEventHandler` acknowledges the click with a snackbar, then edits that message
|
|
56
58
|
using `conversation_message_id`. Both buttons remain available for repeated use.
|
|
59
|
+
A separate link button opens the VK bot documentation.
|
|
57
60
|
|
|
58
61
|
The example validates the payload namespace, structure and supported actions. Ordinary
|
|
59
62
|
message payloads are JSON strings; event payloads can also be objects. In a conversation,
|
|
@@ -25,9 +25,12 @@ from .models import (
|
|
|
25
25
|
DonutSubscriptionEvent,
|
|
26
26
|
DonutSubscriptionEventType,
|
|
27
27
|
Keyboard,
|
|
28
|
+
LocationButton,
|
|
28
29
|
Message,
|
|
29
30
|
MessageEvent,
|
|
31
|
+
OpenLinkButton,
|
|
30
32
|
PhotoAttachment,
|
|
33
|
+
ShowSnackbar,
|
|
31
34
|
TextButton,
|
|
32
35
|
Update,
|
|
33
36
|
User,
|
|
@@ -55,12 +58,15 @@ __all__ = [
|
|
|
55
58
|
"DonutSubscriptionHandler",
|
|
56
59
|
"Handler",
|
|
57
60
|
"Keyboard",
|
|
61
|
+
"LocationButton",
|
|
58
62
|
"LongPoll",
|
|
59
63
|
"Message",
|
|
60
64
|
"MessageEvent",
|
|
61
65
|
"MessageEventHandler",
|
|
62
66
|
"MessageHandler",
|
|
67
|
+
"OpenLinkButton",
|
|
63
68
|
"PhotoAttachment",
|
|
69
|
+
"ShowSnackbar",
|
|
64
70
|
"TextButton",
|
|
65
71
|
"TypeHandler",
|
|
66
72
|
"Update",
|
|
@@ -27,6 +27,7 @@ from .models.attachments import (
|
|
|
27
27
|
PhotoAttachment,
|
|
28
28
|
serialize_attachment,
|
|
29
29
|
)
|
|
30
|
+
from .models.event_answers import ShowSnackbar
|
|
30
31
|
from .models.messages import Keyboard, Message, MessagePage, User
|
|
31
32
|
from .transport import FileInput, HTTPTransport, Parameter
|
|
32
33
|
|
|
@@ -336,15 +337,19 @@ class Bot:
|
|
|
336
337
|
event_id: str,
|
|
337
338
|
user_id: int,
|
|
338
339
|
peer_id: int,
|
|
339
|
-
event_data: Mapping[str, JsonValue] | None = None,
|
|
340
|
+
event_data: ShowSnackbar | Mapping[str, JsonValue] | None = None,
|
|
340
341
|
) -> bool:
|
|
342
|
+
if isinstance(event_data, ShowSnackbar):
|
|
343
|
+
serialized_event_data = event_data.model_dump_json(by_alias=True)
|
|
344
|
+
else:
|
|
345
|
+
serialized_event_data = json.dumps(dict(event_data)) if event_data is not None else None
|
|
341
346
|
result = await self.request(
|
|
342
347
|
"messages.sendMessageEventAnswer",
|
|
343
348
|
{
|
|
344
349
|
"event_id": event_id,
|
|
345
350
|
"user_id": user_id,
|
|
346
351
|
"peer_id": peer_id,
|
|
347
|
-
"event_data":
|
|
352
|
+
"event_data": serialized_event_data,
|
|
348
353
|
},
|
|
349
354
|
)
|
|
350
355
|
return _integer(result) == 1
|
|
@@ -14,8 +14,11 @@ class NetworkError(VKError):
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class HTTPError(VKError):
|
|
17
|
-
|
|
17
|
+
"""HTTP failure with an optional server-supplied delay in seconds."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, status_code: int, *, retry_after: float | None = None) -> None:
|
|
18
20
|
self.status_code = status_code
|
|
21
|
+
self.retry_after = retry_after
|
|
19
22
|
super().__init__(f"VK HTTP request failed with status {status_code}")
|
|
20
23
|
|
|
21
24
|
|
|
@@ -6,8 +6,16 @@ from .attachments import (
|
|
|
6
6
|
VideoAttachment,
|
|
7
7
|
)
|
|
8
8
|
from .donut import DonutSubscriptionEvent, DonutSubscriptionEventType
|
|
9
|
+
from .event_answers import ShowSnackbar
|
|
9
10
|
from .events import Update
|
|
10
|
-
from .keyboards import
|
|
11
|
+
from .keyboards import (
|
|
12
|
+
ButtonColor,
|
|
13
|
+
ButtonType,
|
|
14
|
+
CallbackButton,
|
|
15
|
+
LocationButton,
|
|
16
|
+
OpenLinkButton,
|
|
17
|
+
TextButton,
|
|
18
|
+
)
|
|
11
19
|
from .messages import Coordinates, Geo, Keyboard, Message, MessageEvent, User
|
|
12
20
|
|
|
13
21
|
__all__ = [
|
|
@@ -22,9 +30,12 @@ __all__ = [
|
|
|
22
30
|
"DonutSubscriptionEventType",
|
|
23
31
|
"Geo",
|
|
24
32
|
"Keyboard",
|
|
33
|
+
"LocationButton",
|
|
25
34
|
"Message",
|
|
26
35
|
"MessageEvent",
|
|
36
|
+
"OpenLinkButton",
|
|
27
37
|
"PhotoAttachment",
|
|
38
|
+
"ShowSnackbar",
|
|
28
39
|
"TextButton",
|
|
29
40
|
"Update",
|
|
30
41
|
"User",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Outgoing actions for replies to VK message_event callbacks."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ShowSnackbar(BaseModel):
|
|
9
|
+
"""Show a notification containing at most 90 characters."""
|
|
10
|
+
|
|
11
|
+
model_config = ConfigDict(extra="forbid", validate_assignment=True, hide_input_in_errors=True)
|
|
12
|
+
|
|
13
|
+
type: Literal["show_snackbar"] = "show_snackbar"
|
|
14
|
+
text: str = Field(max_length=90, repr=False)
|
|
@@ -30,18 +30,18 @@ class ButtonType(StrEnum):
|
|
|
30
30
|
|
|
31
31
|
TEXT = "text"
|
|
32
32
|
CALLBACK = "callback"
|
|
33
|
+
OPEN_LINK = "open_link"
|
|
34
|
+
LOCATION = "location"
|
|
33
35
|
|
|
34
36
|
|
|
35
|
-
class
|
|
37
|
+
class _Button(BaseModel):
|
|
36
38
|
model_config = ConfigDict(
|
|
37
39
|
extra="forbid", validate_assignment=True, hide_input_in_errors=True, allow_inf_nan=False
|
|
38
40
|
)
|
|
39
41
|
|
|
40
|
-
label: str = Field(repr=False)
|
|
41
42
|
payload: dict[str, JsonValue] | SerializeAsAny[BaseModel] | str | None = Field(
|
|
42
43
|
default=None, repr=False
|
|
43
44
|
)
|
|
44
|
-
color: ButtonColor = ButtonColor.SECONDARY
|
|
45
45
|
|
|
46
46
|
@field_serializer("payload", when_used="json")
|
|
47
47
|
def serialize_payload(self, value: dict[str, JsonValue] | BaseModel | str | None) -> str | None:
|
|
@@ -63,6 +63,11 @@ class _LabeledButton(BaseModel):
|
|
|
63
63
|
return button
|
|
64
64
|
|
|
65
65
|
|
|
66
|
+
class _LabeledButton(_Button):
|
|
67
|
+
label: str = Field(repr=False)
|
|
68
|
+
color: ButtonColor = ButtonColor.SECONDARY
|
|
69
|
+
|
|
70
|
+
|
|
66
71
|
class TextButton(_LabeledButton):
|
|
67
72
|
"""Send the label and optional payload as a message, handled by MessageHandler."""
|
|
68
73
|
|
|
@@ -75,4 +80,20 @@ class CallbackButton(_LabeledButton):
|
|
|
75
80
|
type: Literal[ButtonType.CALLBACK] = ButtonType.CALLBACK
|
|
76
81
|
|
|
77
82
|
|
|
78
|
-
|
|
83
|
+
class OpenLinkButton(_Button):
|
|
84
|
+
"""Open a URL using VK's link action, without a configurable color."""
|
|
85
|
+
|
|
86
|
+
type: Literal[ButtonType.OPEN_LINK] = ButtonType.OPEN_LINK
|
|
87
|
+
label: str = Field(repr=False)
|
|
88
|
+
link: str = Field(repr=False)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class LocationButton(_Button):
|
|
92
|
+
"""Let the user choose a location and send it as a message with geo data."""
|
|
93
|
+
|
|
94
|
+
type: Literal[ButtonType.LOCATION] = ButtonType.LOCATION
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
type TypedButton = Annotated[
|
|
98
|
+
TextButton | CallbackButton | OpenLinkButton | LocationButton, Field(discriminator="type")
|
|
99
|
+
]
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import logging
|
|
5
|
+
import math
|
|
5
6
|
import re
|
|
6
7
|
from collections.abc import Mapping
|
|
7
8
|
from contextlib import suppress
|
|
9
|
+
from datetime import UTC, datetime
|
|
10
|
+
from email.utils import parsedate_to_datetime
|
|
8
11
|
from pathlib import Path
|
|
9
12
|
from types import TracebackType
|
|
10
13
|
from typing import BinaryIO, Literal, Self, cast
|
|
@@ -29,6 +32,53 @@ type Parameter = str | int | float | bool | None
|
|
|
29
32
|
type FileInput = bytes | Path | BinaryIO
|
|
30
33
|
|
|
31
34
|
|
|
35
|
+
_HTTP_DATE = re.compile(
|
|
36
|
+
r"(?:"
|
|
37
|
+
r"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), [0-9]{2} "
|
|
38
|
+
r"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{4} "
|
|
39
|
+
r"[0-9]{2}:[0-9]{2}:[0-9]{2} GMT"
|
|
40
|
+
r"|(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), "
|
|
41
|
+
r"[0-9]{2}-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-9]{2} "
|
|
42
|
+
r"[0-9]{2}:[0-9]{2}:[0-9]{2} GMT"
|
|
43
|
+
r"|(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) "
|
|
44
|
+
r"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (?:[0-9]{2}| [0-9]) "
|
|
45
|
+
r"[0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4}"
|
|
46
|
+
r")"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _parse_retry_after(value: str | None) -> float | None:
|
|
51
|
+
"""Parse RFC 9110 seconds or HTTP-date without retaining server data."""
|
|
52
|
+
if value is None:
|
|
53
|
+
return None
|
|
54
|
+
value = value.strip(" \t")
|
|
55
|
+
try:
|
|
56
|
+
if re.fullmatch(r"[0-9]+", value):
|
|
57
|
+
seconds = float(value)
|
|
58
|
+
elif _HTTP_DATE.fullmatch(value):
|
|
59
|
+
now = datetime.now(UTC)
|
|
60
|
+
deadline = parsedate_to_datetime(value)
|
|
61
|
+
if deadline.tzinfo is None:
|
|
62
|
+
# The obsolete asctime format has no zone; HTTP defines it as UTC.
|
|
63
|
+
deadline = deadline.replace(tzinfo=UTC)
|
|
64
|
+
if "-" in value:
|
|
65
|
+
# RFC 850's two-digit year is interpreted relative to the current century.
|
|
66
|
+
year = now.year // 100 * 100 + deadline.year % 100
|
|
67
|
+
if year > now.year + 50:
|
|
68
|
+
year -= 100
|
|
69
|
+
else:
|
|
70
|
+
# The email parser applies a century heuristic even to four-digit years.
|
|
71
|
+
parts = value.split()
|
|
72
|
+
year = int(parts[3] if "," in value else parts[-1])
|
|
73
|
+
deadline = deadline.replace(year=year)
|
|
74
|
+
seconds = max(0.0, (deadline - now).total_seconds())
|
|
75
|
+
else:
|
|
76
|
+
return None
|
|
77
|
+
except ValueError, TypeError, OverflowError:
|
|
78
|
+
return None
|
|
79
|
+
return seconds if math.isfinite(seconds) else None
|
|
80
|
+
|
|
81
|
+
|
|
32
82
|
def _read_upload(source: Path | BinaryIO) -> bytes:
|
|
33
83
|
"""Read in a worker; Path.read_bytes closes its own file even on failure."""
|
|
34
84
|
try:
|
|
@@ -125,7 +175,10 @@ class HTTPTransport:
|
|
|
125
175
|
except httpx.RequestError:
|
|
126
176
|
raise NetworkError("VK HTTP request could not complete") from None
|
|
127
177
|
if not response.is_success:
|
|
128
|
-
raise HTTPError(
|
|
178
|
+
raise HTTPError(
|
|
179
|
+
response.status_code,
|
|
180
|
+
retry_after=_parse_retry_after(response.headers.get("Retry-After")),
|
|
181
|
+
)
|
|
129
182
|
try:
|
|
130
183
|
return cast(JsonValue, response.json())
|
|
131
184
|
except ValueError:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_vk_bot-0.5.0 → python_vk_bot-0.6.0}/python_vk_bot/.agents/skills/telegram-to-vk/SKILL.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|