简体   繁体   English

如何根据 Telegram 上的文件 ID 发送文件

[英]How to send file according to file ID on Telegram

How can I send (not forward) file existing on Telegram to user according to file ID?如何根据文件 ID 向用户发送(不转发)Telegram 上存在的文件?

I know all files uploaded on Telegram have unique ID.我知道在 Telegram 上上传的所有文件都有唯一的 ID。 How can I extract that ID and what's the function or method to send that file by extracted ID?如何提取该 ID,以及通过提取的 ID 发送该文件的功能或方法是什么? (I use Python Telepot library) (我使用 Python Telepot 库)

import telepot
from telepot.loop import MessageLoop
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg,'chat')
if content_type == 'text':
    user_msg_text = msg['text']
    if user_msg_text == '/start':
        bot.sendDocument(chat_id=chat_id, )
TOKEN = "479761462:AAE8yqX2RGCbynHJgShIdJzCZWYF9SSBUkU"
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
                  'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')

what I should enter on second argument of sendDocument() method?我应该在 sendDocument() 方法的第二个参数中输入什么?

import telepot
from telepot.loop import MessageLoop
def on_chat_message(msg):
   content_type, chat_type, chat_id = telepot.glance(msg,'chat')
     if content_type == 'document':
        file_id = msg['document']['file_id']
        print(file_id)
TOKEN = "479761462:AAE8yqX2RGCbynHJgShIdJzCZWYF9SSBUkU"
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
              'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')

You should first extract file_id from document file.when you run your bot,send a document to bot,you can print it and copy it,and past it to this command: bot.sendDocument(chat_id=chat_id,file_id) You should place the phrase you copied instead of file_id.您应该首先从文档文件中提取 file_id。当您运行机器人时,将文档发送到机器人,您可以打印并复制它,并将其粘贴到此命令中: bot.sendDocument(chat_id=chat_id,file_id) 您应该将您复制的短语而不是 file_id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM