All Projects → mevellea → telegram_menu

mevellea / telegram_menu

Licence: GPL-3.0 License
A python library to generate navigation menus using Telegram Bot API

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to telegram menu

TelegramBot
A genuine Perl 6 client for Telegram Bot API
Stars: ✭ 24 (+26.32%)
Mutual labels:  telegram-bot, telegram-bot-api
Bot-Telegram-BeMEAN
💣 Bot para o Telegram do grupo do Be MEAN
Stars: ✭ 76 (+300%)
Mutual labels:  telegram-bot, telegram-bot-api
telegram-stepfunctions-bot
Serverless Telegram bot made on 4 AWS Lambda chained by AWS Step Functions. All of this written on Serverless Framework using plugins.
Stars: ✭ 26 (+36.84%)
Mutual labels:  telegram-bot, telegram-bot-api
grouphelperbot
A Telegram Bot made to help group admins, with Italian/English support.
Stars: ✭ 26 (+36.84%)
Mutual labels:  telegram-bot, telegram-bot-api
MT4-Telegram-Bot-Recon
Building a Telegram Chat with a MT4 Forex Trading Expert Advisor
Stars: ✭ 71 (+273.68%)
Mutual labels:  telegram-bot, telegram-bot-api
telegram
📚 Golang bindings for Telegram API
Stars: ✭ 15 (-21.05%)
Mutual labels:  telegram-bot, telegram-bot-api
telegram client
library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script
Stars: ✭ 38 (+100%)
Mutual labels:  telegram-bot, telegram-bot-api
File-Sharing-Bot
Telegram Bot to store Posts and Documents and it can Access by Special Links.
Stars: ✭ 867 (+4463.16%)
Mutual labels:  telegram-bot, telegram-bot-api
LilSholex
A project containing web apps and Telegram API bots.
Stars: ✭ 32 (+68.42%)
Mutual labels:  telegram-bot, telegram-bot-api
echotron
An elegant and concurrent library for Telegram bots in Go.
Stars: ✭ 95 (+400%)
Mutual labels:  telegram-bot, telegram-bot-api
fp-telegram
Wrapper classes library for telegram bots API (FreePascal)
Stars: ✭ 59 (+210.53%)
Mutual labels:  telegram-bot, telegram-bot-api
TelegramBots-Python
TelegramBots written in Python
Stars: ✭ 15 (-21.05%)
Mutual labels:  telegram-bot, telegram-bot-api
Truecaller-Smsbomber telegram bot
Telegram bot which has truecaller and smsbomber features
Stars: ✭ 30 (+57.89%)
Mutual labels:  telegram-bot, telegram-bot-api
telegram-bot-api-worker
Take an alternate route to Telegram Bot API :)
Stars: ✭ 75 (+294.74%)
Mutual labels:  telegram-bot, telegram-bot-api
tdlight-telegram-bot-api
The TDLight Telegram Bot API is an actively enhanced fork of the original Bot API, featuring experimental user support, proxies, unlimited files size, and more.
Stars: ✭ 71 (+273.68%)
Mutual labels:  telegram-bot, telegram-bot-api
Telegram.Bot.Extensions.Polling
Provides ITelegramBotClient extensions for polling updates
Stars: ✭ 35 (+84.21%)
Mutual labels:  telegram-bot, telegram-bot-api
Bybit-Auto-Trading-Bot-Ordes-placed-via-TradingView-Webhook
Python based Trading Bot that uses TradingView.com webhook JSON alerts to place orders(buy/sell/close/manage positions/TP/SL/TS etc.) on Bybit.com. Hire me directly here https://www.freelancer.com/u/Beannsofts for any assistance
Stars: ✭ 235 (+1136.84%)
Mutual labels:  telegram-bot, telegram-bot-api
tmdb bot
IMDB Telegram bot clone using TMDB to get info about movies and TV shows.
Stars: ✭ 22 (+15.79%)
Mutual labels:  telegram-bot, telegram-bot-api
tinjecttelegram delphi
LMCODE
Stars: ✭ 37 (+94.74%)
Mutual labels:  telegram-bot, telegram-bot-api
TgTranslator
Telegram bot that removes language barrier between people in groups
Stars: ✭ 32 (+68.42%)
Mutual labels:  telegram-bot, telegram-bot-api

