I'm trying to send a regular keyboard on telegram and it is failing. I'm using this code:
def reply(msg=None):
""" """
if msg:
import urllib2, urllib, json
https_request = "https://api.telegram.org/bot" + token + "/"
a = urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
'reply_markup': '{"keyboard":[["Yes","No"],["Maybe"],["1","2","3"]],"one_time_keyboard":true}',
})
resp = urllib2.urlopen(https_request + 'sendMessage', a).read()
The error I get is:
>>> reply("hi")
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "<module2>", line 17, in reply
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 435, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 473, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 407, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request
But when I change it to inline_keyboard it works perfectly!
def reply(msg=None):
if msg:
import urllib2, urllib, json
https_request = "https://api.telegram.org/bot" + token + "/"
a = urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
'reply_markup': '{"inline_keyboard": [[{"text": "yo", callback_data": "yo"}, {"text": "yo", "callback_data": "yo"}]]}'
})
resp = urllib2.urlopen(https_request + 'sendMessage', a).read()
I also tried the solution here (which is pretty much the same).
Can you please advise what could be the problem here?