N
N
NnnNuEi2020-06-22 20:44:52
Python
NnnNuEi, 2020-06-22 20:44:52

How to write a keyboard for a bot on vk_api?

There is a chatbot code on vk_api and a regular longpoll.
It is necessary to add a keyboard to the code so that it sends it to the chat when commanded.
Full kettle.

import sys
sys.path.insert(0, "../")

import sqlite3
import random
import vk_api
import time
import datetime
import pytz
from vk_api.longpoll import VkLongPoll, VkEventType
from random import randint
from random import choice
from datetime import datetime

token = "TOKEN"
vk_session = vk_api.VkApi(token=token)

session_api = vk_session.get_api()
longpoll = VkLongPoll(vk_session)

for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        response = event.text.lower()
        if event.from_user and not (event.from_me):
            
            if response == "привет":
                vk_session.method('messages.send', {'user_id': event.user_id, 'message': "Алоэ", 'random_id': 0})

(given example code)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-22
@SoreMix

https://github.com/python273/vk_api/blob/master/ex...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question