python-vk-bot 0.2.0__tar.gz → 0.3.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.2.0 → python_vk_bot-0.3.0}/CHANGELOG.md +8 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/PKG-INFO +1 -1
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/examples/README.md +4 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/pyproject.toml +1 -1
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/__init__.py +8 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/models/__init__.py +5 -0
- python_vk_bot-0.3.0/python_vk_bot/models/keyboards.py +78 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/models/messages.py +2 -1
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/.gitignore +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/LICENSE +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/README.md +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/docs/decisions/README.md +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/.agents/skills/telegram-to-vk/SKILL.md +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/.agents/skills/telegram-to-vk/references/migration-mapping.md +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/_config.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/application.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/bot.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/callback.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/context.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/errors.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/filters.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/handlers.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/long_poll.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/models/api.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/models/attachments.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/models/base.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/models/events.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/py.typed +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/settings.py +0 -0
- {python_vk_bot-0.2.0 → python_vk_bot-0.3.0}/python_vk_bot/transport.py +0 -0
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes will be documented here, following Keep a Changelog.
|
|
4
4
|
|
|
5
|
+
## 0.3.0 - 2026-11-02
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Pydantic `TextButton` and `CallbackButton` models with automatic dictionary/model
|
|
10
|
+
payload serialization and `ButtonColor` / `ButtonType` enums. Keyboards also accept
|
|
11
|
+
raw VK button dictionaries. See the [keyboard API](docs/development/keyboards.md).
|
|
12
|
+
|
|
5
13
|
## 0.2.0 - 2026-11-01
|
|
6
14
|
|
|
7
15
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-vk-bot
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.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
|
|
@@ -37,6 +37,10 @@ smallest example of `Application`, `BotSettings`, `MessageHandler` and `filters.
|
|
|
37
37
|
|
|
38
38
|
## Ordinary and inline keyboards
|
|
39
39
|
|
|
40
|
+
The example constructs Pydantic `TextButton` and `CallbackButton` objects and uses
|
|
41
|
+
`ButtonColor` enum members. Dictionary payloads are JSON encoded by the library.
|
|
42
|
+
See the [keyboard API](../docs/development/keyboards.md) for model payloads and serialization.
|
|
43
|
+
|
|
40
44
|
```bash
|
|
41
45
|
uv run python examples/keyboards.py
|
|
42
46
|
```
|
|
@@ -10,11 +10,15 @@ from .long_poll import LongPoll
|
|
|
10
10
|
from .models import (
|
|
11
11
|
Attachment,
|
|
12
12
|
AudioMessageAttachment,
|
|
13
|
+
ButtonColor,
|
|
14
|
+
ButtonType,
|
|
15
|
+
CallbackButton,
|
|
13
16
|
DocumentAttachment,
|
|
14
17
|
Keyboard,
|
|
15
18
|
Message,
|
|
16
19
|
MessageEvent,
|
|
17
20
|
PhotoAttachment,
|
|
21
|
+
TextButton,
|
|
18
22
|
Update,
|
|
19
23
|
User,
|
|
20
24
|
VideoAttachment,
|
|
@@ -27,7 +31,10 @@ __all__ = [
|
|
|
27
31
|
"AudioMessageAttachment",
|
|
28
32
|
"Bot",
|
|
29
33
|
"BotSettings",
|
|
34
|
+
"ButtonColor",
|
|
35
|
+
"ButtonType",
|
|
30
36
|
"Callback",
|
|
37
|
+
"CallbackButton",
|
|
31
38
|
"CommandHandler",
|
|
32
39
|
"Context",
|
|
33
40
|
"DocumentAttachment",
|
|
@@ -39,6 +46,7 @@ __all__ = [
|
|
|
39
46
|
"MessageEventHandler",
|
|
40
47
|
"MessageHandler",
|
|
41
48
|
"PhotoAttachment",
|
|
49
|
+
"TextButton",
|
|
42
50
|
"Update",
|
|
43
51
|
"User",
|
|
44
52
|
"VideoAttachment",
|
|
@@ -6,11 +6,15 @@ from .attachments import (
|
|
|
6
6
|
VideoAttachment,
|
|
7
7
|
)
|
|
8
8
|
from .events import Update
|
|
9
|
+
from .keyboards import ButtonColor, ButtonType, CallbackButton, TextButton
|
|
9
10
|
from .messages import Coordinates, Geo, Keyboard, Message, MessageEvent, User
|
|
10
11
|
|
|
11
12
|
__all__ = [
|
|
12
13
|
"Attachment",
|
|
13
14
|
"AudioMessageAttachment",
|
|
15
|
+
"ButtonColor",
|
|
16
|
+
"ButtonType",
|
|
17
|
+
"CallbackButton",
|
|
14
18
|
"Coordinates",
|
|
15
19
|
"DocumentAttachment",
|
|
16
20
|
"Geo",
|
|
@@ -18,6 +22,7 @@ __all__ = [
|
|
|
18
22
|
"Message",
|
|
19
23
|
"MessageEvent",
|
|
20
24
|
"PhotoAttachment",
|
|
25
|
+
"TextButton",
|
|
21
26
|
"Update",
|
|
22
27
|
"User",
|
|
23
28
|
"VideoAttachment",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Convenient outgoing button models with VK JSON serialization."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from enum import StrEnum
|
|
5
|
+
from typing import Annotated, Literal
|
|
6
|
+
|
|
7
|
+
from pydantic import (
|
|
8
|
+
BaseModel,
|
|
9
|
+
ConfigDict,
|
|
10
|
+
Field,
|
|
11
|
+
JsonValue,
|
|
12
|
+
SerializeAsAny,
|
|
13
|
+
SerializerFunctionWrapHandler,
|
|
14
|
+
field_serializer,
|
|
15
|
+
model_serializer,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ButtonColor(StrEnum):
|
|
20
|
+
"""Colors documented by the VK keyboard guide."""
|
|
21
|
+
|
|
22
|
+
PRIMARY = "primary"
|
|
23
|
+
SECONDARY = "secondary"
|
|
24
|
+
POSITIVE = "positive"
|
|
25
|
+
NEGATIVE = "negative"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ButtonType(StrEnum):
|
|
29
|
+
"""Action types supported by the typed button models."""
|
|
30
|
+
|
|
31
|
+
TEXT = "text"
|
|
32
|
+
CALLBACK = "callback"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class _LabeledButton(BaseModel):
|
|
36
|
+
model_config = ConfigDict(
|
|
37
|
+
extra="forbid", validate_assignment=True, hide_input_in_errors=True, allow_inf_nan=False
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
label: str = Field(repr=False)
|
|
41
|
+
payload: dict[str, JsonValue] | SerializeAsAny[BaseModel] | str | None = Field(
|
|
42
|
+
default=None, repr=False
|
|
43
|
+
)
|
|
44
|
+
color: ButtonColor = ButtonColor.SECONDARY
|
|
45
|
+
|
|
46
|
+
@field_serializer("payload", when_used="json")
|
|
47
|
+
def serialize_payload(self, value: dict[str, JsonValue] | BaseModel | str | None) -> str | None:
|
|
48
|
+
if isinstance(value, BaseModel):
|
|
49
|
+
return value.model_dump_json(by_alias=True)
|
|
50
|
+
if isinstance(value, dict):
|
|
51
|
+
return json.dumps(value, ensure_ascii=False, allow_nan=False, separators=(",", ":"))
|
|
52
|
+
return value
|
|
53
|
+
|
|
54
|
+
@model_serializer(mode="wrap", when_used="json")
|
|
55
|
+
def serialize_button(self, handler: SerializerFunctionWrapHandler) -> dict[str, JsonValue]:
|
|
56
|
+
action: dict[str, JsonValue] = handler(self)
|
|
57
|
+
button: dict[str, JsonValue] = {"action": action}
|
|
58
|
+
if "color" in action:
|
|
59
|
+
button["color"] = action.pop("color")
|
|
60
|
+
# Absence of payload is represented by an omitted action field, never JSON null.
|
|
61
|
+
if action.get("payload") is None:
|
|
62
|
+
action.pop("payload", None)
|
|
63
|
+
return button
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class TextButton(_LabeledButton):
|
|
67
|
+
"""Send the label and optional payload as a message, handled by MessageHandler."""
|
|
68
|
+
|
|
69
|
+
type: Literal[ButtonType.TEXT] = ButtonType.TEXT
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class CallbackButton(_LabeledButton):
|
|
73
|
+
"""Emit a message_event, handled by MessageEventHandler."""
|
|
74
|
+
|
|
75
|
+
type: Literal[ButtonType.CALLBACK] = ButtonType.CALLBACK
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
type TypedButton = Annotated[TextButton | CallbackButton, Field(discriminator="type")]
|
|
@@ -4,6 +4,7 @@ from pydantic import Field, JsonValue
|
|
|
4
4
|
|
|
5
5
|
from .attachments import Attachment, parse_attachment
|
|
6
6
|
from .base import VKModel
|
|
7
|
+
from .keyboards import TypedButton
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
class Coordinates(VKModel):
|
|
@@ -53,7 +54,7 @@ class User(VKModel):
|
|
|
53
54
|
|
|
54
55
|
|
|
55
56
|
class Keyboard(VKModel):
|
|
56
|
-
buttons: list[list[dict[str, JsonValue]]]
|
|
57
|
+
buttons: list[list[TypedButton | dict[str, JsonValue]]]
|
|
57
58
|
one_time: bool = False
|
|
58
59
|
inline: bool = False
|
|
59
60
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_vk_bot-0.2.0 → python_vk_bot-0.3.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
|