I'm using this line for a custom keyboard on my Telegram bot:
markup = ReplyKeyboardMarkup(keyboard=[['Time', KeyboardButton(text='NewKey')],["File", "Audio"]])
I want my bot to change custom keyboard to another when user sends NewKey
. And it will send show up a new custom keyboard but it's layout will be same as the default keyboard.
I have tried this but it is not working:
elif command == 'NewKey':
markup = ReplyKeyboardMarkup(keyboard=[['More', KeyboardButton(text='More2')],["More3", "More5"]])
Here is my full code of my bot:
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)
`