-
Notifications
You must be signed in to change notification settings - Fork 0
View
The view/ folder handles all the strings for the response messages, the bot buttons logic and, in general, all the stuff about the visualization of responses during the interaction with the Telegram Bot (the UI, in a way).
The MenuOptions class is a class of constants only, which represents the bot's static commands. The constants should be the keys of the array $valid_static_inputs in each process class (this is better explained here (LINK)):
// inside the MenuOptions class
public const COMMAND_START = '/start';
public const COMMAND_RESTART = '/restartbot';// inside a process class
protected array $valid_static_inputs = [
view\MenuOptions::COMMAND_START => "startProcedure",
view\MenuOptions::COMMAND_RESTART => "restartProcedure"
];The ViewWrapper class is similar to the BaseEntity class, mentioned in the Chapter 7. This class has a defined __callStatic magic method which, for every "get" static call of the Keyboards and InlineKeyboards sub-classes, returns the formatted buttons to be used as the value for the reply_markup parameter, in a sendMessage request, for example.
The buttons can be defined statically as public constants in the sub-classes (instructions on how to do this are provided in the specific files for these classes).
For Keyboards and InlineKeyboards are used, respectively, KeyboardsTrait and InlineKeyboardsTrait, two traits that offer the functions to create the keyboard and the inline keyboard from an array:
// inside Keyboards class
public const MAIN_MENU = [
[MenuOptions::COMMAND_START, MenuOptions::COMMAND_RESTART]
];// example of usage
$_Bot->sendMessage([
'text' => "==> " . $test,
'reply_markup' => Keyboards::getMainMenu()
]);