События¶
GroupLongPoll¶
GroupLongPoll
¶
GroupLongPoll(
api,
/,
*,
group_id=None,
wait=25,
new_event_callbacks=None,
requests_session=None,
json_parser=None,
)
Bases: BaseLongPoll
Source code in vkflow\longpoll.py
UserLongPoll¶
UserLongPoll
¶
UserLongPoll(
api,
/,
*,
version=3,
wait=15,
mode=234,
new_event_callbacks=None,
requests_session=None,
json_parser=None,
)
Bases: BaseLongPoll
Source code in vkflow\longpoll.py
GroupEvent¶
GroupEvent
¶
UserEvent¶
UserEvent
¶
WebhookApp¶
WebhookApp
dataclass
¶
WebhookApp(
prefixes=list(),
name="VK Flow App",
filter=None,
commands=list(),
event_handlers=(lambda: defaultdict(list))(),
message_handlers=list(),
startup_handlers=list(),
shutdown_handlers=list(),
button_onclick_handlers=dict(),
button_callback_handlers=dict(),
inviting_handlers=list(),
fsm_storage=None,
fsm_strategy="user_chat",
packages=list(),
debug=False,
strict_mode=False,
description="Чат-бот для ВКонтакте, написанный на Python с использованием VK Flow",
addons=list(),
payload_factory=None,
experimental=dict(),
secret_key=None,
confirmation_key=None,
path="/webhook",
)
Bases: App
App subclass that uses VK Callback API (webhooks) instead of LongPoll.
All features of :class:App are fully supported -commands, cogs, FSM,
middleware, event/message handlers, callback buttons, ViewStore,
startup/shutdown hooks, on_ready, wait_for,
conquer_new_message, addons, and extensions.
Single bot::
app = WebhookApp(
prefixes=["/"],
secret_key="abc",
confirmation_key="xyz",
)
@app.command("ping")
async def ping(ctx):
await ctx.reply("pong")
app.run("token", host="0.0.0.0", port=8080)
Multi bot::
app = WebhookApp(prefixes=["/"])
app.run(
WebhookBotEntry("token1", secret_key="s1", confirmation_key="c1"),
WebhookBotEntry("token2", secret_key="s2", confirmation_key="c2"),
host="0.0.0.0", port=8080,
)
Mixed (plain tokens inherit app-level keys)::
app = WebhookApp(
prefixes=["/"],
secret_key="shared_secret",
confirmation_key="shared_conf",
)
app.run("token1", "token2", host="0.0.0.0", port=8080)
Manual integration with an existing aiohttp app::
async def main():
await app.prepare("token")
aiohttp_app = app.create_aiohttp_app()
aiohttp.web.run_app(aiohttp_app)
run
¶
Synchronous entry-point (mirrors App.run).
Source code in vkflow\webhook.py
start
async
¶
Async: initialise bots, start aiohttp server, wait for signal.
Source code in vkflow\webhook.py
prepare
async
¶
Initialise bots without starting the HTTP server.
Useful for manual integration with an existing aiohttp application
(call :meth:create_aiohttp_app afterwards).
Source code in vkflow\webhook.py
create_aiohttp_app
¶
Return an aiohttp.web.Application with the webhook route registered.
Source code in vkflow\webhook.py
close
async
¶
Graceful shutdown: stop factories, cleanup runner, call shutdown handlers, close sessions.
Source code in vkflow\webhook.py
WebhookEventFactory¶
WebhookEventFactory
¶
Bases: BaseEventFactory
Event factory for webhook (Callback API) transport.
Does not poll a long-poll server. Events are pushed externally
via :meth:push_event, which feeds any active :meth:listen
generators (used by conquer_new_message, run_state_handling, etc.).