Telegram 对 webhook Flask 应用程序更新的结构是什么?

What's the structure of Telegram's updates to webhook Flask app?

我正在尝试在带有 telepot 的 Flask 应用程序中使用 webhook 在 PythonAnywhere 中对 Telegram 机器人进行编程。因此,我想知道来自 Telegram 的更新的结构是什么,以便知道那里有什么以及它是如何调用的,并在 bot 中使用它,基本上。

我尝试将它收到的消息记录到控制台(虽然我不确定控制台应该在 PythonAnywhere 上的什么位置),并且还通过 [=17 写入同一服务器中的文件=],但这也不起作用。

#This that seemed easy didn't work either in the Flask web app
with open('log.txt', 'a') as f:
    f.write('Is this working?')

感觉好像遗漏了一些每个人都认为理所当然的简单信息,但我不知道那是什么。

确实有一点我没有注意到。发帖以防对任何人有帮助。

在 PythonAnywhere 的 Web 应用程序部分,有三个日志文件链接,您可以在其中查看在常规 Python 应用程序的控制台上会出现的各种内容。

这些链接如下所示:

username.eu.pythonanywhere.com.access.log 
username.eu.pythonanywhere.com.error.log
username.eu.pythonanywhere.com.server.log #no .eu on the american PythonAnywhere

server.log 是控制台 print 语句结束的地方。

此外,来自 Telegram 用户的常规消息在到达 Flask 时看起来像这样:

{
'update_id': 123456789, 
'message': {
    'message_id': 42, 
    'from': {
        'id': 42424242, 
        'is_bot': False, 
        'first_name': 'Joaquim', 
        'last_name': 'Pernil Rinoceronts', 
        'username': 'Juqim', 
        'language_code': 'ca'
        }, 
    'chat': {
        'id': 42424242, 
        'first_name': 'Joaquim',
        'last_name': 'Pernil Rinoceronts', 
        'username': 'Juqim', 
        'type': 'private'
        }, 
    'date': 1562247903, 
    'text': 'Patata'
    }
}

贴纸的信息 'text' 为:

'sticker': {
    'width': 512, 
    'height': 512, 
    'emoji': '', 
    'set_name': 'Ruscamems', 
    'thumb': {
        'file_id': 'AAQEABNgnrsaAAQkkp4QRiVF1rokAAIC', 
        'file_size': 4840, 
        'width': 128, 
        'height': 128
        }, 
    'file_id': 'CAADBAADBQADkvulAumgmwOAjdfYAg', 
    'file_size': 36612
}

图片有 'photo',它们来自不同尺寸的集合:

'photo':[
    {
    'file_id': 'AgADBAADVrAxG2wj8FCs-f6v7AGFUQvo-RkABFGq4cIH4_MaHXIFAAEC', 
    'file_size': 2101, 
    'width': 66, 
    'height': 90
    },
    {
    #same but bigger (different id too)
    },
    ... #I got 4 sizes.
    ]

我想我也会 post 回调,我们会有大部分有趣的东西:

{
'update_id': 123456793, 
'callback_query': {
    'id': '424242424242424242', 
    'from': { #Who pressed the Button
        'id': 42424242, 
        'is_bot': False, 
        'first_name': 'Joaquim', 
        'last_name': 'Pernil Rinoceronts', 
        'username': 'Juqim', 
        'language_code': 'ca'
        }, 
    'message': { #What message was the button in
        'message_id': 123, 
        'from': {
            'id': 434343434, 
            'is_bot': True, 
            'first_name': 'The Bot Name', 
            'username': 'name_bot'
            }, 
        'chat': {
            'id': 42424242, 
            'first_name': 'Joaquim', 
            'last_name': 'Pernil Rinoceronts', 
            'username': 'Juqim', 
            'type': 'private'
            }, 
        'date': 1562252792, 
        'text': 'A viam si funciona això', 
        'reply_markup': { #Keyboard pressed
            'inline_keyboard': [[{'text': 'Cliccami', 'callback_data': 'clicat'}]]
            }
        }, 
    'chat_instance': '1234123412341234242', 
    'data': 'clicat' #Callback data (button pressed)
    }
}