Изменить пользовательскую клавиатуру, отправив команды на телепота Telegram Bot - PullRequest
0 голосов
/ 04 сентября 2018

Я использую эту строку для пользовательской клавиатуры на моем боте Telegram:

markup = ReplyKeyboardMarkup(keyboard=[['Time', KeyboardButton(text='NewKey')],["File", "Audio"]])

Я хочу, чтобы мой бот сменил пользовательскую клавиатуру на другую, когда пользователь отправляет NewKey. И он покажет новую пользовательскую клавиатуру, но ее расположение будет таким же, как и у клавиатуры по умолчанию. Я пробовал это, но это не работает: elif command == 'NewKey': markup = ReplyKeyboardMarkup(keyboard=[['More', KeyboardButton(text='More2')],["More3", "More5"]])

Вот мой полный код моего бота:

import time, datetime
import telepot
from telepot.loop import MessageLoop
from telepot.namedtuple import ReplyKeyboardMarkup, KeyboardButton

now = datetime.datetime.now()

def action(msg):
    chat_id = msg['`chat']['id']
    command = msg['text']

    print('Received: %s' % command)

    markup = ReplyKeyboardMarkup(keyboard=[['Time', KeyboardButton(text='NewKey')],["File", "Audio"]])
    if command == '/start':
        telegram_bot.sendMessage (chat_id, str("Hi! Which one do you want? choose from the below keyboard buttons."), reply_markup=markup)
        telegram_bot.sendMessage(chat_id, str(now.hour)+str(":")+str(now.minute))
    elif command == 'NewKey':
   markup = ReplyKeyboardMarkup(keyboard=[['More', KeyboardButton(text='More2')],["More3", "More5"]]))
    elif command == 'Time':
        telegram_bot.sendMessage(chat_id, str(now.hour)+str(":")+str(now.minute))
    elif command == '/file':
        telegram_bot.sendDocument(chat_id, document=open('/home/pi/Aisha.py'))
    elif command == '/audio':
        telegram_bot.sendAudio(chat_id, audio=open('/home/pi/test.mp3'))

telegram_bot = telepot.Bot('MY-BOT-TOKEN')
print((telegram_bot.getMe()))

MessageLoop(telegram_bot, action).run_as_thread()
print('Up and Running....')

while 1:
    time.sleep(10)

`

...