Chat actions
chat_actions.py
1import os
2
3from pyvkbot import Bot
4
5token = os.getenv("TOKEN")
6group_id = os.getenv("GROUP_ID")
7
8bot = Bot(token=token, group_id=group_id)
9
10
11def get_user(bot: Bot, user_id: int) -> str | dict[str, str]:
12 return bot.send_api_method("users.get", {"user_id": user_id})
13
14
15@bot.action("chat_invite_user")
16def hello(bot: Bot, message: dict[str, str]):
17 new_user = get_user(bot, message["action"]["member_id"])[0]
18 bot.send_message(message["peer_id"], text=f"hello {new_user['first_name']}")
19
20
21@bot.attachment("audio_message")
22def delete_audio_message(bot: Bot, message: dict["str", "str"]):
23 bot.delete_message(message["peer_id"], cmids=[message["conversation_message_id"]])
24 bot.send_message(message["peer_id"], text="Audio message are not allowed")
25
26
27bot.start_polling()