Skip to content

[FEATURE] Auto-pagination for inline results #2071

@Bibo-Joshi

Description

@Bibo-Joshi

Is your feature request related to a problem? Please describe.

TG requires pagination for inline results using the next_offset parameter. Currently this has to be implemented manually, but the logic is always the same, so it's basically copy paste.

I think it would fit well into PTBs "more than just a wrapper" credo to provide a convenience method for that.

Describe the solution you'd like

Add a parameters pagination and current_offset to answer_inline_query to make PTB take care of that automically. it should be along the lines

offset = current_offset
max_length = 50
next_offset = None

if not offset:
    if len(results) > max_length :
        next_offset = len(results) - max_length 
        next_offset = next_offset or None
        results = results[:max_length]
elif len(results) > offset:
    results = results[offset:offset + max_length]
    if len(results) > offset + max_length:
        next_offset = offset + max_length
else:
    next_offset = ''

Describe alternatives you've considered

If we don't want to integrate this directly into answer_inline_query, we could at least add a function to utils.helpers , along the lines

def paginate_inline_results(reslts: List[InlineQueryResult], current_offset: int) -> {'results': …, 'next_offset': …}

so one could call it like

answer_inline_query(**paginate_inline_results(results, offset), …)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions