Advertisement
Guest User

telepot keyboard example (source code)

a guest
Jun 30th, 2016
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import time
  3.  
  4. import telepot
  5.  
  6. def handler(msg):
  7.     chat_id = msg['chat']['id']
  8.     chat_message = msg['text']
  9.  
  10.     buttons = {'keyboard': [['Option #1', 'Option #2'], ['Option #3', 'Option #4']]}
  11.     bot.sendMessage(chat_id, 'Main options', reply_markup=buttons)
  12.  
  13.     # Ex: Option #1 > You selected Option #1
  14.     bot.sendMessage(chat_id, 'Main selected: %s' %chat_message)
  15.  
  16.     if chat_message == 'Option #1':
  17.         sub_buttons = {'keyboard': [['Sub option #1_1', 'Sub option #1_2'], ['Sub option #1_3', 'Sub option #1_4']]}
  18.         bot.sendMessage(chat_id, 'Sub options', reply_markup=sub_buttons)
  19.  
  20.         if chat_message == 'Sub option #1_1':
  21.             bot.sendMessage(chat_id, 'Sub selected %s' %chat_message)
  22.         # ...
  23.  
  24.     # ...
  25.  
  26. bot = telepot.Bot('API KEY')
  27. bot.message_loop(handler)
  28.  
  29. print('[+] started...')
  30.  
  31. while 1:
  32.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement