windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
269 stars 119 forks source link

How Get File Info #364

Closed Alefair closed 5 months ago

Alefair commented 9 months ago

Hi, I want to get the full url to the picture from the message. My body is from a bot:

msg.payload = {
    "chatId":xxx,
    "messageId":xxx,
    "type":"photo",
    "content":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADeQADNAQ",
    "date":1708614987,
    "blob":true,
    "photos":[
        {
            "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADcwADNAQ",
            "file_unique_id":"AQADSdcxG2gCuEp4",
            "file_size":1248,
            "width":90,
            "height":51
        },
        {
            "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADbQADNAQ",
            "file_unique_id":"AQADSdcxG2gCuEpy",
            "file_size":13845,
            "width":320,"height":180
        },
        {
            "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADeAADNAQ",
            "file_unique_id":"AQADSdcxG2gCuEp9",
            "file_size":48285,
            "width":800,
            "height":450
        },
        {
            "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADeQADNAQ",
            "file_unique_id":"AQADSdcxG2gCuEp-",
            "file_size":59072,
            "width":1024,
            "height":576
        }
    ]
}

I thought I'd get it with the help of:

if(msg.payload.type === 'photo'){

    // manually download the first photo using the fileId.
    msg.payload = {
        getfile: {
            fileId : msg.payload.photos[msg.payload.photos.length - 1].file_id,
        },
    }

    return msg;
}

but I get a mistake: TypeError: Cannot read property 'fileId' of undefined

windkh commented 9 months ago

If you want to access the raw message then you should find it here msg.payload.originalMessage

Alefair commented 9 months ago

If you want to access the raw message then you should find it here msg.payload.originalMessage

I want the photo that was put in the message.

image

is

msg.payload = { "chatId":xxx, "messageId":xxx, "type":"photo", "content":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADeQADNAQ", "date":1708614987, "blob":true, "photos":[ { "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADcwADNAQ", "file_unique_id":"AQADSdcxG2gCuEp4", "file_size":1248, "width":90, "height":51 }, { "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADbQADNAQ", "file_unique_id":"AQADSdcxG2gCuEpy", "file_size":13845, "width":320,"height":180 }, { "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADeAADNAQ", "file_unique_id":"AQADSdcxG2gCuEp9", "file_size":48285, "width":800, "height":450 }, { "file_id":"AgACAgIAAxkBAAIJT2XXZUvoKcOmp6oMb09-mV6-lcvbAAJJ1zEbaAK4StFdeOx3g7IQAQADAgADeQADNAQ", "file_unique_id":"AQADSdcxG2gCuEp-", "file_size":59072, "width":1024, "height":576 } ] }

i want get this file as url or to buffer

Original message as image

image

image

windkh commented 9 months ago

There is a getfile example in the examples folder. Did you have a look at that one yet?

Alefair commented 9 months ago

There is a getfile example in the examples folder. Did you have a look at that one yet?

Yes, I showed the example above, just an example of getfile, and I described everything that I get in response

windkh commented 5 months ago

@Alefair see https://github.com/windkh/node-red-contrib-telegrambot/blob/master/examples/downloadfile.json then check msg.payload.weblink