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

This package is auto-updated.

Last update: 2022-05-15 16:50:43 UTC


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:

  1. 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);
  1. 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();
  1. 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 (...);
    }
}
  1. 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,
]);