Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import vk_api
- from vk_api.longpoll import VkLongPoll, VkEventType
- from config import token
- from vktools import Keyboard, KeyboardButton, Carousel, CarouselButton
- session = vk_api.VkApi(token=token)
- def send_message(user_id, message, keyboard=None, carousel=None):
- post = {
- "user_id": user_id,
- "message": message,
- "random_id": 0
- }
- if keyboard != None:
- post["keyboard"] = keyboard.add_keyboard()
- if carousel != None:
- post["template"] = carousel.add_carousel()
- session.method("messages.send", post)
- for event in VkLongPoll(session).listen():
- if event.type == VkEventType.MESSAGE_NEW and event.to_me:
- text = event.text.lower()
- user_id = event.user_id
- if text == "start":
- keyboard = Keyboard(
- [
- [
- KeyboardButton().text("RED", "negative"),
- KeyboardButton().text("GREEN", "positive"),
- KeyboardButton().text("BLUE", "primary"),
- KeyboardButton().text("WHITE")
- ],
- [
- KeyboardButton().openlink("YouTube", "https://youtube.com/c/Фсоки")
- ],
- [
- KeyboardButton().location()
- ]
- ]
- )
- send_message(user_id, "New Keyboard", keyboard)
- elif text == "test":
- carousel = Carousel(
- [
- CarouselButton().openlink(
- [
- CarouselButton().element(
- title="Title 1",
- description="Description 1",
- photo_id="-203980592_457239030",
- link="https://vk.com/fsoky",
- buttons=[KeyboardButton().text("Test button", "primary")]
- ),
- CarouselButton().element(
- title="Title 2",
- description="Description 2",
- photo_id="-203980592_457239030",
- link="https://vk.com/fsoky",
- buttons=[KeyboardButton().text("Test button 2", "negative")]
- ),
- ]
- )
- ]
- )
- send_message(user_id, "Carousel", carousel=carousel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement