californiamountainsnake / longmantelegrambot-inlinemenu
This package is abandoned and no longer maintained.
No replacement package was suggested.
The inline menu for the longman/telegram-bot library!
1.3.0
2021-03-15 14:29 UTC
Requires
- php: ^7.2
- ext-json: *
- ext-mbstring: *
- californiamountainsnake/longmantelegrambot-utils: ^1.1.4
- longman/telegram-bot: ~0.55
- myclabs/php-enum: ^1.5
Requires (Dev)
- ext-dom: *
- phpunit/phpunit: ^7.0
README
It's the inline menu for the longman/telegram-bot library!
Functionality:
- Inline-menu with sub-menus.
- Call a bot command by inline button.
- Toast message!
Install:
Require this package with Composer
Install this package through Composer.
Edit your project's composer.json
file to require californiamountainsnake/longmantelegrambot-inlinemenu
:
{ "name": "yourproject/yourproject", "type": "project", "require": { "php": "^7.3.1", "californiamountainsnake/longmantelegrambot-inlinemenu": "*" } }
and run composer update
or
run this command in your command line:
composer require californiamountainsnake/longmantelegrambot-inlinemenu
Usage:
- Extend your Telegram class from InlineMenuTelegram (or include the InlineMenuTelegramTrait into your existed Telegram class):
<?php // Create your own Telegram class: class MyTelegram extends InlineMenuTelegram { } // somewhere in the webhook.php: $telegram = new MyTelegram($bot_api_key, $bot_username);
- Create your Menu object:
<?php $menu = new Menu('Top root menu', 'root', [ [ InlineButton::startCommand('Help!', 'help'), InlineButton::url('It\'s google', 'https://google.ru'), ], [ InlineButton::toast('toast_identifier', 'Toast text!'), new Menu('Sub menu', 'submenu', [ InlineButton::toast('sub_menu_toast', 'Submenu toast!'), InlineButton::menuSection('<< Back', Menu::path('root')) ]), ] ]); // You must call this method once only on the your TOP level menu object. $menu->buildPathsFromThisRoot();
- Extend your standard CallbackqueryCommand from InlineMenuCallbackqueryCommand and realise abstract methods:
<?php class CallbackqueryCommand extends InlineMenuCallbackqueryCommand { protected function getRootMenu(): Menu { // return the Menu object from the previous step return new Menu (...); } }
- Get standard Longman\TelegramBot\Entities\InlineKeyboard object and use it in Request::sendMessage () in your commands:
<?php $menu = new Menu (...); $menu->buildPathsFromThisRoot(); $inlineKeyboard = $menu->getInlineKeyboard(); Request::sendMessage([ 'chat_id' => 'some_chat_id', 'text' => 'This is menu!', 'reply_markup' => $inlineKeyboard, ]);