Giter Site home page Giter Site logo

python-telegram-bot-pagination's Introduction

python-telegram-bot-pagination

Download Month Build Status

Provide easy way for create number pagination with inline keyboard for telegram bot on python.

Example with pyTelegramBotAPI

Example with python-telegram-bot

Installation

pip install python-telegram-bot-pagination

Usage

    from telegram_bot_pagination import InlineKeyboardPaginator

    paginator = InlineKeyboardPaginator(
        page_count,
        current_page=page,
        data_pattern='page#{page}'
    )

    bot.send_message(
        chat_id,
        text,
        reply_markup=paginator.markup,
    )

Init arguments:

  • page_count - integer, total 1-based pages count.
  • current_page - integer, 1-based current page. Default 1
  • data_pattern - string with python style formatting named argument 'page'. Used for generate callback data for button. Default '{page}'

Properties:

Button render controlling

For edit button render, use paginator object properties:

  • first_page_label
  • previous_page_label
  • current_page_label
  • next_page_label
  • last_page_label

All of them can by python style formatting string with one arg, or simple string.

For example:

class MyPaginator(InlineKeyboardPaginator):
    first_page_label = '<<'
    previous_page_label = '<'
    current_page_label = '-{}-'
    next_page_label = '>'
    last_page_label = '>>'

paginator = MyPaginator(page_count)

Result:

Adding extra button

For adding button line before and after pagination use methods:

  • add_before(*args)
  • add_after(*args)

Each argument mast provide property 'text' and 'callback_data'

For example:

paginator.add_before(
    InlineKeyboardButton('Like', callback_data='like#{}'.format(page)),
    InlineKeyboardButton('Dislike', callback_data='dislike#{}'.format(page))
)
paginator.add_after(InlineKeyboardButton('Go back', callback_data='back'))

Result:

python-telegram-bot-pagination's People

Contributors

ksinn avatar nanakotakashi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.