Answer the question
In order to leave comments, you need to log in
How to make a chain for a VK bot in Python?
There is a Vkontakte bot in python. Now he can only reply to messages. It has this structure:
while True:
try:
messages = vk.method("messages.getConversations", {
"offset": 0,
"count": 20,
"filter": "unanswered"
})
if messages["count"] >= 1:
id = messages["items"][0]["last_message"]["from_id"]
body = messages["items"][0]["last_message"]["text"]
if body.lower() == "привет":
vk.method(
"messages.send", {
"peer_id": id,
"message":
"Привет!",
"random_id": random.randint(1, 2147483647)
})
elif body.lower() == "пока":
vk.method(
"messages.send", {
"peer_id": id,
"message":
"Пока",
"random_id": random.randint(1, 2147483647)
})
else:
vk.method(
"messages.send", {
"peer_id": id,
"message":
"Не понял",
"random_id": random.randint(1, 2147483647)
})
User: Fill out the form
Bot: What is your name?
User: Alexey
Bot: How old are you?
User: 18
Bot: Thanks for the answers.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question