1

このフレームワークpyTelegramBotAPIを使用してchatbotを作成し、電文のchatbotにwebhookを設定しました。私はCherryPyを使っています。すべてうまく動作します。しかし、ユーザーがボットに送るデータは扱えません。私はちょうどユーザーが何かを送るという通知を受け取ります。どうすればこの問題を解決できますか?ありがとう。pythonのWebhookデータを電文で処理する3

答えて

0

私はこの問題を解決しました。ちょうど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) 
関連する問題