我使用这个框架pyTelegramBotAPI制作了聊天机器人,并在电报中为我的聊天机器人设置了web钩子。我用CherryPy来做这个。一切都很好。但是我无法处理用户发送给我的机器人的数据。我刚收到通知说用户发送了一些东西。我怎么能解决这个问题?谢谢。
发布于 2017-07-21 08:47:02
我解决了这个问题。刚刚在我的代码中找到了响应json的变量。这是我的密码:
class WebhookServer(object):
@cherrypy.expose
def index(self):
if 'content-length' in cherrypy.request.headers and \
'content-type' in cherrypy.request.headers and \
cherrypy.request.headers['content-type'] == 'application/json':
length = int(cherrypy.request.headers['content-length'])
json_string = cherrypy.request.body.read(length).decode("utf-8") <-- this one responds for json from webhook
update = telebot.types.Update.de_json(json_string)
global jsonObj
jsonObj = json.loads(json_string)
print(jsonObj)
bot.process_new_updates([update])
return ''
else:
raise cherrypy.HTTPError(403)https://stackoverflow.com/questions/44518722
复制相似问题