如何使用python电报机器人将pdf文件发送回用户?

如何使用python电报机器人将pdf文件发送回用户?,python,pdf,telegram-bot,python-telegram-bot,sendfile,Python,Pdf,Telegram Bot,Python Telegram Bot,Sendfile,我尝试使用update.sendDocumentchat\u id=update.message.chat\u id,document=opensomething.pdf,“b”,但它没有返回pdf文件。有什么帮助吗?作为参考,这里有一个完整的工作示例,对我很有用。 如果仍然不起作用,请确保您发送的pdf文档小于20MB 依照 作为参考,这里有一个完整的工作示例,对我来说很有用。 如果仍然不起作用,请确保您发送的pdf文档小于20MB 依照 要将文档发送给用户,您必须具有该文档的文件id 假设用

我尝试使用update.sendDocumentchat\u id=update.message.chat\u id,document=opensomething.pdf,“b”,但它没有返回pdf文件。有什么帮助吗?

作为参考,这里有一个完整的工作示例,对我很有用。 如果仍然不起作用,请确保您发送的pdf文档小于20MB 依照


作为参考,这里有一个完整的工作示例,对我来说很有用。 如果仍然不起作用,请确保您发送的pdf文档小于20MB 依照


要将文档发送给用户,您必须具有该文档的文件id

假设用户将文档发送到bot,而您希望将其发送回用户,这是我的解决方案:

def file_handler (update, context):
    chat_id = update.message.chat_id
    ## retrieve file_id from document sent by user
    fileID = update.message['document']['file_id']
    context.bot.sendDocument(chat_id = chat_id,
                             caption = 'This is the file that you've sent to bot',
                             document = fileID)
在def main上,您必须添加:

updater.dispatcher.add_handler(MessageHandler(Filters.document, file_handler))

通过这最后一行,您的机器人将了解,当用户向其发送文档时,并且仅发送文档时,它将调用def file_handler。

要向用户发送文档,您必须具有该文档的文件id

假设用户将文档发送到bot,而您希望将其发送回用户,这是我的解决方案:

def file_handler (update, context):
    chat_id = update.message.chat_id
    ## retrieve file_id from document sent by user
    fileID = update.message['document']['file_id']
    context.bot.sendDocument(chat_id = chat_id,
                             caption = 'This is the file that you've sent to bot',
                             document = fileID)
在def main上,您必须添加:

updater.dispatcher.add_handler(MessageHandler(Filters.document, file_handler))

通过这最后一行,您的机器人将了解,当用户发送一个文档,并且仅发送一个文档时,它将调用def file_handler。

OP没有问如何处理文件表单客户端,他问如何将文件发送到客户端。OP没有问如何处理文件表单客户端,他问如何将文件发送到客户端。该死。。。谢谢你,伙计。我想知道作者为什么没有给你们一个正确的答案。很有魅力。该死的。。。谢谢你,伙计。我想知道作者为什么没有给你们一个正确的答案。工作起来很有魅力。