Answer the question
In order to leave comments, you need to log in
How to add an inline button call in this method?
Hello!
How to display inline button instead of plain text in sender(id, 'Unknown button') ? :)
For example, popup with type show_snackbar?) Python 3.9.1
import vk_api, json, requests, datetime
from vk_api.longpoll import VkLongPoll, VkEventType
vk_session = vk_api.VkApi(token = "*************")
vk = vk_session.get_api()
longpol = VkLongPoll(vk_session)
def get_but(text, color):
return {
"action": {
"type": "text",
"payload": "{\"button\": \"" + "1" + "\"}",
"label": f"{text}"
},
"color": f"{color}"
}
keyboard = {
"one_time" : False,
"buttons" : [
[get_but('Button', 'positive')],
[get_but('Button 2', 'positive')]
]
}
keyboard = json.dumps(keyboard, ensure_ascii = False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))
def sender(id, text):
vk_session.method('messages.send', {'user_id' : id, 'message' : text, 'random_id' : 0, 'keyboard' : keyboard})
def main():
for event in longpol.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
msg = event.text
id = event.user_id
if msg in ['Button', 'Button 2']:
if msg == 'Button':
sender(id,'Button')
elif msg == 'Button 2':
sender(id,'Button 2')
else:
sender(id,'Unknown button')
while(True):
main()
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