C
C
cenox2020-12-13 20:41:43
Python
cenox, 2020-12-13 20:41:43

How to add an inline button to a VK text message?

Script on VKBOTTLE
I want to add an inline button to the bot message when it is added to the conversation
example:
5fd651ca3b8fe030476188.jpeg
How can I do this?
Hello code:

@bot.on.chat_invite()
async def invite(message: Message):
    dialog_filename = f"{dir_to_txt}{message.peer_id}.txt"
    picture_filename = f"{dir_to_pic}{message.peer_id}.txt"
    if not os.path.exists(dialog_filename):
        open(dialog_filename, "w").close()
    if not os.path.exists(picture_filename):
        open(picture_filename, "w").close()
    await message(hello_message)

Welcome message:
hello_message = """дарова я нейробред
я рандомно высираю демотиваторы, беру ваши сообщения и картинки, которые вы отправляете
отвечаю на @neurobred или дем или d или / если выдана переписка
не забудьте выдать доступ к переписке или админку, а то бот будет игнорить
"помощь" - команды бота
F.A.Q - https://vk.com/@neurobred-faq
"""

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-12-13
@SoreMix

https://github.com/timoniq/vkbottle/blob/master/ex...

# Example of sending and receiving an event after pressing the Callback button
# Documentation: https://vk.cc/aC9JG2

import os
import logging

from vkbottle import Keyboard, Callback, GroupTypes, GroupEventType
from vkbottle.bot import Bot, Message

bot = Bot(os.environ["TOKEN"])
logging.basicConfig(level=logging.INFO)

KEYBOARD = (
    Keyboard(one_time=False)
    .add(Callback("Callback-кнопка", payload={"cmd": "callback"}))
    .get_json()
)


@bot.on.private_message(text="/callback")
async def send_callback_button(message: Message):
    await message.answer("Лови!", keyboard=KEYBOARD)


@bot.on.raw_event(GroupEventType.MESSAGE_EVENT, dataclass=GroupTypes.MessageEvent)
async def handle_message_event(event: GroupTypes.MessageEvent):
    # event_data parameter accepts three object types
    # "show_snackbar" type

    await bot.api.messages.send_message_event_answer(
        event_id=event.object.event_id,
        user_id=event.object.user_id,
        peer_id=event.object.peer_id,
        event_data='{"type":"show_snackbar", "text":"Сейчас я исчезну"}',
    )


bot.run_forever()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question