I've downloaded this open-source code from GitHub which is written in Python(that I'm pretty new to it), I wanted to make my bot to have a Custom-Keyboard instead of letting users say whatever they wanted. for instance if user start the chat with my bot, they will automatically send /start and when this happens I want my bot to give them two to three options ['Option One'], [Option Two], on keyboard, when they choose one of those options, I want to have totally different options (for instance ['Plan A'], ['Plan B'],). And again when they choose one of them, they get different options on their keyboard, and so on.
class WebhookHandler(webapp2.RequestHandler):
def post(self):
urlfetch.set_default_fetch_deadline(60)
body = json.loads(self.request.body)
logging.info('request body:')
logging.info(body)
self.response.write(json.dumps(body))
update_id = body['update_id']
try:
message = body['message']
except:
message = body['edited_message']
message_id = message.get('message_id')
date = message.get('date')
text = message.get('text')
fr = message.get('from')
chat = message['chat']
chat_id = chat['id']
if not text:
logging.info('no text')
return
def reply(msg=None, img=None):
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
})).read()
else:
logging.error('no msg or img specified')
resp = None
logging.info('send response:')
logging.info(resp)
if text.startswith('/'):
if text == '/start':
reply('Bot enabled')
setEnabled(chat_id, True)
elif text == '/stop':
reply('Bot disabled')
setEnabled(chat_id, False)
else:
reply('That ain\'t been coded yet.')
As I said I'm virgin to Pyhton, and I'd be so thankful if you applied your code to the code that's above this text, instead of giving me ideas(which I wouldn't know how to use them, and get the work done!).