Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How telegram bot can get file_id of uploaded file?

In telegram API documentation I see: "You can either pass a file_id as String to resend a photo that is already on the Telegram servers", but I can't find ways to get file_id of uploaded file. How can I get it?

like image 344
Arsenii Sigiller Avatar asked May 12 '16 14:05

Arsenii Sigiller


2 Answers

Its depended to your content_types ,for example:

Video:

message.video.file_id

Audio:

message.audio.file_id

Photo:

message.photo[2].file_id

For more see this link.

like image 141
Farbod Ahmadian Avatar answered Sep 28 '22 05:09

Farbod Ahmadian


This is the easiest way I've found to do it.

Upload your file to any chat and forward the message to @RawDataBot. It will return something like this:

{
    "update_id": 754677603,
    "message": {
        "message_id": 403656,
        "from": {
            "id": xxx,
            "is_bot": false,
            "first_name": "xxx",
            "username": "xxx",
            "language_code": "en"
        },
        "chat": {
            "id": xxx,
            "first_name": "xxx",
            "username": "xxx",
            "type": "private"
        },
        "date": 1589342513,
        "forward_from": {
            "id": xxx,
            "is_bot": false,
            "first_name": "xxx",
            "username": "xxx",
            "language_code": "en"
        },
        "forward_date": 1589342184,
        "document": {
            "file_name": "filename.pdf",
            "mime_type": "application/pdf",
            "file_id": "This_Is_The_Thing_You_Need",
            "file_unique_id": "notthis",
            "file_size": 123605
        }
    }
}

What you need is the string under file_id. Once you have copied that, you can simply the following code to send the message.

    context.bot.sendDocument(chat_id=update.effective_chat.id, 
        document = "Your_FILE_ID_HERE")
like image 28
Yip Jung Hon Avatar answered Sep 28 '22 05:09

Yip Jung Hon