telegram_menu package

drawing drawing drawing
A python library to generate navigation menus using Telegram Bot API.

Features:

  • Menu navigation using tree structure, unlimited depth
  • Support for sending pictures (local file or url), notifications, and polls
  • Session manager with multiple users connecting to the same bot
  • Messages can read text input from the keyboard
  • Automatic deletion of messages when configurable timer has expired
  • Integration of HTML formatting + emojis

Here is an example of navigation with menus and inlined buttons:

Demo: TelegramMenuSession

Installation

pip install telegram_menu

Getting Started

You first need to create a Telegram bot, then you can refer to the sample code in tests\test_connection.py to run a complete use-case.

A session can be started with the keyword /start from a Telegram client.

Following code block creates a Hello, World! message:

from telegram_menu import BaseMessage, TelegramMenuSession, NavigationHandler

API_KEY = "put_your_telegram_bot_api_key_here"

class StartMessage(BaseMessage):
    """Start menu, create all app sub-menus."""

    LABEL = "start"

    def __init__(self, navigation: NavigationHandler) -> None:
        """Init StartMessage class."""
        super().__init__(navigation, StartMessage.LABEL)

    def update(self) -> str:
        """Update message content."""
        return "Hello, world!"

TelegramMenuSession(API_KEY).start(StartMessage)

You can add new buttons in StartMessage, using self.add_button() method. The callback of a button can be used to update the content of the current message, or to open a new menu. For example, adding these lines in the constructor of the previous class will open a second menu:

second_menu = SecondMenuMessage(navigation)
self.add_button(label="Second menu", callback=second_menu)

Then define the second message:

class SecondMenuMessage(BaseMessage):
    """Second menu, create an inlined button."""

    LABEL = "action"

    def __init__(self, navigation: NavigationHandler) -> None:
        """Init SecondMenuMessage class."""
        super().__init__(navigation, StartMessage.LABEL, inlined=True)

        # 'run_and_notify' function executes an action and return a string as Telegram notification.
        self.add_button(label="Action", callback=self.run_and_notify)
        # 'back' button goes back to previous menu
        self.add_button_back()
        # 'home' button goes back to main menu
        self.add_button_home()

    def update(self) -> str:
        """Update message content."""
        # emoji can be inserted with a keyword enclosed with ::
        # list of emojis can be found at this link: https://www.webfx.com/tools/emoji-cheat-sheet/
        return ":warning: Second message"

    @staticmethod
    def run_and_notify() -> str:
        """Update message content."""
        return "This is a notification"

An application message can contain several inlined buttons, the behavior is similar to MenuMessage buttons. To define a message as inlined, the property inlined must be set to True.

A message can also be used to create a poll or show a picture, using property btype.

The input field can be set using the property input_field (non-inlined messages only). You can use the keyword <disable> to restore the default behaviour.

The default number of buttons per row is 2 for base keyboards, 4 for inlined keyboards, to create a new row the property new_row can be set to True when calling add_button().

from telegram_menu import MenuButton

# 'get_content' function must return the text content to display, eventually with markdown formatting
self.add_button(label="Display content", callback=self.get_content, btype=ButtonType.MESSAGE)

# 'get_picture' function must return the path of a picture to display in Telegram
self.add_button(label="Show picture", callback=self.get_picture, btype=ButtonType.PICTURE, new_row=True)

# New buttons can be added to the 'keyboard' property of the message instance too.
# Next poll message will get items to display from function 'get_playlists_arg', and run 'select_playlist' when 
# the poll button is selected, identified with emoji 'closed_book'
poll_button = MenuButton(
    label=":closed_book:", callback=self.select_playlist, btype=ButtonType.POLL, args=self.get_playlists_arg()
)
self.keyboard.append([poll_button])

Structure

Classes in package telegram_menu are stored in 2 python files:

  • navigation.py - Main interface, menu and message generation and management
  • models.py - Menu and message models, classes definition

Following class diagram describes all public interfaces:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].