https://github.com/Fsoky/vktools
Project description
vktools
Инструменты для удобной работы с vk_api
Все нужные импорты
Keyboard
from vktools import Keyboard, ButtonColor, Text, OpenLink, Location # Еще имеются VkApps, VkPay
keyboard = Keyboard(
[
[
Text("RED", ButtonColor.NEGATIVE),
Text("GREEN", ButtonColor.POSITIVE),
Text("BLUE", ButtonColor.PRIMARY),
Text("WHITE")
],
[
OpenLink("YouTube", "https://youtube.com/c/Фсоки"),
Location()
]
]
)
vk.messages.send(user_id=event.user_id, message="Test Keyboard", keyboard=keyboard.add_keyboard())
Карусели (template)
from vktools import Keyboard, ButtonColor, Carousel, Element
carousel = Carousel(
[
Element(
"Title 1",
"Description 1",
"-203980592_457239030", # photo_id
"https://vk.com/fsoky", # redirect url, if user click on element
[Text("Button 1", ButtonColor.POSITIVE)]
),
Element(
"Title 2",
"Description 2",
"-203980592_457239030", # photo_id
"https://vk.com/fsoky", # redirect url, if user click on element
[Text("Button 2", ButtonColor.PRIMARY)]
)
]
)
vk.messages.send(user_id=event.user_id, message="Test Keyboard", template=carousel.add_carousel())
Example code
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from vktools import Keyboard, ButtonColor, Text, OpenLink, Location, Carousel, Element
vk = vk_api.VkApi(token="token")
def send_message(user_id, message, keyboard=None, carousel=None):
values = {
"user_id": user_id,
"message": message,
"random_id": 0
}
if keyboard is not None:
values["keyboard"] = keyboard.add_keyboard()
if carousel is not None:
values["template"] = carousel.add_carousel()
vk.method("messages.send", values)
for event in VkLongPoll(vk).listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
text = event.text.lower()
user_id = event.user_id
if text == "test":
keyboard = Keyboard(
[
[
Text("RED", ButtonColor.NEGATIVE),
Text("GREEN", ButtonColor.POSITIVE),
Text("BLUE", ButtonColor.PRIMARY),
Text("WHITE")
],
[
OpenLink("YouTube", "https://youtube.com/c/Фсоки"),
Location()
]
]
)
send_message(user_id, "VkTools Keyboard by Fsoky ~", keyboard)
elif text == "test carousel":
carousel = Carousel(
[
Element(
"Title 1",
"Description 1",
"-203980592_457239030", # photo_id
"https://vk.com/fsoky", # redirect url, if user click on element
[Text("Button 1", ButtonColor.POSITIVE)]
),
Element(
"Title 2",
"Description 2",
"-203980592_457239030", # photo_id
"https://vk.com/fsoky", # redirect url, if user click on element
[Text("Button 2", ButtonColor.PRIMARY)]
)
]
)
send_message(user_id, "VkTools Carousel by Fsoky ~", carousel=carousel)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
vktools-1.0.3.tar.gz
(581.9 kB
view hashes)
Built Distribution
vktools-1.0.3-py3-none-any.whl
(586.0 kB
view hashes)