windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
265 stars 118 forks source link

inline_query cache time set? #208

Closed moshed closed 3 years ago

moshed commented 3 years ago

how can one edit the cache time of an inline query? it seems like its doable from this section of the api docs https://core.telegram.org/bots/api#answerinlinequery as well as in your thanks section you attribute MorbidDevil: for extending answerInlineQuery with options

the relevant portion of my code is below in a function node using event node (set to inline_query) to receive queries and telegram sender to send

single_result = {
        type: 'article',
        title: player_name,
        id: count,
        thumb_url: 'https://img.mlbstatic.com/mlb-photos/image/upload/w_75/v1/people/' + id + '/headshot/67/current.jpeg',
        input_message_content: {
            message_text: '[' + player_name + '](https://img.mlbstatic.com/mlb-photos/image/upload/v1/people/' + id + '/headshot/67/current.jpeg)',
            parse_mode: 'Markdown'
        },
        reply_markup: {
            inline_keyboard: [[
                {
                    text: 'Show Player Name',
                    callback_data: 'show_player_name'            
                }
            ]]
        }
    }
    all_results.push(single_result)
    if ( all_results.length == 50 ) {
        break
}
msg.payload.results = all_results

adding cache_time as instructed in the api docs doesnt do anything. Am I doing something wrong?

windkh commented 3 years ago

answerInlineQuery takes three arguments: msg.payload.inlineQueryId msg.payload.results msg.payload.options

all optional values must be passed as an object inside msg.payload.options

moshed commented 3 years ago

as it stand now I only have msg.payload.results with nothing by way of msg.payload.inlineQueryId. it seems that it gets those automatically as its been working fine and wasn't even aware of those at all. I will try to add to msg.payload.options thanks!

windkh commented 3 years ago

can I close the issue?

moshed commented 3 years ago

I couldn't get it to work. im a bit of a beginner so im sure im just misunderstanding but, I have added cache_time: 1 to my function node as below but the bot still appears to cache results

image

for (i = 0; i < player_info.length; i++ ) {
        player_name = Object.keys(player_info[i]).toString()
        id = player_info[i][player_name].id
        if ( player_name.match(player_name_search) ) {
            photo_url = 'https://img.mlbstatic.com/mlb-photos/image/upload/v1/people/' + id + '/headshot/67/current.jpeg'
            count++
            node.warn(count)
            single_result = {
                type: 'article',
                cache_time: 1,
                title: player_name,
                id: count,
                thumb_url: 'https://img.mlbstatic.com/mlb-photos/image/upload/w_75/v1/people/' + id + '/headshot/67/current.jpeg',
                input_message_content: {
                    message_text: '[' + player_name + '](https://img.mlbstatic.com/mlb-photos/image/upload/v1/people/' + id + '/headshot/67/current.jpeg)',
                    parse_mode: 'Markdown'
                },
                reply_markup: {
                    inline_keyboard: [[
                        {
                            text: 'Show Player Name',
                            callback_data: 'show_player_name'            
                        }
                    ]]
                }
            }
            all_results.push(single_result)
            if ( all_results.length == 50 ) {
                break
            }
        }
    }
}
msg.payload.results = all_results
return msg
moshed commented 3 years ago

I know you already closed this issue but I figured it out for anyone that ends up here the final payload need to look like below

msg.payload = {
    type: 'answerInlineQuery',
    inlineQueryId: msg.payload.inlineQueryId,
    options: {
        cache_time: 1
    },
    results: all_results
}
windkh commented 3 years ago

Yes that is correct.